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

How i got the scroll handler In feed page to work #1

Open
johnsonfash opened this issue Nov 16, 2024 · 0 comments
Open

How i got the scroll handler In feed page to work #1

johnsonfash opened this issue Nov 16, 2024 · 0 comments

Comments

@johnsonfash
Copy link

johnsonfash commented Nov 16, 2024

  const { top } = useSafeAreaInsets();
  const prevScroll = useRef(0);
  const tabMargin = useRef(0)
  const navigation = useNavigation();
  const tabBarHeight = useBottomTabBarHeight();
  
   useFocusEffect(useCallback(() => {
       navigation.getParent()?.setOptions({
        tabBarStyle: {
          marginBottom: 0
        }
      });
  }, []))

  const handleScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
    const currentOffset = e.nativeEvent.contentOffset.y;
    const maxHeight = e.nativeEvent.contentSize.height - e.nativeEvent.layoutMeasurement.height;
    if (currentOffset == 0) {
      setNavigation()
    }
    if (currentOffset > 0 && currentOffset <= maxHeight) {
      if (currentOffset > prevScroll.current) {
        if (tabMargin.current > -tabBarHeight) {
          tabMargin.current = tabMargin.current - 5
        }
      } else {
        if (tabMargin.current < 0) {
          tabMargin.current = tabMargin.current + 5;
        }
      }
      if (tabMargin.current > tabBarHeight) {
        tabMargin.current = tabBarHeight
      }
      if (tabMargin.current < -tabBarHeight) {
        tabMargin.current = -tabBarHeight
      }
      navigation.getParent()?.setOptions({
        tabBarStyle: {
          marginBottom: tabMargin.current
        }
      });
    }
    prevScroll.current = currentOffset;
  }
  
  
  
 <FlashList
  onScroll={handleScroll}
  scrollEventThrottle={16}
  keyExtractor={(item) => item.id as string}
  data={data}
  onEndReachedThreshold={0.5}
  showsVerticalScrollIndicator={false}
  renderItem={({ item }) => (
    <Link asChild suppressHighlighting href={{
      pathname: '/(feed)/thread/[id]',
      params: { id: item.id as string }
    }}>
      <TouchableOpacity activeOpacity={0.8} >
        <Thread likeMessage={likeMessage} thread={item} />
      </TouchableOpacity>
    </Link>
  )}
  />
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

1 participant