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

stickyHeader prevents touch events on foreground

Open peacechen opened this issue 7 years ago • 16 comments

When both renderForeground and renderStickyHeader are supplied, touch events no longer register on the foreground header.

peacechen avatar Apr 03 '17 20:04 peacechen

Did you find a solution to this? @peacechen ? I am running into the same problem

alejandrochacinortega avatar May 31 '17 10:05 alejandrochacinortega

Same problem here

renay007 avatar Jun 08 '17 14:06 renay007

I am also facing the same problem.. only the stickyHeaderHeight area is not touchable.. else works fine.. I tried disabling by changing to stickyHeaderHeight={0}, Now touches are working... Had anyone found some hack or solution, please help..

bgoyal2222 avatar Jul 20 '17 09:07 bgoyal2222

Unfortunately, the hack I've been using requires you to change code in the node module. Fix #57 did the trick for me but no one merged the pull request. If you're changing the node module directly, make sure you keep track of where you made the change since all changes will go away if you delete all node modules and do a simple npm install

renay007 avatar Jul 20 '17 11:07 renay007

https://github.com/monterosalondon/react-native-parallax-scroll

i have found a alternative component check this..

bgoyal2222 avatar Jul 20 '17 12:07 bgoyal2222

Actually, I've looked at the current open issues and it seems that there are still problems when it comes to make the foreground touchable. Be careful and best of luck with the one you end up going with! :-)

renay007 avatar Jul 20 '17 12:07 renay007

isForegroundTouchable this property they have added to solve that issue

bgoyal2222 avatar Jul 20 '17 12:07 bgoyal2222

Awesome!!!

renay007 avatar Jul 20 '17 12:07 renay007

Hello, Has anyone found a solution with this module?

artsx avatar Oct 16 '17 09:10 artsx

@fungilation I forked your version of this library but this issue doesn't seem to be fixed, did I miss something? (I can't find a better way to comment to you than via the issue itself).

flikQ avatar Sep 06 '18 12:09 flikQ

I haven't touched this, I can't reproduce. I use both renderForeground and renderStickyHeader in my app and I don't have any touch event issues.

fungilation avatar Sep 06 '18 18:09 fungilation

@fungilation Do touch events register on the sticky header area? To test this, it needs to contain a touchable component listening for events.

What version of RN are you using? Maybe the behavior is different between RN releases.

peacechen avatar Sep 06 '18 18:09 peacechen

On RN 0.56. Yes I use a touchable on the entire renderStickyHeader to scroll a long FlatList back to the top. You can see this in my app WonderSwipe. Download the iOS app, search something, swipe left, scroll down on one of the summaries, tap sticky header on top.

fungilation avatar Sep 06 '18 19:09 fungilation

Add "stickHeaderheight" and add scrollEvent props like this: scrollEvent={event => { if ( event.nativeEvent.contentOffset.y <= 0 && this.state.stickHeaderHeight > 0 ) this.setState({ stickHeaderHeight: 0 }); else if ( event.nativeEvent.contentOffset.y > 0 && this.state.stickHeaderHeight === 0 ) this.setState({ stickHeaderHeight: 50 + statusBarHeight }); }} It works perffect for me. Good luck.

daleside710 avatar Oct 24 '18 16:10 daleside710

@daleside710 - Using your solution works fine but a Yellowbox warning is popping up with a warning message 'YellowBox.js:67 Property stickyHeaderHeight must be set if renderStickyHeader is used.'

jifromz09 avatar Mar 06 '19 08:03 jifromz09

@daleside710 solution works fine for me. I wrapped it in a component like this

import React, {useState} from 'react';
import UIParallaxScrollView from 'react-native-parallax-scroll-view';

export const ParallaxScrollView = ({
  children,
  stickyHeaderHeight,
  ...restProps
}) => {
  const [altStickyHeaderHeight, setStickyHeaderHeight] = useState(1);
  const onScroll = event => {
    const threshold = 30;
    if (restProps.renderStickyHeader) {
      if (
        event.nativeEvent.contentOffset.y <= threshold &&
        altStickyHeaderHeight > 1
      ) {
        setStickyHeaderHeight(1);
      } else if (
        event.nativeEvent.contentOffset.y > threshold &&
        altStickyHeaderHeight === 1
      ) {
        setStickyHeaderHeight(stickyHeaderHeight);
      }
    }
  };
  return (
    <UIParallaxScrollView
      stickyHeaderHeight={altStickyHeaderHeight}
      scrollEvent={onScroll}
      {...restProps}>
      {children}
    </UIParallaxScrollView>
  );
};

hope it helps anyone trying to solve this

daimagine avatar Nov 26 '19 07:11 daimagine