ascoders / react-native-image-viewer

🚀 tiny & fast lib for react native image viewer pan and zoom
MIT License
2.44k stars 577 forks source link

swipeNavigationDisabled attribute added. #429

Open sungsong88 opened 3 years ago

sungsong88 commented 3 years ago

swipeNavigationDisabled optional attribute will disable the swipe navigation on true. Short flickering, or long dragging both will be ignored. A good way to navigate while it's disabled is by changing the index which could be done in the callback triggered from the rendered arrow component's onPress. (renderArrowLeft and renderArrowRight can be used to render touchable arrow) Zoom and SwipeDown gestures still work.

Example code:

      <ImageViewer 
        imageUrls={[
          { url: "https://www.petmd.com/sites/default/files/cat-with-kittens.jpg" },
          { url: "https://res.cloudinary.com/twenty20/private_images/t_watermark-criss-cross-10/v1507883269000/photosp/1640068f-eab2-4859-9f01-16b3534006fb/stock-photo-kitten-pet-kitty-kittens-cute-kitten-grey-kitten-tabby-kitten-sweetpaws-1640068f-eab2-4859-9f01-16b3534006fb.jpg" },
          { url: "http://www.pethealthnetwork.com/sites/default/files/content/images/5-silent-killers-cats-475212379.jpg" },
          { url: "https://imgflip.com/s/meme/Cute-Cat.jpg" },
        ]}
        index={index}
        swipeNavigationDisabled={true}
        swipeDownThreshold={100}
        enableSwipeDown={true}
        renderArrowLeft={() => {
          return index !== 0 ? (
            <TouchableOpacity 
              style={styles.arrow}
              onPress={() => {
                setIndex(index - 1);
              }}
            >
              <Icon
                name="ios-arrow-back"
                type="ionicon"
                color="#fff"
                size={40}
                iconStyle={styles.arrowIconStyle}
              />
            </TouchableOpacity>
          ) : null;
        }}
        renderArrowRight={() => {
          return index !== 3 ? (
            <TouchableOpacity 
              style={styles.arrow}
              onPress={() => {
                setIndex(index + 1);
              }}
            >
              <Icon
                name="ios-arrow-forward"
                type="ionicon"
                color="#fff"
                size={40}
                iconStyle={styles.arrowIconStyle}
              />
            </TouchableOpacity>
          ) : null;
        }}
        onSwipeDown={() => alert("Swiped!")}
      />