Created
February 10, 2024 12:14
-
-
Save ozcanzaferayan/f5115e76dc7cec8f478b97cb74c6c10e to your computer and use it in GitHub Desktop.
useTabPress.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useNavigation } from "expo-router"; | |
import { useEffect } from "react"; | |
import { FlatList } from "react-native"; | |
export const useTabPressScroll = <T>(ref: React.RefObject<FlatList<T>>) => { | |
const navigation = useNavigation(); | |
useEffect(() => { | |
// @ts-expect-error tabPress is not in the type | |
const unsub = navigation.addListener("tabPress", (evt) => { | |
if (navigation.isFocused()) { | |
ref.current?.scrollToOffset({ | |
offset: 0, | |
animated: true, | |
}); | |
} | |
}); | |
return unsub; | |
}, [navigation]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment