Skip to content

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

@johnsonfash

Description

@johnsonfash
  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>
  )}
  />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions