react-navigation-reanimated-top-tabs 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/README.md +5 -17
  2. package/lib/commonjs/components/ReanimatedTopTab/ReanimatedTabView.js +5 -3
  3. package/lib/commonjs/components/ReanimatedTopTab/ReanimatedTabView.js.map +1 -1
  4. package/lib/commonjs/components/elements/TabBarBaseComponent.js +6 -5
  5. package/lib/commonjs/components/elements/TabBarBaseComponent.js.map +1 -1
  6. package/lib/commonjs/components/elements/TabBarLabelBaseComponent.js +2 -4
  7. package/lib/commonjs/components/elements/TabBarLabelBaseComponent.js.map +1 -1
  8. package/lib/commonjs/components/wrappers/GestureWrapper.js +18 -26
  9. package/lib/commonjs/components/wrappers/GestureWrapper.js.map +1 -1
  10. package/lib/commonjs/components/wrappers/ScreenWrapper.js +4 -4
  11. package/lib/commonjs/components/wrappers/ScreenWrapper.js.map +1 -1
  12. package/lib/commonjs/components/wrappers/ScrollView.js +27 -16
  13. package/lib/commonjs/components/wrappers/ScrollView.js.map +1 -1
  14. package/lib/commonjs/context/Context.helpers.js +19 -0
  15. package/lib/commonjs/context/Context.helpers.js.map +1 -0
  16. package/lib/commonjs/context/Context.hooks.js +216 -0
  17. package/lib/commonjs/context/Context.hooks.js.map +1 -0
  18. package/lib/commonjs/context/Context.js +68 -0
  19. package/lib/commonjs/context/Context.js.map +1 -0
  20. package/lib/commonjs/hooks/useHeader.js +30 -0
  21. package/lib/commonjs/hooks/useHeader.js.map +1 -0
  22. package/lib/commonjs/hooks/useScreenGesture.js +21 -0
  23. package/lib/commonjs/hooks/useScreenGesture.js.map +1 -0
  24. package/lib/commonjs/hooks/useScreenProperties.js +21 -0
  25. package/lib/commonjs/hooks/useScreenProperties.js.map +1 -0
  26. package/lib/commonjs/hooks/useScreenScrollable.js +64 -0
  27. package/lib/commonjs/hooks/useScreenScrollable.js.map +1 -0
  28. package/lib/commonjs/hooks/useTabContext.js +11 -0
  29. package/lib/commonjs/hooks/useTabContext.js.map +1 -0
  30. package/lib/commonjs/hooks/useTabOffset.js +18 -0
  31. package/lib/commonjs/hooks/useTabOffset.js.map +1 -0
  32. package/lib/commonjs/index.js +34 -80
  33. package/lib/commonjs/index.js.map +1 -1
  34. package/lib/commonjs/navigator/createReanimatedTopTabNavigator.js +14 -29
  35. package/lib/commonjs/navigator/createReanimatedTopTabNavigator.js.map +1 -1
  36. package/lib/commonjs/services/Warning.service.js +16 -0
  37. package/lib/commonjs/services/Warning.service.js.map +1 -0
  38. package/lib/module/components/ReanimatedTopTab/ReanimatedTabView.js +8 -6
  39. package/lib/module/components/ReanimatedTopTab/ReanimatedTabView.js.map +1 -1
  40. package/lib/module/components/elements/TabBarBaseComponent.js +5 -4
  41. package/lib/module/components/elements/TabBarBaseComponent.js.map +1 -1
  42. package/lib/module/components/elements/TabBarLabelBaseComponent.js +2 -4
  43. package/lib/module/components/elements/TabBarLabelBaseComponent.js.map +1 -1
  44. package/lib/module/components/wrappers/GestureWrapper.js +18 -27
  45. package/lib/module/components/wrappers/GestureWrapper.js.map +1 -1
  46. package/lib/module/components/wrappers/ScreenWrapper.js +3 -3
  47. package/lib/module/components/wrappers/ScreenWrapper.js.map +1 -1
  48. package/lib/module/components/wrappers/ScrollView.js +23 -12
  49. package/lib/module/components/wrappers/ScrollView.js.map +1 -1
  50. package/lib/module/context/Context.helpers.js +15 -0
  51. package/lib/module/context/Context.helpers.js.map +1 -0
  52. package/lib/module/context/Context.hooks.js +213 -0
  53. package/lib/module/context/Context.hooks.js.map +1 -0
  54. package/lib/module/context/Context.js +64 -0
  55. package/lib/module/context/Context.js.map +1 -0
  56. package/lib/module/hooks/useHeader.js +25 -0
  57. package/lib/module/hooks/useHeader.js.map +1 -0
  58. package/lib/module/hooks/useScreenGesture.js +16 -0
  59. package/lib/module/hooks/useScreenGesture.js.map +1 -0
  60. package/lib/module/hooks/useScreenProperties.js +16 -0
  61. package/lib/module/hooks/useScreenProperties.js.map +1 -0
  62. package/lib/module/hooks/useScreenScrollable.js +57 -0
  63. package/lib/module/hooks/useScreenScrollable.js.map +1 -0
  64. package/lib/module/hooks/useTabContext.js +6 -0
  65. package/lib/module/hooks/useTabContext.js.map +1 -0
  66. package/lib/module/hooks/useTabOffset.js +12 -0
  67. package/lib/module/hooks/useTabOffset.js.map +1 -0
  68. package/lib/module/index.js +33 -8
  69. package/lib/module/index.js.map +1 -1
  70. package/lib/module/navigator/createReanimatedTopTabNavigator.js +13 -27
  71. package/lib/module/navigator/createReanimatedTopTabNavigator.js.map +1 -1
  72. package/lib/module/services/Warning.service.js +12 -0
  73. package/lib/module/services/Warning.service.js.map +1 -0
  74. package/lib/typescript/src/components/ReanimatedTopTab/AnimationHelper.d.ts.map +1 -0
  75. package/lib/typescript/src/components/ReanimatedTopTab/ReanimatedTabView.d.ts.map +1 -0
  76. package/lib/typescript/src/components/ReanimatedTopTab/types.d.ts.map +1 -0
  77. package/lib/typescript/{module/src → src}/components/elements/TabBarBaseComponent.d.ts +1 -2
  78. package/lib/typescript/src/components/elements/TabBarBaseComponent.d.ts.map +1 -0
  79. package/lib/typescript/{commonjs/src → src}/components/elements/TabBarLabelBaseComponent.d.ts +1 -2
  80. package/lib/typescript/src/components/elements/TabBarLabelBaseComponent.d.ts.map +1 -0
  81. package/lib/typescript/src/components/wrappers/GestureWrapper.d.ts +7 -0
  82. package/lib/typescript/src/components/wrappers/GestureWrapper.d.ts.map +1 -0
  83. package/lib/typescript/src/components/wrappers/ScreenWrapper.d.ts.map +1 -0
  84. package/lib/typescript/src/components/wrappers/ScrollView.d.ts +5 -0
  85. package/lib/typescript/src/components/wrappers/ScrollView.d.ts.map +1 -0
  86. package/lib/typescript/{commonjs/src/context/TopTabContext.d.ts → src/context/Context.d.ts} +2 -2
  87. package/lib/typescript/src/context/Context.d.ts.map +1 -0
  88. package/lib/typescript/src/context/Context.helpers.d.ts +4 -0
  89. package/lib/typescript/src/context/Context.helpers.d.ts.map +1 -0
  90. package/lib/typescript/src/context/Context.hooks.d.ts +15 -0
  91. package/lib/typescript/src/context/Context.hooks.d.ts.map +1 -0
  92. package/lib/typescript/src/hooks/useHeader.d.ts +10 -0
  93. package/lib/typescript/src/hooks/useHeader.d.ts.map +1 -0
  94. package/lib/typescript/src/hooks/useScreenGesture.d.ts +2 -0
  95. package/lib/typescript/src/hooks/useScreenGesture.d.ts.map +1 -0
  96. package/lib/typescript/src/hooks/useScreenProperties.d.ts +10 -0
  97. package/lib/typescript/src/hooks/useScreenProperties.d.ts.map +1 -0
  98. package/lib/typescript/src/hooks/useScreenScrollable.d.ts +14 -0
  99. package/lib/typescript/src/hooks/useScreenScrollable.d.ts.map +1 -0
  100. package/lib/typescript/src/hooks/useTabContext.d.ts +2 -0
  101. package/lib/typescript/src/hooks/useTabContext.d.ts.map +1 -0
  102. package/lib/typescript/src/hooks/useTabOffset.d.ts +2 -0
  103. package/lib/typescript/src/hooks/useTabOffset.d.ts.map +1 -0
  104. package/lib/typescript/src/index.d.ts +45 -0
  105. package/lib/typescript/src/index.d.ts.map +1 -0
  106. package/lib/typescript/src/navigator/createReanimatedTopTabNavigator.d.ts.map +1 -0
  107. package/lib/typescript/src/services/Warning.service.d.ts +5 -0
  108. package/lib/typescript/src/services/Warning.service.d.ts.map +1 -0
  109. package/lib/typescript/{module/src → src}/types.d.ts +24 -17
  110. package/lib/typescript/src/types.d.ts.map +1 -0
  111. package/package.json +24 -38
  112. package/src/components/ReanimatedTopTab/ReanimatedTabView.tsx +7 -6
  113. package/src/components/elements/TabBarBaseComponent.tsx +7 -3
  114. package/src/components/elements/TabBarLabelBaseComponent.tsx +4 -3
  115. package/src/components/wrappers/GestureWrapper.tsx +27 -29
  116. package/src/components/wrappers/ScreenWrapper.tsx +4 -3
  117. package/src/components/wrappers/ScrollView.tsx +33 -19
  118. package/src/context/Context.helpers.tsx +10 -0
  119. package/src/context/Context.hooks.ts +253 -0
  120. package/src/context/Context.tsx +69 -0
  121. package/src/hooks/useHeader.ts +30 -0
  122. package/src/hooks/useScreenGesture.ts +13 -0
  123. package/src/hooks/useScreenProperties.ts +11 -0
  124. package/src/hooks/useScreenScrollable.ts +69 -0
  125. package/src/hooks/useTabContext.ts +4 -0
  126. package/src/hooks/useTabOffset.ts +8 -0
  127. package/src/index.tsx +34 -10
  128. package/src/navigator/createReanimatedTopTabNavigator.tsx +8 -32
  129. package/src/services/Warning.service.ts +11 -0
  130. package/src/types.ts +23 -19
  131. package/lib/commonjs/context/TopTabContext.hooks.js +0 -48
  132. package/lib/commonjs/context/TopTabContext.hooks.js.map +0 -1
  133. package/lib/commonjs/context/TopTabContext.js +0 -86
  134. package/lib/commonjs/context/TopTabContext.js.map +0 -1
  135. package/lib/commonjs/hooks/TopTab.hooks.js +0 -120
  136. package/lib/commonjs/hooks/TopTab.hooks.js.map +0 -1
  137. package/lib/module/context/TopTabContext.hooks.js +0 -44
  138. package/lib/module/context/TopTabContext.hooks.js.map +0 -1
  139. package/lib/module/context/TopTabContext.js +0 -82
  140. package/lib/module/context/TopTabContext.js.map +0 -1
  141. package/lib/module/hooks/TopTab.hooks.js +0 -110
  142. package/lib/module/hooks/TopTab.hooks.js.map +0 -1
  143. package/lib/typescript/commonjs/src/components/ReanimatedTopTab/AnimationHelper.d.ts.map +0 -1
  144. package/lib/typescript/commonjs/src/components/ReanimatedTopTab/ReanimatedTabView.d.ts.map +0 -1
  145. package/lib/typescript/commonjs/src/components/ReanimatedTopTab/types.d.ts.map +0 -1
  146. package/lib/typescript/commonjs/src/components/elements/TabBarBaseComponent.d.ts +0 -24
  147. package/lib/typescript/commonjs/src/components/elements/TabBarBaseComponent.d.ts.map +0 -1
  148. package/lib/typescript/commonjs/src/components/elements/TabBarLabelBaseComponent.d.ts.map +0 -1
  149. package/lib/typescript/commonjs/src/components/wrappers/GestureWrapper.d.ts +0 -2
  150. package/lib/typescript/commonjs/src/components/wrappers/GestureWrapper.d.ts.map +0 -1
  151. package/lib/typescript/commonjs/src/components/wrappers/ScreenWrapper.d.ts.map +0 -1
  152. package/lib/typescript/commonjs/src/components/wrappers/ScrollView.d.ts +0 -6
  153. package/lib/typescript/commonjs/src/components/wrappers/ScrollView.d.ts.map +0 -1
  154. package/lib/typescript/commonjs/src/context/TopTabContext.d.ts.map +0 -1
  155. package/lib/typescript/commonjs/src/context/TopTabContext.hooks.d.ts +0 -5
  156. package/lib/typescript/commonjs/src/context/TopTabContext.hooks.d.ts.map +0 -1
  157. package/lib/typescript/commonjs/src/hooks/TopTab.hooks.d.ts +0 -33
  158. package/lib/typescript/commonjs/src/hooks/TopTab.hooks.d.ts.map +0 -1
  159. package/lib/typescript/commonjs/src/index.d.ts +0 -10
  160. package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
  161. package/lib/typescript/commonjs/src/navigator/createReanimatedTopTabNavigator.d.ts.map +0 -1
  162. package/lib/typescript/commonjs/src/types.d.ts +0 -56
  163. package/lib/typescript/commonjs/src/types.d.ts.map +0 -1
  164. package/lib/typescript/module/src/components/ReanimatedTopTab/AnimationHelper.d.ts +0 -11
  165. package/lib/typescript/module/src/components/ReanimatedTopTab/AnimationHelper.d.ts.map +0 -1
  166. package/lib/typescript/module/src/components/ReanimatedTopTab/ReanimatedTabView.d.ts +0 -14
  167. package/lib/typescript/module/src/components/ReanimatedTopTab/ReanimatedTabView.d.ts.map +0 -1
  168. package/lib/typescript/module/src/components/ReanimatedTopTab/types.d.ts +0 -30
  169. package/lib/typescript/module/src/components/ReanimatedTopTab/types.d.ts.map +0 -1
  170. package/lib/typescript/module/src/components/elements/TabBarBaseComponent.d.ts.map +0 -1
  171. package/lib/typescript/module/src/components/elements/TabBarLabelBaseComponent.d.ts +0 -8
  172. package/lib/typescript/module/src/components/elements/TabBarLabelBaseComponent.d.ts.map +0 -1
  173. package/lib/typescript/module/src/components/wrappers/GestureWrapper.d.ts +0 -2
  174. package/lib/typescript/module/src/components/wrappers/GestureWrapper.d.ts.map +0 -1
  175. package/lib/typescript/module/src/components/wrappers/ScreenWrapper.d.ts +0 -6
  176. package/lib/typescript/module/src/components/wrappers/ScreenWrapper.d.ts.map +0 -1
  177. package/lib/typescript/module/src/components/wrappers/ScrollView.d.ts +0 -6
  178. package/lib/typescript/module/src/components/wrappers/ScrollView.d.ts.map +0 -1
  179. package/lib/typescript/module/src/context/TopTabContext.d.ts +0 -4
  180. package/lib/typescript/module/src/context/TopTabContext.d.ts.map +0 -1
  181. package/lib/typescript/module/src/context/TopTabContext.hooks.d.ts +0 -5
  182. package/lib/typescript/module/src/context/TopTabContext.hooks.d.ts.map +0 -1
  183. package/lib/typescript/module/src/hooks/TopTab.hooks.d.ts +0 -33
  184. package/lib/typescript/module/src/hooks/TopTab.hooks.d.ts.map +0 -1
  185. package/lib/typescript/module/src/index.d.ts +0 -10
  186. package/lib/typescript/module/src/index.d.ts.map +0 -1
  187. package/lib/typescript/module/src/navigator/createReanimatedTopTabNavigator.d.ts +0 -4
  188. package/lib/typescript/module/src/navigator/createReanimatedTopTabNavigator.d.ts.map +0 -1
  189. package/lib/typescript/module/src/types.d.ts.map +0 -1
  190. package/src/context/TopTabContext.hooks.ts +0 -55
  191. package/src/context/TopTabContext.tsx +0 -115
  192. package/src/hooks/TopTab.hooks.ts +0 -112
  193. /package/lib/{typescript/commonjs → commonjs}/package.json +0 -0
  194. /package/lib/{typescript/module → module}/package.json +0 -0
  195. /package/lib/typescript/{commonjs/src → src}/components/ReanimatedTopTab/AnimationHelper.d.ts +0 -0
  196. /package/lib/typescript/{commonjs/src → src}/components/ReanimatedTopTab/ReanimatedTabView.d.ts +0 -0
  197. /package/lib/typescript/{commonjs/src → src}/components/ReanimatedTopTab/types.d.ts +0 -0
  198. /package/lib/typescript/{commonjs/src → src}/components/wrappers/ScreenWrapper.d.ts +0 -0
  199. /package/lib/typescript/{commonjs/src → src}/navigator/createReanimatedTopTabNavigator.d.ts +0 -0
