react-native-parallax-scroll-view icon indicating copy to clipboard operation
react-native-parallax-scroll-view copied to clipboard

We can't detect press on the image

Open pcrouillere opened this issue 8 years ago • 24 comments

When I click on the image in the parallaxview nothing is detected, why ?

We can not use https://github.com/oblador/react-native-lightbox with parallax and its really bad.. :(

pcrouillere avatar Aug 09 '16 12:08 pcrouillere

It's a good point, touch isn't detected on background and foreground view, it's annoying :/ I look a little bit into the code and I can't really find why the touch doesn't work

Edit:

I look again the code, and I think it's because background view and foreground view are wrapped in Animated.View, so I think it's why the touchable events doesn't work, maybe a react-native bug

magrinj avatar Aug 09 '16 13:08 magrinj

I was thinking the same, but in lightbox we have this :

  <View
        ref={component => this._root = component}
        style={this.props.style}
        onLayout={() => {}}
      >
        <Animated.View style={{opacity: this.state.layoutOpacity}}>
          <TouchableHighlight
            underlayColor={this.props.underlayColor}
            onPress={this.open}
          >
            {this.props.children}
          </TouchableHighlight>
        </Animated.View>
        {this.props.navigator ? false : <LightboxOverlay {...this.getOverlayProps()} />}
      </View>

So apparently something wrapped in Animated.View can be touchable (?!) I really don't get why it's not working in this case, too bad :(

pcrouillere avatar Aug 09 '16 13:08 pcrouillere

Strange... Normally a component can be touchable in an Animated.View but in the old version of react-native this bug happened on Android, so I was wondering if in the latest release something broke up but apparently not. Maybe it's a problem with the Scroll component but I don't think so :/

magrinj avatar Aug 09 '16 13:08 magrinj

+1

techmentormaria avatar Aug 16 '16 08:08 techmentormaria

Ok so I look deep into the code, and I don't really understand why touchable components doesn't work in the background, but I think that's can be due to all the view behind the background component. In my app I just set my button in the foreground and that's working! :)

In my first message, I said that it doesn't work, but the problem was I don't use TouchableWithoutFeedback in the right way, this component seem to doesn't take style props, so all the style need to be applied to the child view.

Instead you can also use TouchableOpacity, with this one you can apply a style.

Hope that's gonna help everyone!

magrinj avatar Aug 16 '16 09:08 magrinj

If you make the following changes in the source in index.js it should work:

_maybeRenderStickyHeader({ parallaxHeaderHeight, stickyHeaderHeight, backgroundColor, renderFixedHeader, renderStickyHeader }) { const { viewWidth, scrollY } = this.state; if (renderStickyHeader || renderFixedHeader) { const p = pivotPoint(parallaxHeaderHeight, stickyHeaderHeight); return ( <View style={[styles.stickyHeader, { width: viewWidth, ...(stickyHeaderHeight ? { height: scrollY._value>0?stickyHeaderHeight:0 } : null ) }]}> { renderStickyHeader ? ( <Animated.View style={{ backgroundColor: backgroundColor, height: scrollY._value>0?stickyHeaderHeight:0, opacity: interpolate(scrollY, { inputRange: [0, p], outputRange: [0, 1], extrapolate: 'clamp' }) }}> <Animated.View style={{ transform: [{ translateY: interpolate(scrollY, { inputRange: [0, p], outputRange: [stickyHeaderHeight, 0], extrapolate: 'clamp' }) }] }}> { renderStickyHeader() } </Animated.View> </Animated.View> ) : null } { renderFixedHeader && renderFixedHeader() } </View> ); } else { return null; } } }

And in _onScroll(e)

_onScroll(e) { const { parallaxHeaderHeight, stickyHeaderHeight, onChangeHeaderVisibility, onScroll: prevOnScroll = () => {} } = this.props;

const p = pivotPoint(parallaxHeaderHeight, stickyHeaderHeight);

this._maybeUpdateScrollPosition(e);

if (e.nativeEvent.contentOffset.y >= p) { onChangeHeaderVisibility(false); } else { onChangeHeaderVisibility(true); } this.forceUpdate(); prevOnScroll(e); }

bhavyata9 avatar Aug 16 '16 17:08 bhavyata9

Hey @bhavyata9 Thank you ! But can you use "Insert code", cause I think there are some mistake in your code, for exemple "return ( 0?stickyHeaderHeight:0 } : null ) }]}>".

Thanks in advance :)

pcrouillere avatar Aug 17 '16 09:08 pcrouillere

index.txt

bhavyata9 avatar Aug 17 '16 13:08 bhavyata9

@bhavyata9
It's not working, still no lightbox :( but thanks :)

pcrouillere avatar Aug 18 '16 08:08 pcrouillere

@pcrouillere Did you try to put your button in the foreground as I suggest in my last message ?

magrinj avatar Aug 18 '16 08:08 magrinj

@magrinj I'm going to try today ! But with the button I have to make my "own" lightbox I think.

pcrouillere avatar Aug 18 '16 08:08 pcrouillere

@pcrouillere Oh yes sorry I forgot that LightBox wrap the image child and detect the click :/ Yes maybe you have to do your own lightbox for this.

magrinj avatar Aug 18 '16 08:08 magrinj

@pcrouillere You can also modify lightbox code, to enable it to be opened programmatically

magrinj avatar Aug 18 '16 08:08 magrinj

This component can render a foreground view and a background view but the parrallax is only on the background view. Whereas the foreground view detects the click. So as @magrinj said, you need to make a transparent button on the foreground if you want to make it work. For instance a view with opacity 0 containing a ligthbox component. This should do the trick. Didn't test on IOS but it should work too.

Regards, Sébastien

sebastienbarteau avatar Sep 28 '16 08:09 sebastienbarteau

using zIndex and the background view can detects the click, but it needs react-native version higher than 0.30

tanpuer avatar Dec 08 '16 09:12 tanpuer

I'm trying to insert a carousel in the parallax background but it also doesn't get the touch event. The only one I could get to appear correctly is react-native-looped-carousel but I have to put it on autoplay or else it just stays on the first image. I tried viewpager or image-slider but with no success.

@tanpuer how can you make it detect the click with zIndex? I tried in the <View> inside the renderBackground, I tried in the <Carousel> component, but the click or drag is not detected.

nbastoWM avatar Mar 15 '17 16:03 nbastoWM

@nbastoWM any progress on figuring this out?

connorbrathwaite avatar May 09 '17 16:05 connorbrathwaite

@nbastoWM Yeah, something to say ? :)

davidroman0O avatar Aug 04 '17 08:08 davidroman0O

+1

matteo-pennisi avatar Aug 25 '17 13:08 matteo-pennisi

+1

shukerullah avatar Sep 23 '17 10:09 shukerullah

+1

chookg avatar Sep 28 '17 11:09 chookg

+1

artsx avatar Oct 17 '17 17:10 artsx

Unfortunately I had to abandon Parallax in order to have a scroll of images with swipe. None of what I tried could detect the touch swipe in the parallax.

nbastoWM avatar Oct 23 '17 09:10 nbastoWM

Can't reproduce. Touch events in images or otherwise all work in background, foreground and renderStickyHeader.

fungilation avatar Oct 23 '17 12:10 fungilation