Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/src/Examples/BottomNavigationExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const BottomNavigationExample = ({ navigation }: Props) => {
sceneAnimationEnabled={sceneAnimation !== undefined}
sceneAnimationType={sceneAnimation}
sceneAnimationEasing={Easing.ease}
getLazy={({ route }) => route.key !== 'album'}
/>
</View>
);
Expand Down
9 changes: 8 additions & 1 deletion src/components/BottomNavigation/BottomNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Route = {
color?: string;
accessibilityLabel?: string;
testID?: string;
lazy?: boolean;
};

type NavigationState = {
Expand Down Expand Up @@ -262,6 +263,11 @@ export type Props = {
* TestID used for testing purposes
*/
testID?: string;
/**
* @supported Available in v5.x
* Get lazy for the current screen. Uses true by default.
*/
getLazy?: (props: { route: Route }) => boolean | undefined;
};

const MIN_RIPPLE_SCALE = 0.001; // Minimum scale is not 0 due to bug with animation
Expand Down Expand Up @@ -385,6 +391,7 @@ const BottomNavigation = ({
labelMaxFontSizeMultiplier = 1,
compact = !theme.isV3,
testID = 'bottom-navigation',
getLazy = ({ route }: { route: Route }) => route.lazy,
}: Props) => {
const { scale } = theme.animation;

Expand Down Expand Up @@ -679,7 +686,7 @@ const BottomNavigation = ({
<View style={[styles.container, style]} testID={testID}>
<View style={[styles.content, { backgroundColor: colors?.background }]}>
{routes.map((route, index) => {
if (!loaded.includes(route.key)) {
if (getLazy({ route }) !== false && !loaded.includes(route.key)) {
// Don't render a screen if we've never navigated to it
return null;
}
Expand Down
15 changes: 15 additions & 0 deletions src/components/__tests__/BottomNavigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,18 @@ it('renders a single tab', () => {

expect(queryByTestId('bottom-navigation')).not.toBeNull();
});

it('renders bottom navigation with getLazy', () => {
const tree = render(
<BottomNavigation
navigationState={createState(0, 5)}
onIndexChange={jest.fn()}
renderScene={({ route }) => route.title}
getLazy={({ route }) => route.key === 'key-2'}
/>
);

expect(tree).toMatchSnapshot();

expect(tree.queryByTestId('RouteScreen: 2')).toBeNull();
});
Loading