@@ -0,0 +1,8 @@
1
+ // returns read-only property
2
+ import { useTabContext } from './useTabContext';
3
+ import { useDerivedValue } from 'react-native-reanimated';
4
+
5
+ export const useTabOffset = () => {
6
+ const { transformationX } = useTabContext();
7
+ return useDerivedValue(() => transformationX.value);
8
+ };
package/src/index.tsx CHANGED
@@ -1,15 +1,39 @@
1
- export { Provider, Context } from './context/TopTabContext';
1
+ import { ScrollView } from './components/wrappers/ScrollView';
2
+ import { ScreenWrapper } from './components/wrappers/ScreenWrapper';
3
+ import { TabBarBaseComponent } from './components/elements/TabBarBaseComponent';
4
+ import { TabBarLabelBaseComponent } from './components/elements/TabBarLabelBaseComponent';
5
+ import { useEffect } from 'react';
6
+ import { WarningService } from './services/Warning.service';
7
+ import { useTabContext } from './hooks/useTabContext';
8
+ import { useTabOffset } from './hooks/useTabOffset';
9
+ import { useScreenGesture } from './hooks/useScreenGesture';
10
+ import { useScreenScrollable } from './hooks/useScreenScrollable';
11
+ import { useScreenProperties } from './hooks/useScreenProperties';
12
+ import { useHeader } from './hooks/useHeader';
13
+
14
+ export { type ReanimatedTopTabNavigation } from './types';
2
15
  export { createReanimatedTopTabNavigator } from './navigator/createReanimatedTopTabNavigator';
