This repository was archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathCustomAnimationExample.tsx
More file actions
87 lines (78 loc) · 1.87 KB
/
CustomAnimationExample.tsx
File metadata and controls
87 lines (78 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import * as React from 'react';
import { StyleSheet } from 'react-native';
import {
TabView,
TabBar,
SceneMap,
NavigationState,
SceneRendererProps,
} from 'react-native-tab-view';
import Article from './Shared/Article';
import Albums from './Shared/Albums';
import Chat from './Shared/Chat';
import Contacts from './Shared/Contacts';
type State = NavigationState<{
key: string;
title: string;
}>;
const animateOnIndexChange = (currentIndex: number, nextIndex: number) => {
return Math.abs(currentIndex - nextIndex) === 1;
};
const CustomAnimationExample = () => {
const [index, onIndexChange] = React.useState(1);
const [routes] = React.useState([
{ key: 'article', title: 'Article' },
{ key: 'contacts', title: 'Contacts' },
{ key: 'albums', title: 'Albums' },
{ key: 'chat', title: 'Chat' },
]);
const renderTabBar = (
props: SceneRendererProps & { navigationState: State }
) => (
<TabBar
{...props}
scrollEnabled
indicatorStyle={styles.indicator}
style={styles.tabbar}
tabStyle={styles.tab}
labelStyle={styles.label}
/>
);
const renderScene = SceneMap({
albums: Albums,
contacts: Contacts,
article: Article,
chat: Chat,
});
return (
<TabView
lazy
navigationState={{
index,
routes,
}}
renderScene={renderScene}
renderTabBar={renderTabBar}
onIndexChange={onIndexChange}
animateOnIndexChange={animateOnIndexChange}
/>
);
};
CustomAnimationExample.title = 'Custom Animation';
CustomAnimationExample.backgroundColor = '#3f51b5';
CustomAnimationExample.appbarElevation = 0;
export default CustomAnimationExample;
const styles = StyleSheet.create({
tabbar: {
backgroundColor: '#3f51b5',
},
tab: {
width: 'auto',
},
indicator: {
backgroundColor: '#ffeb3b',
},
label: {
fontWeight: '400',
},
});