-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f17fa06
commit c9f13ad
Showing
11 changed files
with
196 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'react-native-bottom-tabs': patch | ||
'@bottom-tabs/react-navigation': patch | ||
--- | ||
|
||
feat: add freezeOnBlur |
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
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
115 changes: 115 additions & 0 deletions
115
apps/example/src/Examples/NativeBottomTabsFreezeOnBlur.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import * as React from 'react'; | ||
import { Platform, StyleSheet, Text, View } from 'react-native'; | ||
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation'; | ||
|
||
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(props: any) { | ||
const value = useValue(); | ||
const screenName = props?.route?.params?.screenName; | ||
// only 1 'render' should appear at the time | ||
console.log(`${Platform.OS} Details Screen render ${value} ${screenName}`); | ||
return ( | ||
<View style={styles.screenContainer}> | ||
<Text>Details!</Text> | ||
<Text style={{ alignSelf: 'center' }}> | ||
Details Screen {value} {screenName ? screenName : ''}{' '} | ||
</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} | ||
initialParams={{ | ||
screenName: 'Article', | ||
}} | ||
options={{ | ||
tabBarIcon: () => require('../../assets/icons/article_dark.png'), | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="Albums" | ||
component={DetailsScreen} | ||
initialParams={{ | ||
screenName: 'Albums', | ||
}} | ||
options={{ | ||
tabBarIcon: () => require('../../assets/icons/grid_dark.png'), | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="Contact" | ||
component={DetailsScreen} | ||
initialParams={{ | ||
screenName: 'Contact', | ||
}} | ||
options={{ | ||
tabBarIcon: () => require('../../assets/icons/person_dark.png'), | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="Chat" | ||
component={DetailsScreen} | ||
initialParams={{ | ||
screenName: 'Chat', | ||
}} | ||
options={{ | ||
tabBarIcon: () => require('../../assets/icons/chat_dark.png'), | ||
}} | ||
/> | ||
</Tab.Navigator> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
screenContainer: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as React from 'react'; | ||
import { View } from 'react-native'; | ||
import type { StyleProp, ViewProps, ViewStyle } from 'react-native'; | ||
|
||
interface Props extends ViewProps { | ||
visible: boolean; | ||
children?: React.ReactNode; | ||
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 function Screen({ visible, ...rest }: Props) { | ||
if (Screens?.screensEnabled()) { | ||
return <Screens.Screen activityState={visible ? 2 : 0} {...rest} />; | ||
} | ||
return <View {...rest} />; | ||
} |
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
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
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
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
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