3
- export { ScrollView } from './components/wrappers/ScrollView';
4
- export { ScreenWrapper } from './components/wrappers/ScreenWrapper';
5
- export { GestureWrapper } from './components/wrappers/GestureWrapper';
6
- export { TabBarBaseComponent } from './components/elements/TabBarBaseComponent';
7
- export { TabBarLabelBaseComponent } from './components/elements/TabBarLabelBaseComponent';
8
- export {
9
- useTabContext,
16
+
17
+ const _useTabContext = () => {
18
+ useEffect(() => {
19
+ WarningService.warn();
20
+ }, []);
21
+
22
+ return useTabContext();
23
+ };
24
+
25
+ export const TabHooks = {
10
26
  useHeader,
11
27
  useScreenProperties,
12
28
  useScreenScrollable,
13
29
  useScreenGesture,
14
- } from './hooks/TopTab.hooks';
15
- export { type ReanimatedTopTabNavigation } from './types';
30
+ useTabContext: _useTabContext,
31
+ useTabOffset,
32
+ };
33
+
34
+ export const Tab = {
35
+ ScrollView,
36
+ ScreenWrapper,
37
+ TabBarBaseComponent,
38
+ TabBarLabelBaseComponent,
39
+ };
@@ -12,17 +12,14 @@ import {
12
12
  type RenderTabsParams,
13
13
  TabBarBaseComponent,
14
14
  } from '../components/elements/TabBarBaseComponent';
