-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
types.ts
183 lines (166 loc) · 3.4 KB
/
types.ts
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import type {
StyleProp,
ViewStyle,
Insets,
Animated as RNAnimated,
} from 'react-native';
import type Animated from 'react-native-reanimated';
import type Presets from './presets';
import type { PresetEnum } from './presets';
export type TabsConfig<T, P = { [key: string]: T }> = {
[key in keyof P]: T;
};
export interface Space {
vertical?: number;
horizontal?: number;
}
interface TabBarItemSpacing {
innerVerticalSpace: number;
innerHorizontalSpace: number;
outerVerticalSpace: number;
outerHorizontalSpace: number;
}
export interface TabBarConfigurableProps {
/**
* Animation duration.
* @default PresetConstants
*/
duration?: number;
/**
* Animation easing function.
* @default Easing.out(Easing.exp)
*/
easing?: Animated.EasingFunction;
/**
* Item padding space.
* @default PresetConstants
*/
itemInnerSpace?: number | Space;
/**
* Item margin space.
* @default PresetConstants
*/
itemOuterSpace?: number | Space;
/**
* Item container width.
* @default PresetConstants
*/
itemContainerWidth?: 'auto' | 'fill';
/**
* Icon size.
* @default PresetConstants
*/
iconSize?: number;
/**
* Item layout direction.
* @default false
*/
isRTL?: boolean;
/**
* Callback when item been long pressed.
*/
onLongPress?: (index: number) => void;
}
export interface TabInfo {
title: string;
key: string;
}
export type TabBarViewProps<C, T> = {
/**
* Selected animated index.
*/
selectedIndex: Animated.Value<number>;
/**
* Callback when animated index change.
*/
animatedOnChange: (index: number) => Animated.Node<number>;
/**
* Tabs configs.
*/
tabs: Array<TabInfo & T>;
/**
* Root container style.
*/
style?: StyleProp<ViewStyle>;
} & TabBarConfigurableProps &
C;
export interface TabBarItemProps
extends Required<
Omit<
TabBarConfigurableProps,
| 'itemInnerSpace'
| 'itemOuterSpace'
| 'onLongPress'
| 'duration'
| 'easing'
>
> {
/**
* Animated focus value.
*/
animatedFocus: Animated.Node<number>;
/**
* Tab index.
*/
index: number;
/**
* Tab label.
*/
label: string;
/**
* Tab spacing
*/
spacing: TabBarItemSpacing;
}
export type AnimatedTabBarProps<T extends PresetEnum = 'bubble'> = {
/**
* Animation preset.
*/
preset?: T;
/**
* Tabs configurations.
*/
tabs: TabsConfig<typeof Presets[T]['$t']>;
/**
* Root container style.
*/
style?:
| StyleProp<ViewStyle>
| RNAnimated.WithAnimatedValue<StyleProp<ViewStyle>>;
/**
* React Navigation Props
*/
state?: any;
navigation?: any;
descriptors?: any;
onTabPress?: any;
onTabLongPress?: any;
safeAreaInsets?: Insets;
} & Omit<TabBarConfigurableProps, 'onLongPress'> &
ExtractPresetConfig<T>;
export type AnimatedTabBarViewProps<T extends PresetEnum> = {
/**
* Initial index.
*/
index: number;
/**
* Tabs configurations.
*/
tabs: TabsConfig<typeof Presets[T]['$t'] & Partial<TabInfo>>;
/**
* Animation preset.
*/
preset?: T;
/**
* Root container style.
*/
style?: StyleProp<ViewStyle>;
/**
* Callback when animated index changes.
*/
onIndexChange: (index: number) => void;
} & TabBarConfigurableProps &
ExtractPresetConfig<T>;
export type ExtractPresetConfig<T extends PresetEnum> = {
[k in keyof typeof Presets[T]['$c']]: typeof Presets[T]['$c'][k];
};