-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Adding freezeOnBlur for android and iOS #113
Closed
shubhamguptadream11
wants to merge
6
commits into
callstackincubator:main
from
dream-sports-labs:feat/freezeOnBlur
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5b908e8
feat: added freezeOnBlur
shubhamguptadream11 dcb3e81
feat: screen container implemented
shubhamguptadream11 b143d5a
fix: inline styles removed
shubhamguptadream11 9ae95cf
fix: updated docs
shubhamguptadream11 8d92942
fix: iOS crash fixed
shubhamguptadream11 4cbdd6d
feat: detach inactive screen removed for android
shubhamguptadream11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,100 @@ | ||
import * as React from 'react'; | ||
import { 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('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', | ||
}, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import * as React from 'react'; | ||
import { 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, | ||
...rest | ||
}: ViewProps & { | ||
enabled: boolean; | ||
hasTwoStates: boolean; | ||
children: React.ReactNode; | ||
}) => { | ||
if (Screens?.screensEnabled?.()) { | ||
return <Screens.ScreenContainer enabled={enabled} {...rest} />; | ||
} | ||
|
||
return <View {...rest} />; | ||
}; | ||
|
||
export function MaybeScreen({ visible, children, ...rest }: Props) { | ||
if (Screens?.screensEnabled?.()) { | ||
return ( | ||
<Screens.Screen activityState={visible ? 2 : 0} {...rest}> | ||
{children} | ||
</Screens.Screen> | ||
); | ||
} | ||
return <View {...rest}>{children}</View>; | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.