15
- import { Provider } from '../context/TopTabContext';
15
+ import { Provider } from '../context/Context';
16
16
  import { type ReanimatedTopTabNavigation } from '../types';
17
17
  import { omit } from 'lodash';
18
- import { useCallback, useMemo, useRef } from 'react';
19
- import { Gesture } from 'react-native-gesture-handler';
20
- import Reanimated, {
21
- makeMutable,
22
- type SharedValue,
23
- } from 'react-native-reanimated';
18
+ import { useCallback, useMemo } from 'react';
19
+ import Reanimated, { type SharedValue } from 'react-native-reanimated';
24
20
  import type { ReanimatedTabViewTypes } from '../components/ReanimatedTopTab/types';
25
21
  import { ReanimatedTabView } from '../components/ReanimatedTopTab/ReanimatedTabView';
22
+ import { ContextHooks } from '../context/Context.hooks';
26
23
 
27
24
  const TabViewNavigator = ({
28
25
  HeaderComponent,
@@ -51,31 +48,10 @@ const TabViewNavigator = ({
51
48
  if (!config) {
52
49
  _config = state.routes.map(() => 'normal');
53
50
  }
54
- const screenProperties = useRef(
55
- state.routes.reduce(
56
- (prev, route) => ({
57
- ...prev,
58
- [route.key]: {
59
- innerLayout: makeMutable({
60
- height: 0,
61
- width: 0,
62
- x: 0,
63
- y: 0,
64
- }),
65
- nativeGesture: Gesture.Native(),
66
- outerLayout: makeMutable({
67
- height: 0,
68
- width: 0,
69
- x: 0,
70
- y: 0,
71
- }),
72
- scrollY: makeMutable(0),
73
- },
74
- }),
75
- {} as ReanimatedTopTabNavigation.ContextType['screenProperties']
76
- )
77
- ).current;
78
51
 
52
+ const context = ContextHooks.usePrepareContext({ state });
53
+
54
+ //NOTE: all belows reefers to Tabs component directly. Consider to move it somewhere
79
55
  const onIndexChange =
80
56
  (
81
57
  currentScreenIndex: SharedValue<number>,
@@ -142,7 +118,7 @@ const TabViewNavigator = ({
142
118
  descriptors[route.key]?.render();
143
119
 
144
120
  return (
145
- <Provider config={_config} screenProperties={screenProperties}>
121
+ <Provider config={_config} context={context}>
146
122
  {({
147
123
  currentScreenIndex,
148
124
  gestureEnabled,
@@ -0,0 +1,11 @@
1
+ export const WarningService = {
2
+ hasWarned: false,
3
+ warn() {
4
+ if (__DEV__ && !this.hasWarned) {
5
+ console.warn(
6
+ '[react-navigation-reanimated-top-tabs]: You are directly using the tab context, which may lead to unexpected behavior. Please use the provided hooks or API for better stability.'
7
+ );
8
+ this.hasWarned = true;
9
+ }
10
+ },
11
+ };
package/src/types.ts CHANGED
@@ -3,15 +3,11 @@ import * as React from 'react';
3
3
  import { type ReactNode } from 'react';
4
4
  import { type LayoutRectangle } from 'react-native';
5
5
  import { type NativeGesture } from 'react-native-gesture-handler';
6
- import { type SharedValue } from 'react-native-reanimated';
6
+ import Reanimated, { type SharedValue } from 'react-native-reanimated';
7
7
  import { type StackNavigationOptions } from '@react-navigation/stack';
8
8
 
9
9
  export namespace ReanimatedTopTabNavigation {
10
10
  export interface ContextType {
11
- screenRefs: {
12
- refs: { current: Record<string, { current: any }> };
13
- setRef(key: string, ref: any): void;
14
- };
15
11
  closeOffset: SharedValue<number>;
16
12
  config: string[];
17
13
  currentScreenIndex: SharedValue<number>;
@@ -19,19 +15,30 @@ export namespace ReanimatedTopTabNavigation {
19
15
  gestureEnabled: SharedValue<boolean>;
20
16
  headerHeight: SharedValue<number>;
21
17
  navHeight: SharedValue<number>;
22
- screenProperties: Record<
23
- string,
24
- {
25
- innerLayout: SharedValue<LayoutRectangle>;
26
- nativeGesture: NativeGesture;
27
- outerLayout: SharedValue<LayoutRectangle>;
28
- scrollY: SharedValue<number>;
29
- }
30
- >;
31
18
  topTabHeight: SharedValue<number>;
32
- topTapNativeRef: NativeGesture;
19
+ topTabNativeGesture: NativeGesture;
33
20
  transformationX: SharedValue<number>;
34
21
  transformationY: SharedValue<number>;
22
+ context: {
23
+ screen: {
24
+ properties: Record<
25
+ string,
26
+ {
27
+ innerLayout: SharedValue<LayoutRectangle>;
28
+ nativeGesture: NativeGesture;
29
+ outerLayout: SharedValue<LayoutRectangle>;
30
+ scrollY: SharedValue<number>;
31
+ scrollRef: { current: Reanimated.ScrollView | null };
32
+ }
33
+ >;
34
+ setRef(key: string, ref: Reanimated.ScrollView | null): void;
35
+ getRef(key: string): { current: Reanimated.ScrollView | null };
36
+ };
37
+ route: {
38
+ map: Record<number, string>;
39
+ getKeyForIndex(index: number): string;
40
+ };
41
+ };
35
42
  }
36
43
 
37
44
  export interface TabViewNavigatorProps {
@@ -45,10 +52,7 @@ export namespace ReanimatedTopTabNavigation {
45
52
  screenOptions?: StackNavigationOptions;
46
53
  }
47
54
 
48
- export type TopTabContextProps = Pick<
49
- ContextType,
50
- 'screenProperties' | 'config'
51
- > & {
55
+ export type TopTabContextProps = Pick<ContextType, 'config' | 'context'> & {
52
56
  children: (props: ContextType) => React.ReactNode;
53
57
  };
54
58
 
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TopTabContextHooks = void 0;
7
- var _reactNativeReanimated = require("react-native-reanimated");
8
- const useResetApproachingScreenScrollOffset = ({
9
- screenRefs,
10
- transformationX,
11
- screenProperties,
12
- currentYPosition
13
- }) => {
14
- const resetApproachingScreenOffset = (index, shouldReset) => {
15
- if (shouldReset) {
16
- //NOTE: use reanimated scrollTo does not work
17
- const {
18
- scrollTo
19
- } = Object.values(screenRefs.refs.current)[index]?.current ?? {
20
- scrollTo: () => null
21
- };
22
- scrollTo({
23
- y: 0,
24
- animated: false
25
- });
26
- }
27
- };
28
- (0, _reactNativeReanimated.useAnimatedReaction)(() => transformationX.value, (current, previous) => {
29
- const approachingIndex = getTargetIndex(current, previous);
30
- const approachingScreenOffset = Object.values(screenProperties).map(({
31
- scrollY
32
- }) => scrollY.value)[approachingIndex] ?? -1;
33
- (0, _reactNativeReanimated.runOnJS)(resetApproachingScreenOffset)(approachingIndex, approachingScreenOffset > 0 && currentYPosition.value === 0);
34
- });
35
- };
36
- function getTargetIndex(currentValue, previousValue) {
37
- 'worklet';
38
-
39
- if (currentValue > (previousValue ?? 0)) {
40
- return Math.ceil(currentValue);
41
- } else {
42
- return Math.floor(currentValue);
43
- }
44
- }
45
- const TopTabContextHooks = exports.TopTabContextHooks = {
46
- useResetApproachingScreenScrollOffset
47
- };
48
- //# sourceMappingURL=TopTabContext.hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNativeReanimated","require","useResetApproachingScreenScrollOffset","screenRefs","transformationX","screenProperties","currentYPosition","resetApproachingScreenOffset","index","shouldReset","scrollTo","Object","values","refs","current","y","animated","useAnimatedReaction","value","previous","approachingIndex","getTargetIndex","approachingScreenOffset","map","scrollY","runOnJS","currentValue","previousValue","Math","ceil","floor","TopTabContextHooks","exports"],"sourceRoot":"../../../src","sources":["context/TopTabContext.hooks.ts"],"mappings":";;;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAGA,MAAMC,qCAAqC,GAAGA,CAAC;EAC7CC,UAAU;EACVC,eAAe;EACfC,gBAAgB;EAChBC;AAIF,CAAC,KAAK;EACJ,MAAMC,4BAA4B,GAAGA,CACnCC,KAAa,EACbC,WAAoB,KACjB;IACH,IAAIA,WAAW,EAAE;MACf;MACA,MAAM;QAAEC;MAAS,CAAC,GAAGC,MAAM,CAACC,MAAM,CAACT,UAAU,CAACU,IAAI,CAACC,OAAO,CAAC,CAACN,KAAK,CAAC,EAC9DM,OAAO,IAAI;QAAEJ,QAAQ,EAAEA,CAAA,KAAM;MAAK,CAAC;MAEvCA,QAAQ,CAAC;QAAEK,CAAC,EAAE,CAAC;QAAEC,QAAQ,EAAE;MAAM,CAAC,CAAC;IACrC;EACF,CAAC;EAED,IAAAC,0CAAmB,EACjB,MAAMb,eAAe,CAACc,KAAK,EAC3B,CAACJ,OAAO,EAAEK,QAAQ,KAAK;IACrB,MAAMC,gBAAgB,GAAGC,cAAc,CAACP,OAAO,EAAEK,QAAQ,CAAC;IAE1D,MAAMG,uBAAuB,GAC3BX,MAAM,CAACC,MAAM,CAACP,gBAAgB,CAAC,CAACkB,GAAG,CAAC,CAAC;MAAEC;IAAQ,CAAC,KAAKA,OAAO,CAACN,KAAK,CAAC,CACjEE,gBAAgB,CACjB,IAAI,CAAC,CAAC;IAET,IAAAK,8BAAO,EAAClB,4BAA4B,CAAC,CACnCa,gBAAgB,EAChBE,uBAAuB,GAAG,CAAC,IAAIhB,gBAAgB,CAACY,KAAK,KAAK,CAC5D,CAAC;EACH,CACF,CAAC;AACH,CAAC;AAED,SAASG,cAAcA,CAACK,YAAoB,EAAEC,aAA4B,EAAE;EAC1E,SAAS;;EACT,IAAID,YAAY,IAAIC,aAAa,IAAI,CAAC,CAAC,EAAE;IACvC,OAAOC,IAAI,CAACC,IAAI,CAACH,YAAY,CAAC;EAChC,CAAC,MAAM;IACL,OAAOE,IAAI,CAACE,KAAK,CAACJ,YAAY,CAAC;EACjC;AACF;AAEO,MAAMK,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAAG;EAChC7B;AACF,CAAC","ignoreList":[]}
@@ -1,86 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Provider = exports.Context = void 0;
7
- var _react = require("react");
8
- var _reactNativeGestureHandler = require("react-native-gesture-handler");
9
- var _reactNativeReanimated = require("react-native-reanimated");
10
- var _TopTabHooks = require("../hooks/TopTab.hooks.js");
11
- var _TopTabContextHooks = require("./TopTabContext.hooks.js");
12
- var _jsxRuntime = require("react/jsx-runtime");
13
- const Context = exports.Context = /*#__PURE__*/(0, _react.createContext)({});
14
- const Provider = exports.Provider = /*#__PURE__*/(0, _react.memo)(({
15
- children,
16
- config,
17
- screenProperties
18
- }) => {
19
- const transformationY = (0, _reactNativeReanimated.useSharedValue)(0);
20
- const transformationX = (0, _reactNativeReanimated.useSharedValue)(0);
21
- const currentYPosition = (0, _reactNativeReanimated.useSharedValue)(0);
22
- const gestureEnabled = (0, _reactNativeReanimated.useSharedValue)(true);
23
- const currentScreenIndex = (0, _reactNativeReanimated.useSharedValue)(0);
24
- const navHeight = (0, _reactNativeReanimated.useSharedValue)(0);
25
- const headerHeight = (0, _reactNativeReanimated.useSharedValue)(0);
26
- const closeOffset = (0, _reactNativeReanimated.useSharedValue)(0);
27
- const topTabHeight = (0, _reactNativeReanimated.useSharedValue)(0);
28
- const topTapNativeRef = (0, _react.useRef)(_reactNativeGestureHandler.Gesture.Native()).current;
29
- const screenRefs = (0, _TopTabHooks.useScreenRefs)(Object.keys(screenProperties));
30
-
31
- //Hide header base on config
32
- const inputRange = (0, _reactNativeReanimated.useDerivedValue)(() => config.map((_, idx) => idx), [config]);
33
- const outputRange = (0, _reactNativeReanimated.useDerivedValue)(() => config.map(type => {
34
- switch (type) {
35
- case 'normal':
36
- return 0;
37
- case 'minimalized':
38
- return -headerHeight.value;
39
- default:
40
- return 0;
41
- }
42
- }), [config]);
43
- (0, _reactNativeReanimated.useAnimatedReaction)(() => transformationX.value, value => {
44
- if (currentYPosition.value === -headerHeight.value) return;
45
- transformationY.value = (0, _reactNativeReanimated.interpolate)(value, inputRange.value, outputRange.value, 'clamp');
46
- });
47
- _TopTabContextHooks.TopTabContextHooks.useResetApproachingScreenScrollOffset({
48
- screenRefs,
49
- currentYPosition,
50
- screenProperties,
51
- transformationX
52
- });
53
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(Context.Provider, {
54
- value: {
55
- closeOffset,
56
- config,
57
- currentScreenIndex,
58
- currentYPosition,
59
- gestureEnabled,
60
- headerHeight,
61
- navHeight,
62
- screenProperties,
63
- topTabHeight,
64
- topTapNativeRef,
65
- transformationX,
66
- transformationY,
67
- screenRefs
68
- },
69
- children: children({
70
- screenRefs,
71
- closeOffset,
72
- config,
73
- currentScreenIndex,
74
- currentYPosition,
75
- gestureEnabled,
76
- headerHeight,
77
- navHeight,
78
- screenProperties,
79
- topTabHeight,
80
- topTapNativeRef,
81
- transformationX,
82
- transformationY
83
- })
84
- });
85
- });
86
- //# sourceMappingURL=TopTabContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","_reactNativeGestureHandler","_reactNativeReanimated","_TopTabHooks","_TopTabContextHooks","_jsxRuntime","Context","exports","createContext","Provider","memo","children","config","screenProperties","transformationY","useSharedValue","transformationX","currentYPosition","gestureEnabled","currentScreenIndex","navHeight","headerHeight","closeOffset","topTabHeight","topTapNativeRef","useRef","Gesture","Native","current","screenRefs","useScreenRefs","Object","keys","inputRange","useDerivedValue","map","_","idx","outputRange","type","value","useAnimatedReaction","interpolate","TopTabContextHooks","useResetApproachingScreenScrollOffset","jsx"],"sourceRoot":"../../../src","sources":["context/TopTabContext.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,0BAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AAMA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AAA2D,IAAAK,WAAA,GAAAL,OAAA;AAEpD,MAAMM,OAAO,GAAAC,OAAA,CAAAD,OAAA,gBAAG,IAAAE,oBAAa,EAClC,CAAC,CACH,CAAC;AAEM,MAAMC,QAAQ,GAAAF,OAAA,CAAAE,QAAA,gBAAG,IAAAC,WAAI,EAC1B,CAAC;EACCC,QAAQ;EACRC,MAAM;EACNC;AAC6C,CAAC,KAAK;EACnD,MAAMC,eAAe,GAAG,IAAAC,qCAAc,EAAC,CAAC,CAAC;EACzC,MAAMC,eAAe,GAAG,IAAAD,qCAAc,EAAC,CAAC,CAAC;EACzC,MAAME,gBAAgB,GAAG,IAAAF,qCAAc,EAAC,CAAC,CAAC;EAE1C,MAAMG,cAAc,GAAG,IAAAH,qCAAc,EAAC,IAAI,CAAC;EAC3C,MAAMI,kBAAkB,GAAG,IAAAJ,qCAAc,EAAC,CAAC,CAAC;EAE5C,MAAMK,SAAS,GAAG,IAAAL,qCAAc,EAAC,CAAC,CAAC;E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wC,GAAA,EAACvC,OAAO,CAACG,QAAQ;IACf+B,KAAK,EAAE;MACLlB,WAAW;MACXV,MAAM;MACNO,kBAAkB;MAClBF,gBAAgB;MAChBC,cAAc;MACdG,YAAY;MACZD,SAAS;MACTP,gBAAgB;MAChBU,YAAY;MACZC,eAAe;MACfR,eAAe;MACfF,eAAe;MACfe;IACF,CAAE;IAAAlB,QAAA,EAEDA,QAAQ,CAAC;MACRkB,UAAU;MACVP,WAAW;MACXV,MAAM;MACNO,kBAAkB;MAClBF,gBAAgB;MAChBC,cAAc;MACdG,YAAY;MACZD,SAAS;MACTP,gBAAgB;MAChBU,YAAY;MACZC,eAAe;MACfR,eAAe;MACfF;IACF,CAAC;EAAC,CACc,CAAC;AAEvB,CACF,CAAC","ignoreList":[]}
@@ -1,120 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useTabContext = exports.useScreenScrollable = exports.useScreenRefs = exports.useScreenProperties = exports.useScreenGesture = exports.useHeader = void 0;
7
- var _native = require("@react-navigation/native");
8
- var _TopTabContext = require("../context/TopTabContext.js");
9
- var _react = require("react");
10
- var _reactNativeReanimated = require("react-native-reanimated");
11
- var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
12
- var _reactNative = require("react-native");
13
- const useTabContext = () => (0, _react.useContext)(_TopTabContext.Context);
14
- exports.useTabContext = useTabContext;
15
- const useScreenGesture = () => {
16
- const {
17
- key
18
- } = (0, _native.useRoute)();
19
- const {
20
- screenProperties
21
- } = useTabContext();
22
- const nativeRef = screenProperties[key]?.nativeGesture;
23
- if (!nativeRef) throw 'GestureRef does not exist for this route';
24
- return nativeRef;
25
- };
26
- exports.useScreenGesture = useScreenGesture;
27
- const useScreenScrollable = () => {
28
- const {
29
- key
30
- } = (0, _native.useRoute)();
31
- const {
32
- height
33
- } = (0, _reactNative.useWindowDimensions)();
34
- const {
35
- bottom
36
- } = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
37
- const {
38
- currentYPosition,
39
- gestureEnabled,
40
- headerHeight,
41
- screenProperties,
42
- topTabHeight,
43
- transformationY
44
- } = useTabContext();
45
-
46
- //TODO: Navigation header hook is available if Tabs are rendered inside the Stack (createNavigationStack())
47
- //useHeaderHeight();
48
- const navigationHeader = 50;
49
- const animatedProps = (0, _reactNativeReanimated.useAnimatedProps)(() => ({
50
- scrollEnabled: !gestureEnabled.value || currentYPosition.value === -headerHeight.value
51
- }));
52
- const onScroll = (0, _reactNativeReanimated.useAnimatedScrollHandler)(({
53
- contentOffset
54
- }) => {
55
- const scrollPosition = screenProperties[key]?.scrollY;
56
- if (!scrollPosition) throw 'ScrollPosition property does not exist for this route';
57
- scrollPosition.value = contentOffset.y;
58
- });
59
- const oppositeHeaderState = (0, _reactNativeReanimated.useDerivedValue)(() => transformationY.value >= 0 ? headerHeight.value : 0);
60
- const style = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
61
- minHeight: height - topTabHeight.value - oppositeHeaderState.value - navigationHeader
62
- }));
63
- return {
64
- animatedProps,
65
- bounces: false,
66
- contentContainerStyle: {
67
- paddingBottom: bottom
68
- },
69
- onScroll,
70
- style
71
- };
72
- };
73
- exports.useScreenScrollable = useScreenScrollable;
74
- const useScreenProperties = () => {
75
- const {
76
- key
77
- } = (0, _native.useRoute)();
78
- const {
79
- screenProperties
80
- } = useTabContext();
81
- const screen = screenProperties[key];
82
- if (!screen) throw 'No screen properties registered for this route';
83
- return screen;
84
- };
85
- exports.useScreenProperties = useScreenProperties;
86
- const useHeader = () => {
87
- const {
88
- headerHeight,
89
- transformationX
90
- } = useTabContext();
91
- const hideHeader = () => {
92
- transformationX.value = (0, _reactNativeReanimated.withTiming)(-headerHeight.value);
93
- };
94
- return {
95
- hideHeader
96
- };
97
- };
98
- exports.useHeader = useHeader;
99
- const useScreenRefs = keys => {
100
- const refs = {
101
- current: keys.reduce((prev, key) => ({
102
- ...prev,
103
- [key]: {
104
- current: null
105
- }
106
- }), {})
107
- };
108
- const setRef = (key, ref) => {
109
- refs.current = {
110
- ...refs.current,
111
- [key]: ref
112
- };
113
- };
114
- return {
115
- setRef,
116
- refs
117
- };
118
- };
119
- exports.useScreenRefs = useScreenRefs;
120
- //# sourceMappingURL=TopTab.hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_native","require","_TopTabContext","_react","_reactNativeReanimated","_reactNativeSafeAreaContext","_reactNative","useTabContext","useContext","Context","exports","useScreenGesture","key","useRoute","screenProperties","nativeRef","nativeGesture","useScreenScrollable","height","useWindowDimensions","bottom","useSafeAreaInsets","currentYPosition","gestureEnabled","headerHeight","topTabHeight","transformationY","navigationHeader","animatedProps","useAnimatedProps","scrollEnabled","value","onScroll","useAnimatedScrollHandler","contentOffset","scrollPosition","scrollY","y","oppositeHeaderState","useDerivedValue","style","useAnimatedStyle","minHeight","bounces","contentContainerStyle","paddingBottom","useScreenProperties","screen","useHeader","transformationX","hideHeader","withTiming","useScreenRefs","keys","refs","current","reduce","prev","setRef","ref"],"sourceRoot":"../../../src","sources":["hooks/TopTab.hooks.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AAOA,IAAAI,2BAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AAEO,MAAMM,aAAa,GAAGA,CAAA,KAAM,IAAAC,iBAAU,EAACC,sBAAO,CAAC;AAACC,OAAA,CAAAH,aAAA,GAAAA,aAAA;AAEhD,MAAMI,gBAAgB,GAAGA,CAAA,KAAM;EACpC,MAAM;IAAEC;EAAI,CAAC,GAAG,IAAAC,gBAAQ,EAAC,CAAC;EAC1B,MAAM;IAAEC;EAAiB,CAAC,GAAGP,aAAa,CAAC,CAAC;EAE5C,MAAMQ,SAAS,GAAGD,gBAAgB,CAACF,GAAG,CAAC,EAAEI,aAAa;EAEtD,IAAI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AAE,GAAGD,IAAI,CAACC,OAAO;MAAE,CAAC3C,GAAG,GAAG+C;IAAI,CAAC;EAChD,CAAC;EAED,OAAO;IAAED,MAAM;IAAEJ;EAAK,CAAC;AACzB,CAAC;AAAC5C,OAAA,CAAA0C,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- import { runOnJS, useAnimatedReaction } from 'react-native-reanimated';
4
- const useResetApproachingScreenScrollOffset = ({
5
- screenRefs,
6
- transformationX,
7
- screenProperties,
8
- currentYPosition
9
- }) => {
10
- const resetApproachingScreenOffset = (index, shouldReset) => {
11
- if (shouldReset) {
12
- //NOTE: use reanimated scrollTo does not work
13
- const {
14
- scrollTo
15
- } = Object.values(screenRefs.refs.current)[index]?.current ?? {
16
- scrollTo: () => null
17
- };
18
- scrollTo({
19
- y: 0,
20
- animated: false
21
- });
22
- }
23
- };
24
- useAnimatedReaction(() => transformationX.value, (current, previous) => {
25
- const approachingIndex = getTargetIndex(current, previous);
26
- const approachingScreenOffset = Object.values(screenProperties).map(({
27
- scrollY
28
- }) => scrollY.value)[approachingIndex] ?? -1;
29
- runOnJS(resetApproachingScreenOffset)(approachingIndex, approachingScreenOffset > 0 && currentYPosition.value === 0);
30
- });
31
- };
32
- function getTargetIndex(currentValue, previousValue) {
33
- 'worklet';
34
-
35
- if (currentValue > (previousValue ?? 0)) {
36
- return Math.ceil(currentValue);
37
- } else {
38
- return Math.floor(currentValue);
39
- }
40
- }
41
- export const TopTabContextHooks = {
42
- useResetApproachingScreenScrollOffset
43
- };
44
- //# sourceMappingURL=TopTabContext.hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["runOnJS","useAnimatedReaction","useResetApproachingScreenScrollOffset","screenRefs","transformationX","screenProperties","currentYPosition","resetApproachingScreenOffset","index","shouldReset","scrollTo","Object","values","refs","current","y","animated","value","previous","approachingIndex","getTargetIndex","approachingScreenOffset","map","scrollY","currentValue","previousValue","Math","ceil","floor","TopTab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H,YAAY,CAAC;EAChC,CAAC,MAAM;IACL,OAAOE,IAAI,CAACE,KAAK,CAACJ,YAAY,CAAC;EACjC;AACF;AAEA,OAAO,MAAMK,kBAAkB,GAAG;EAChC3B;AACF,CAAC","ignoreList":[]}
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- import { createContext, memo, useRef } from 'react';
4
- import { Gesture } from 'react-native-gesture-handler';
5
- import { interpolate, useAnimatedReaction, useDerivedValue, useSharedValue } from 'react-native-reanimated';
6
- import { useScreenRefs } from "../hooks/TopTab.hooks.js";
7
- import { TopTabContextHooks } from "./TopTabContext.hooks.js";
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- export const Context = /*#__PURE__*/createContext({});
10
- export const Provider = /*#__PURE__*/memo(({
11
- children,
12
- config,
13
- screenProperties
14
- }) => {
15
- const transformationY = useSharedValue(0);
16
- const transformationX = useSharedValue(0);
17
- const currentYPosition = useSharedValue(0);
18
- const gestureEnabled = useSharedValue(true);
19
- const currentScreenIndex = useSharedValue(0);
20
- const navHeight = useSharedValue(0);
21
- const headerHeight = useSharedValue(0);
22
- const closeOffset = useSharedValue(0);
23
- const topTabHeight = useSharedValue(0);
24
- const topTapNativeRef = useRef(Gesture.Native()).current;
25
- const screenRefs = useScreenRefs(Object.keys(screenProperties));
26
-
27
- //Hide header base on config
28
- const inputRange = useDerivedValue(() => config.map((_, idx) => idx), [config]);
29
- const outputRange = useDerivedValue(() => config.map(type => {
30
- switch (type) {
31
- case 'normal':
32
- return 0;
33
- case 'minimalized':
34
- return -headerHeight.value;
35
- default:
36
- return 0;
37
- }
38
- }), [config]);
39
- useAnimatedReaction(() => transformationX.value, value => {
40
- if (currentYPosition.value === -headerHeight.value) return;
41
- transformationY.value = interpolate(value, inputRange.value, outputRange.value, 'clamp');
42
- });
43
- TopTabContextHooks.useResetApproachingScreenScrollOffset({
44
- screenRefs,
45
- currentYPosition,
46
- screenProperties,
47
- transformationX
48
- });
49
- return /*#__PURE__*/_jsx(Context.Provider, {
50
- value: {
51
- closeOffset,
52
- config,
53
- currentScreenIndex,
54
- currentYPosition,
55
- gestureEnabled,
56
- headerHeight,
57
- navHeight,
58
- screenProperties,
59
- topTabHeight,
60
- topTapNativeRef,
61
- transformationX,
62
- transformationY,
63
- screenRefs
64
- },
65
- children: children({
66
- screenRefs,
67
- closeOffset,
68
- config,
69
- currentScreenIndex,
70
- currentYPosition,
71
- gestureEnabled,
72
- headerHeight,
73
- navHeight,
74
- screenProperties,
75
- topTabHeight,
76
- topTapNativeRef,
77
- transformationX,
78
- transformationY
79
- })
80
- });
81
- });
82
- //# sourceMappingURL=TopTabContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["createContext","memo","useRef","Gesture","interpolate","useAnimatedReaction","useDerivedValue","useSharedValue","useScreenRefs","TopTabContextHooks","jsx","_jsx","Context","Provider","children","config","screenProperties","transformationY","transformationX","currentYPosition","gestureEnabled","currentScreenIndex","navHeight","headerHeight","closeOffset","topTabHeight","topTapNativeRef","Native","current","screenRefs","Object","keys","inputRange","map","_","idx","outputRange","type","value","useResetApproachingScreenScrollOffset"],"sourceRoot":"../../../src","sources":["context/TopTabContext.tsx"],"mappings":";;AACA,SAASA,aAAa,EAAEC,IAAI,EAAEC,MAAM,QAAQ,OAAO;AACnD,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SACEC,WAAW,EACXC,mBAAmB,EACnBC,eAAe,EACfC,cAAc,QACT,yBAAyB;AAChC,SAASC,aAAa,QAAQ,0BAAuB;AACrD,SAASC,kBAAkB,QAAQ,0BAAuB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3D,OAAO,MAAMC,OAAO,gBAAGZ,aAAa,CAClC,CAAC,CACH,CAAC;AAED,OAAO,MAAMa,QAAQ,gBAAGZ,IAAI,CAC1B,CAAC;EACCa,QAAQ;EACRC,MAAM;EACNC;AAC6C,CAAC,KAAK;EACnD,MAAMC,eAAe,GAAGV,cAAc,CAAC,CAAC,CAAC;EACzC,MAAMW,eAAe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