-
Notifications
You must be signed in to change notification settings - Fork 83
Adding freezeOnBlur for android and iOS #113
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
Changes from 5 commits
5b908e8
dcb3e81
b143d5a
9ae95cf
8d92942
4cbdd6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import * as React from 'react'; | ||
| import { Platform, StyleSheet, Text, View } from 'react-native'; | ||
| import createNativeBottomTabNavigator from '../../../src/react-navigation/navigators/createNativeBottomTabNavigator'; | ||
|
|
||
| const store = new Set<Dispatch>(); | ||
|
|
||
| type Dispatch = (value: number) => void; | ||
|
|
||
| function useValue() { | ||
| const [value, setValue] = React.useState<number>(0); | ||
|
|
||
| React.useEffect(() => { | ||
| const dispatch = (value: number) => { | ||
| setValue(value); | ||
| }; | ||
| store.add(dispatch); | ||
| return () => { | ||
| store.delete(dispatch); | ||
| }; | ||
| }, [setValue]); | ||
|
|
||
| return value; | ||
| } | ||
|
|
||
| function HomeScreen() { | ||
| return ( | ||
| <View style={styles.screenContainer}> | ||
| <Text>Home!</Text> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function DetailsScreen() { | ||
| const value = useValue(); | ||
| // only 1 'render' should appear at the time | ||
| console.log(`${Platform.OS} Details Screen render ${value}`); | ||
| return ( | ||
| <View style={styles.screenContainer}> | ||
| <Text>Details!</Text> | ||
| <Text style={{ alignSelf: 'center' }}>Details Screen {value}</Text> | ||
| </View> | ||
| ); | ||
| } | ||
| const Tab = createNativeBottomTabNavigator(); | ||
|
|
||
| export default function NativeBottomTabsFreezeOnBlur() { | ||
| React.useEffect(() => { | ||
| let timer = 0; | ||
| const interval = setInterval(() => { | ||
| timer = timer + 1; | ||
| store.forEach((dispatch) => dispatch(timer)); | ||
| }, 3000); | ||
| return () => clearInterval(interval); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <Tab.Navigator | ||
| screenOptions={{ | ||
| freezeOnBlur: true, | ||
| }} | ||
| > | ||
| <Tab.Screen | ||
| name="Article" | ||
| component={HomeScreen} | ||
| options={{ | ||
| tabBarIcon: () => require('../../assets/icons/article_dark.png'), | ||
| }} | ||
| /> | ||
| <Tab.Screen | ||
| name="Albums" | ||
| component={DetailsScreen} | ||
| options={{ | ||
| tabBarIcon: () => require('../../assets/icons/grid_dark.png'), | ||
| }} | ||
| /> | ||
| <Tab.Screen | ||
| name="Contact" | ||
| component={DetailsScreen} | ||
| options={{ | ||
| tabBarIcon: () => require('../../assets/icons/person_dark.png'), | ||
| }} | ||
| /> | ||
| <Tab.Screen | ||
| name="Chat" | ||
| component={DetailsScreen} | ||
| options={{ | ||
| tabBarIcon: () => require('../../assets/icons/chat_dark.png'), | ||
| }} | ||
| /> | ||
| </Tab.Navigator> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| screenContainer: { | ||
| flex: 1, | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import * as React from 'react'; | ||
| import { Platform, StyleProp, View, ViewProps, ViewStyle } from 'react-native'; | ||
|
|
||
| type Props = { | ||
| visible: boolean; | ||
| children?: React.ReactNode; | ||
| enabled: boolean; | ||
| freezeOnBlur?: boolean; | ||
| style?: StyleProp<ViewStyle>; | ||
| collapsable?: boolean; | ||
| }; | ||
|
|
||
| let Screens: typeof import('react-native-screens') | undefined; | ||
|
|
||
| try { | ||
| Screens = require('react-native-screens'); | ||
| } catch (e) { | ||
| // Ignore | ||
| } | ||
|
|
||
| export const MaybeScreenContainer = ({ | ||
| enabled, | ||
| children, | ||
| ...rest | ||
| }: ViewProps & { | ||
| enabled: boolean; | ||
| hasTwoStates: boolean; | ||
| children?: React.ReactNode; | ||
| }) => { | ||
| if (Platform.OS === 'android' && Screens?.screensEnabled()) { | ||
| return ( | ||
| <Screens.ScreenContainer enabled={enabled} {...rest}> | ||
| {children} | ||
| </Screens.ScreenContainer> | ||
| ); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we don't have the navigation container on iOS (JS Tabs have it) but it works without it? That's weird 😅 If the @tboba Could you help here? 🙏
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @okwasniewski Yeah on iOS it works even without Screen Container. In case of Android we need
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, @shubhamguptadream11 after consulting with Can you change the PR to only add |
||
|
|
||
| return <>{children}</>; | ||
| }; | ||
|
|
||
| export function MaybeScreen({ visible, ...rest }: Props) { | ||
| if (Screens?.screensEnabled()) { | ||
| return <Screens.Screen activityState={visible ? 2 : 0} {...rest} />; | ||
| } | ||
| return <View {...rest} />; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested it on both new and old architecture? I feel like this might break passing children on new arch as technically now we have only one child.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Till now I tested this on Android for both new and old arch.
I will be testing it on iOS today.