Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not zoom, swipe list images when using Modal #35

Closed
phamhuuan opened this issue Oct 20, 2021 · 7 comments
Closed

Can not zoom, swipe list images when using Modal #35

phamhuuan opened this issue Oct 20, 2021 · 7 comments

Comments

@phamhuuan
Copy link

phamhuuan commented Oct 20, 2021

react-native: 0.65.1
react-native-awessome-gallery: 0.2.6
react-native-reanimated: 2.2.3

Code

<Modal visible={true}>
	<Gallery
		ref={galleryRef}
		data={props.imageUrls}
		maxScale={10}
		initialIndex={props.defaultIndex}
		onIndexChange={setSelectedImage}
	/>
</Modal>
@ArnabXD
Copy link

ArnabXD commented Oct 20, 2021

I am also having the same issue.

  • react-native: 0.66
  • react-native-awessome-gallery: 0.2.6
  • react-native-reanimated: 2.2.3

Reproducible Code

import React, { useState } from 'react';
import { FlatList, Modal, Image, Pressable, Dimensions } from 'react-native';
import { Container } from '../components'; // A View with flex: 1 and flexGrow: 1
import AwesomeGallery from 'react-native-awesome-gallery';

const { width } = Dimensions.get('screen');

const data = new Array(25).fill(
  'https://cdn.stocksnap.io/img-thumbs/960w/business%20meeting-people_QVIEE1UZSX.jpg',
);

export const Gallery = () => {
  const [modalVisible, setModalVisible] = useState(false);
  const [initialIndex, setInitialIndex] = useState(0);
  return (
    <Container>
      <FlatList
        data={data}
        keyExtractor={(item, index) => index + item}
        numColumns={3}
        renderItem={({ item, index }) => (
          <Pressable
            onPress={() => {
              setInitialIndex(index);
              setModalVisible(true);
            }}
          >
            <Image
              source={{ uri: item }}
              style={{ height: width / 3, width: width / 3 }}
            />
          </Pressable>
        )}
      />
      <Modal
        visible={modalVisible}
        transparent={true}
        animationType="slide"
        onRequestClose={() => setModalVisible(false)}
      >
        <AwesomeGallery
          data={data}
          initialIndex={initialIndex}
          numToRender={10}
          keyExtractor={(item, index) => index + item}
        />
      </Modal>
    </Container>
  );
};

@pavelbabenko
Copy link
Owner

@phamhuuan Is it Android?
I can't reproduce on iOS

@ArnabXD
Copy link

ArnabXD commented Oct 20, 2021

It is on Android ,

@phamhuuan
Copy link
Author

@pavelbabenko yes it is on Android.

@phamhuuan
Copy link
Author

I have tried with react-native-modal: 13.0.0
AwesomeGallery work correctly when coverScreen={false}. If coverScreen = true, I have the same issue with using Modal from 'react-native'

@kamui545
Copy link

You need to wrap the gallery with GestureHandlerRootView if you're using it inside a modal on Android.

import { GestureHandlerRootView } from 'react-native-gesture-handler';

<Modal
  visible={viewerVisible}
  animationType="fade"
  transparent
  onRequestClose={closeViewer}>
  <GestureHandlerRootView style={{ flex: 1 }}>
    <Gallery
      data={images}
      onSwipeToClose={closeViewer}
      onIndexChange={onGalleryIndexChange}
      initialIndex={viewerPhoto}
    />
  </GestureHandlerRootView>
</Modal>

Maybe this could be handled by the library itself? @pavelbabenko

https://docs.swmansion.com/react-native-gesture-handler/docs/#for-library-authors

@pavelbabenko
Copy link
Owner

Tested on Android with v0.3.0. Everything worked well.
Note: v0.3.0 uses Gesture Handler v2
I'm closing the issue, but if the bug appears, please reopen it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants