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
14 changes: 7 additions & 7 deletions apps/example/src/Examples/FourTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ interface Props {
activeIndicatorColor?: ColorValue;
}

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
chat: Chat,
});

export default function FourTabs({
disablePageAnimations = false,
scrollEdgeAppearance = 'default',
Expand Down Expand Up @@ -53,13 +60,6 @@ export default function FourTabs({
},
]);

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
chat: Chat,
});

return (
<TabView
sidebarAdaptable
Expand Down
14 changes: 7 additions & 7 deletions apps/example/src/Examples/Labeled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Chat } from '../Screens/Chat';

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
chat: Chat,
});

export default function LabeledTabs({
showLabels = true,
}: {
Expand Down Expand Up @@ -36,13 +43,6 @@ export default function LabeledTabs({
},
]);

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
chat: Chat,
});

return (
<TabView
labeled={showLabels}
Expand Down
12 changes: 6 additions & 6 deletions apps/example/src/Examples/SFSymbols.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Platform } from 'react-native';

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
});

const isAndroid = Platform.OS === 'android';

export default function SFSymbols() {
Expand Down Expand Up @@ -38,12 +44,6 @@ export default function SFSymbols() {
},
]);

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
});

return (
<TabView
sidebarAdaptable
Expand Down
12 changes: 6 additions & 6 deletions apps/example/src/Examples/ThreeTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
});

export default function ThreeTabs() {
const [index, setIndex] = useState(1);
const [routes] = useState([
Expand All @@ -30,12 +36,6 @@ export default function ThreeTabs() {
},
]);

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
});

return (
<TabView
navigationState={{ index, routes }}
Expand Down
15 changes: 7 additions & 8 deletions apps/example/src/Examples/TintColors.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as React from 'react';
import TabView, { SceneMap } from 'react-native-bottom-tabs';
import { useState } from 'react';
import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Chat } from '../Screens/Chat';

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
chat: Chat,
});

export default function TintColorsExample() {
const [index, setIndex] = useState(0);
const [routes] = useState([
Expand Down Expand Up @@ -38,13 +44,6 @@ export default function TintColorsExample() {
},
]);

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
chat: Chat,
});

return (
<TabView
sidebarAdaptable
Expand Down
53 changes: 39 additions & 14 deletions packages/react-native-bottom-tabs/src/TabView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React from 'react';
import type { TabViewItems } from './TabViewNativeComponent';
import type {
OnNativeLayout,
OnPageSelectedEventData,
OnTabBarMeasured,
TabViewItems,
} from './TabViewNativeComponent';
import {
type ColorValue,
Image,
Expand Down Expand Up @@ -215,7 +220,7 @@

if (!loaded.includes(focusedKey)) {
// Set the current tab to be loaded if it was not loaded before
setLoaded((loaded) => [...loaded, focusedKey]);

Check warning on line 223 in packages/react-native-bottom-tabs/src/TabView.tsx

View workflow job for this annotation

GitHub Actions / lint

'loaded' is already declared in the upper scope on line 219 column 10
}

const icons = React.useMemo(
Expand Down Expand Up @@ -279,6 +284,35 @@
onIndexChange(index);
});

const handleTabLongPress = React.useCallback(
({ nativeEvent: { key } }: { nativeEvent: OnPageSelectedEventData }) => {
const index = trimmedRoutes.findIndex((route) => route.key === key);
onTabLongPress?.(index);
},
[trimmedRoutes, onTabLongPress]
);

const handlePageSelected = React.useCallback(
({ nativeEvent: { key } }: { nativeEvent: OnPageSelectedEventData }) => {
jumpTo(key);
},
[jumpTo]
);

const handleTabBarMeasured = React.useCallback(
({ nativeEvent: { height } }: { nativeEvent: OnTabBarMeasured }) => {
setTabBarHeight(height);
},
[setTabBarHeight]
);

const handleNativeLayout = React.useCallback(
({ nativeEvent: { width, height } }: { nativeEvent: OnNativeLayout }) => {
setMeasuredDimensions({ width, height });
},
[setMeasuredDimensions]
);

return (
<BottomTabBarHeightContext.Provider value={tabBarHeight}>
<NativeTabView
Expand All @@ -290,19 +324,10 @@
icons={renderCustomTabBar ? undefined : resolvedIconAssets}
selectedPage={focusedKey}
tabBarHidden={!!renderCustomTabBar}
onTabLongPress={({ nativeEvent: { key } }) => {
const index = trimmedRoutes.findIndex((route) => route.key === key);
onTabLongPress?.(index);
}}
onPageSelected={({ nativeEvent: { key } }) => {
jumpTo(key);
}}
onTabBarMeasured={({ nativeEvent: { height } }) => {
setTabBarHeight(height);
}}
onNativeLayout={({ nativeEvent: { width, height } }) => {
setMeasuredDimensions({ width, height });
}}
onTabLongPress={handleTabLongPress}
onPageSelected={handlePageSelected}
onTabBarMeasured={handleTabBarMeasured}
onNativeLayout={handleNativeLayout}
hapticFeedbackEnabled={hapticFeedbackEnabled}
activeTintColor={activeTintColor}
inactiveTintColor={inactiveTintColor}
Expand Down
Loading