Skip to content

Commit bf8a6a9

Browse files
authored
feat: add disablePageAnimations prop (#50)
1 parent 2b1c536 commit bf8a6a9

File tree

9 files changed

+39
-3
lines changed

9 files changed

+39
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ Default options to use for the screens in the navigator.
109109

110110
Whether to show labels in tabs. Defaults to true.
111111

112+
#### `disablePageAnimations`
113+
114+
Whether to disable page animations between tabs. (iOS only)
115+
112116
#### `sidebarAdaptable`
113117

114118
A tab bar style that adapts to each platform. (Apple platforms only)

android/src/main/java/com/rcttabview/RCTTabViewViewManager.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,7 @@ class RCTTabViewViewManager :
137137

138138
@ReactProp(name = "ignoresTopSafeArea")
139139
fun setIgnoresTopSafeArea(view: ReactBottomNavigationView, flag: Boolean) {}
140+
141+
@ReactProp(name = "disablePageAnimations")
142+
fun setDisablePageAnimations(view: ReactBottomNavigationView, flag: Boolean) {}
140143
}

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ PODS:
12091209
- ReactCommon/turbomodule/bridging
12101210
- ReactCommon/turbomodule/core
12111211
- Yoga
1212-
- react-native-bottom-tabs (0.0.9):
1212+
- react-native-bottom-tabs (0.0.10):
12131213
- DoubleConversion
12141214
- glog
12151215
- RCT-Folly (= 2024.01.01.00)
@@ -1793,7 +1793,7 @@ SPEC CHECKSUMS:
17931793
React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404
17941794
React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4
17951795
React-microtasksnativemodule: 618b64238e43ef3154079f193aa6649e5320ae19
1796-
react-native-bottom-tabs: 6b4dff8469797a3bf8758594832955a2214e2e0d
1796+
react-native-bottom-tabs: f2d0c291b0158846fb8c6964b9535a3ab206fdf2
17971797
react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9
17981798
React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9
17991799
React-NativeModulesApple: 651670a799672bd54469f2981d91493dda361ddf

example/src/App.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const FourTabsIgnoreSafeArea = () => {
2727
return <FourTabs ignoresTopSafeArea />;
2828
};
2929

30+
const FourTabsNoAnimations = () => {
31+
return <FourTabs disablePageAnimations />;
32+
};
33+
3034
const examples = [
3135
{ component: ThreeTabs, name: 'Three Tabs' },
3236
{ component: FourTabs, name: 'Four Tabs' },
@@ -37,6 +41,7 @@ const examples = [
3741
name: 'Four Tabs - No header',
3842
screenOptions: { headerShown: false },
3943
},
44+
{ component: FourTabsNoAnimations, name: 'Four Tabs - no animations' },
4045
{ component: NativeBottomTabs, name: 'Native Bottom Tabs' },
4146
{ component: JSBottomTabs, name: 'JS Bottom Tabs' },
4247
{

example/src/Examples/FourTabs.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import { Chat } from '../Screens/Chat';
77

88
interface Props {
99
ignoresTopSafeArea?: boolean;
10+
disablePageAnimations?: boolean;
1011
}
1112

12-
export default function FourTabs({ ignoresTopSafeArea = false }: Props) {
13+
export default function FourTabs({
14+
ignoresTopSafeArea = false,
15+
disablePageAnimations = false,
16+
}: Props) {
1317
const [index, setIndex] = useState(0);
1418
const [routes] = useState([
1519
{
@@ -48,6 +52,7 @@ export default function FourTabs({ ignoresTopSafeArea = false }: Props) {
4852
<TabView
4953
ignoresTopSafeArea={ignoresTopSafeArea}
5054
sidebarAdaptable
55+
disablePageAnimations={disablePageAnimations}
5156
navigationState={{ index, routes }}
5257
onIndexChange={setIndex}
5358
renderScene={renderScene}

ios/RCTTabViewViewManager.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ - (UIView *)view
3030
RCT_EXPORT_VIEW_PROPERTY(sidebarAdaptable, BOOL)
3131
RCT_EXPORT_VIEW_PROPERTY(labeled, BOOL)
3232
RCT_EXPORT_VIEW_PROPERTY(ignoresTopSafeArea, BOOL)
33+
RCT_EXPORT_VIEW_PROPERTY(disablePageAnimations, BOOL)
3334

3435
@end

ios/TabViewImpl.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class TabViewProps: ObservableObject {
1313
@Published var sidebarAdaptable: Bool?
1414
@Published var labeled: Bool?
1515
@Published var ignoresTopSafeArea: Bool?
16+
@Published var disablePageAnimations: Bool = false
1617
}
1718

1819
/**
@@ -61,6 +62,12 @@ struct TabViewImpl: View {
6162
}
6263
.getSidebarAdaptable(enabled: props.sidebarAdaptable ?? false)
6364
.onChange(of: props.selectedPage ?? "") { newValue in
65+
if (props.disablePageAnimations) {
66+
UIView.setAnimationsEnabled(false)
67+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
68+
UIView.setAnimationsEnabled(true)
69+
}
70+
}
6471
onSelect(newValue)
6572
}
6673
.onAppear {

ios/TabViewProvider.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ struct TabData: Codable {
3535
}
3636
}
3737

38+
@objc var disablePageAnimations: Bool = false {
39+
didSet {
40+
props.disablePageAnimations = disablePageAnimations
41+
}
42+
}
43+
3844
@objc var labeled: Bool = true {
3945
didSet {
4046
props.labeled = labeled

src/TabView.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ interface Props<Route extends BaseRoute> {
3131
* Whether to ignore the top safe area. (iOS only)
3232
*/
3333
ignoresTopSafeArea?: boolean;
34+
35+
/**
36+
* Whether to disable page animations between tabs. (iOS only)
37+
*/
38+
disablePageAnimations?: boolean;
3439
/**
3540
* State for the tab view.
3641
*

0 commit comments

Comments
 (0)