@onekeyfe/react-native-pager-view 1.1.35

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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +306 -0
  3. package/android/Android.mk +45 -0
  4. package/android/build.gradle +237 -0
  5. package/android/debug.keystore +0 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/registration.cpp +18 -0
  8. package/android/src/main/AndroidManifest.xml +4 -0
  9. package/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt +148 -0
  10. package/android/src/main/java/com/reactnativepagerview/PagerViewViewManager.kt +222 -0
  11. package/android/src/main/java/com/reactnativepagerview/PagerViewViewManagerImpl.kt +228 -0
  12. package/android/src/main/java/com/reactnativepagerview/PagerViewViewPackage.kt +17 -0
  13. package/android/src/main/java/com/reactnativepagerview/ViewPagerAdapter.kt +121 -0
  14. package/android/src/main/java/com/reactnativepagerview/ViewPagerViewHolder.kt +21 -0
  15. package/android/src/main/java/com/reactnativepagerview/event/PageScrollEvent.kt +47 -0
  16. package/android/src/main/java/com/reactnativepagerview/event/PageScrollStateChangedEvent.kt +34 -0
  17. package/android/src/main/java/com/reactnativepagerview/event/PageSelectedEvent.kt +38 -0
  18. package/ios/PagerView.xcodeproj/project.pbxproj +274 -0
  19. package/ios/RCTOnPageScrollEvent.h +14 -0
  20. package/ios/RCTOnPageScrollEvent.m +60 -0
  21. package/ios/RNCPagerViewComponentView.h +11 -0
  22. package/ios/RNCPagerViewComponentView.mm +704 -0
  23. package/lib/module/PagerView.js +136 -0
  24. package/lib/module/PagerView.js.map +1 -0
  25. package/lib/module/PagerViewNativeComponent.ts +82 -0
  26. package/lib/module/codegen-types.d.js +2 -0
  27. package/lib/module/codegen-types.d.js.map +1 -0
  28. package/lib/module/index.js +6 -0
  29. package/lib/module/index.js.map +1 -0
  30. package/lib/module/package.json +1 -0
  31. package/lib/module/usePagerView.js +106 -0
  32. package/lib/module/usePagerView.js.map +1 -0
  33. package/lib/module/utils.js +27 -0
  34. package/lib/module/utils.js.map +1 -0
  35. package/lib/typescript/package.json +1 -0
  36. package/lib/typescript/src/PagerView.d.ts +70 -0
  37. package/lib/typescript/src/PagerView.d.ts.map +1 -0
  38. package/lib/typescript/src/PagerViewNativeComponent.d.ts +51 -0
  39. package/lib/typescript/src/PagerViewNativeComponent.d.ts.map +1 -0
  40. package/lib/typescript/src/index.d.ts +10 -0
  41. package/lib/typescript/src/index.d.ts.map +1 -0
  42. package/lib/typescript/src/usePagerView.d.ts +38 -0
  43. package/lib/typescript/src/usePagerView.d.ts.map +1 -0
  44. package/lib/typescript/src/utils.d.ts +3 -0
  45. package/lib/typescript/src/utils.d.ts.map +1 -0
  46. package/package.json +101 -0
  47. package/react-native-pager-view.podspec +20 -0
  48. package/src/PagerView.tsx +170 -0
  49. package/src/PagerViewNativeComponent.ts +82 -0
  50. package/src/codegen-types.d.ts +28 -0
  51. package/src/index.tsx +27 -0
  52. package/src/usePagerView.ts +148 -0
  53. package/src/utils.tsx +22 -0
package/package.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "name": "@onekeyfe/react-native-pager-view",
3
+ "version": "1.1.35",
4
+ "description": "React Native wrapper for Android and iOS ViewPager",
5
+ "source": "./src/index.tsx",
6
+ "main": "./lib/module/index.js",
7
+ "types": "./lib/typescript/src/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "source": "./src/index.tsx",
12
+ "types": "./lib/typescript/src/index.d.ts",
13
+ "default": "./lib/module/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "src",
19
+ "lib",
20
+ "android",
21
+ "ios",
22
+ "react-native-pager-view.podspec",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "clean": "del-cli lib",
36
+ "prepare": "rm -rf lib && bob build",
37
+ "typecheck": "tsc -b",
38
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
+ "test": "jest",
40
+ "release": "yarn prepare && npm whoami && npm publish --access public"
41
+ },
42
+ "keywords": [
43
+ "react-native",
44
+ "ios",
45
+ "android"
46
+ ],
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/nicholasxuu/app-modules.git",
50
+ "directory": "native-views/react-native-pager-view"
51
+ },
52
+ "author": "OneKey",
53
+ "homepage": "https://github.com/nicholasxuu/app-modules#readme",
54
+ "license": "MIT",
55
+ "publishConfig": {
56
+ "registry": "https://registry.npmjs.org/",
57
+ "access": "public"
58
+ },
59
+ "devDependencies": {
60
+ "@types/react": "^19.2.0",
61
+ "react": "19.2.0",
62
+ "react-native": "0.83.0",
63
+ "react-native-builder-bob": "^0.40.13",
64
+ "typescript": "^5.9.2"
65
+ },
66
+ "peerDependencies": {
67
+ "react": "*",
68
+ "react-native": "*"
69
+ },
70
+ "react-native-builder-bob": {
71
+ "source": "src",
72
+ "output": "lib",
73
+ "targets": [
74
+ [
75
+ "module",
76
+ {
77
+ "esm": true
78
+ }
79
+ ],
80
+ [
81
+ "typescript",
82
+ {
83
+ "project": "tsconfig.build.json"
84
+ }
85
+ ]
86
+ ]
87
+ },
88
+ "codegenConfig": {
89
+ "name": "pagerview",
90
+ "type": "components",
91
+ "jsSrcsDir": "src",
92
+ "android": {
93
+ "javaPackageName": "com.reactnativepagerview"
94
+ },
95
+ "ios": {
96
+ "componentProvider": {
97
+ "RNCViewPager": "RNCPagerViewComponentView"
98
+ }
99
+ }
100
+ }
101
+ }
@@ -0,0 +1,20 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "react-native-pager-view"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.ios.deployment_target = "15.1"
14
+ s.source = { :git => "https://github.com/nicholasxuu/app-modules.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm}"
17
+
18
+ install_modules_dependencies(s)
19
+
20
+ end
@@ -0,0 +1,170 @@
1
+ import React from 'react';
2
+ import { Platform, Keyboard } from 'react-native';
3
+ import { I18nManager } from 'react-native';
4
+ import type * as ReactNative from 'react-native';
5
+
6
+ import {
7
+ childrenWithOverriddenStyle,
8
+ } from './utils';
9
+
10
+ import PagerViewNativeComponent, {
11
+ Commands as PagerViewNativeCommands,
12
+ OnPageScrollEventData,
13
+ OnPageScrollStateChangedEventData,
14
+ OnPageSelectedEventData,
15
+ NativeProps,
16
+ } from './PagerViewNativeComponent';
17
+
18
+
19
+ /**
20
+ * Container that allows to flip left and right between child views. Each
21
+ * child view of the `PagerView` will be treated as a separate page
22
+ * and will be stretched to fill the `PagerView`.
23
+ *
24
+ * It is important all children are `<View>`s and not composite components.
25
+ * You can set style properties like `padding` or `backgroundColor` for each
26
+ * child. It is also important that each child have a `key` prop.
27
+ *
28
+ * Example:
29
+ *
30
+ * ```
31
+ * render: function() {
32
+ * return (
33
+ * <PagerView
34
+ * style={styles.PagerView}
35
+ * initialPage={0}>
36
+ * <View style={styles.pageStyle} key="1">
37
+ * <Text>First page</Text>
38
+ * </View>
39
+ * <View style={styles.pageStyle} key="2">
40
+ * <Text>Second page</Text>
41
+ * </View>
42
+ * </PagerView>
43
+ * );
44
+ * }
45
+ *
46
+ * ...
47
+ *
48
+ * var styles = {
49
+ * ...
50
+ * PagerView: {
51
+ * flex: 1
52
+ * },
53
+ * pageStyle: {
54
+ * alignItems: 'center',
55
+ * padding: 20,
56
+ * }
57
+ * }
58
+ * ```
59
+ */
60
+
61
+ export class PagerView extends React.Component<NativeProps> {
62
+ private isScrolling = false;
63
+ pagerView: React.ElementRef<typeof PagerViewNativeComponent> | null = null;
64
+
65
+
66
+ private get deducedLayoutDirection() {
67
+ if (
68
+ !this.props.layoutDirection ||
69
+ //@ts-ignore fix it
70
+ this.props.layoutDirection === 'locale'
71
+ ) {
72
+ return I18nManager.isRTL ? 'rtl' : 'ltr';
73
+ } else {
74
+ return this.props.layoutDirection;
75
+ }
76
+ }
77
+
78
+ private _onPageScroll = (
79
+ e: ReactNative.NativeSyntheticEvent<OnPageScrollEventData>
80
+ ) => {
81
+ if (this.props.onPageScroll) {
82
+ this.props.onPageScroll(e);
83
+ }
84
+
85
+ // Not implemented on iOS yet
86
+ if (Platform.OS === 'android') {
87
+ if (this.props.keyboardDismissMode === 'on-drag') {
88
+ Keyboard.dismiss();
89
+ }
90
+ }
91
+ };
92
+
93
+ private _onPageScrollStateChanged = (
94
+ e: ReactNative.NativeSyntheticEvent<OnPageScrollStateChangedEventData>
95
+ ) => {
96
+ if (this.props.onPageScrollStateChanged) {
97
+ this.props.onPageScrollStateChanged(e);
98
+ }
99
+ this.isScrolling = e.nativeEvent.pageScrollState === 'dragging';
100
+ };
101
+
102
+ private _onPageSelected = (
103
+ e: ReactNative.NativeSyntheticEvent<OnPageSelectedEventData>
104
+ ) => {
105
+ if (this.props.onPageSelected) {
106
+ this.props.onPageSelected(e);
107
+ }
108
+ };
109
+
110
+ private _onMoveShouldSetResponderCapture = () => {
111
+ return this.isScrolling;
112
+ };
113
+
114
+ /**
115
+ * A helper function to scroll to a specific page in the PagerView.
116
+ * The transition between pages will be animated.
117
+ */
118
+ public setPage = (selectedPage: number) => {
119
+ if (this.pagerView) {
120
+ PagerViewNativeCommands.setPage(this.pagerView, selectedPage);
121
+ }
122
+ };
123
+
124
+ /**
125
+ * A helper function to scroll to a specific page in the PagerView.
126
+ * The transition between pages will *not* be animated.
127
+ */
128
+ public setPageWithoutAnimation = (selectedPage: number) => {
129
+ if (this.pagerView) {
130
+ PagerViewNativeCommands.setPageWithoutAnimation(
131
+ this.pagerView,
132
+ selectedPage
133
+ );
134
+ }
135
+ };
136
+
137
+ /**
138
+ * A helper function to enable/disable scroll imperatively
139
+ * The recommended way is using the scrollEnabled prop, however, there might be a case where a
140
+ * imperative solution is more useful (e.g. for not blocking an animation)
141
+ */
142
+ public setScrollEnabled = (scrollEnabled: boolean) => {
143
+ if (this.pagerView) {
144
+ PagerViewNativeCommands.setScrollEnabledImperatively(
145
+ this.pagerView,
146
+ scrollEnabled
147
+ );
148
+ }
149
+ };
150
+
151
+ render() {
152
+ return (
153
+ <PagerViewNativeComponent
154
+ {...this.props}
155
+ ref={(ref) => {
156
+ this.pagerView = ref;
157
+ }}
158
+ style={this.props.style}
159
+ layoutDirection={this.deducedLayoutDirection}
160
+ onPageScroll={this._onPageScroll}
161
+ onPageScrollStateChanged={this._onPageScrollStateChanged}
162
+ onPageSelected={this._onPageSelected}
163
+ onMoveShouldSetResponderCapture={
164
+ this._onMoveShouldSetResponderCapture
165
+ }
166
+ children={childrenWithOverriddenStyle(this.props.children)}
167
+ />
168
+ );
169
+ }
170
+ }
@@ -0,0 +1,82 @@
1
+ import type * as React from 'react';
2
+ import type { HostComponent, ViewProps } from 'react-native';
3
+ import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
4
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
5
+
6
+ import type {
7
+ DirectEventHandler,
8
+ Double,
9
+ Int32,
10
+ WithDefault,
11
+ } from 'react-native/Libraries/Types/CodegenTypes';
12
+
13
+ export type OnPageScrollEventData = Readonly<{
14
+ position: Double;
15
+ offset: Double;
16
+ }>;
17
+
18
+ export type OnPageSelectedEventData = Readonly<{
19
+ position: Double;
20
+ }>;
21
+
22
+ export type OnPageScrollStateChangedEventData = Readonly<{
23
+ pageScrollState: 'idle' | 'dragging' | 'settling';
24
+ }>;
25
+
26
+ export interface NativeProps extends ViewProps {
27
+ scrollEnabled?: WithDefault<boolean, true>;
28
+ layoutDirection?: WithDefault<'ltr' | 'rtl', 'ltr'>;
29
+ initialPage?: Int32;
30
+ orientation?: WithDefault<'horizontal' | 'vertical', 'horizontal'>;
31
+ offscreenPageLimit?: Int32;
32
+ pageMargin?: Int32;
33
+ overScrollMode?: WithDefault<'auto' | 'always' | 'never', 'auto'>;
34
+ overdrag?: WithDefault<boolean, false>;
35
+ keyboardDismissMode?: WithDefault<'none' | 'on-drag', 'none'>;
36
+ /**
37
+ * Controls the sensitivity of scroll gestures on Android.
38
+ * Higher values make scrolling less sensitive.
39
+ * Valid range: 2 - 8
40
+ * @platform android
41
+ */
42
+ scrollSensitivity?: Int32;
43
+ /**
44
+ * When true on an inner PagerView, enables gesture coordination with
45
+ * a parent (outer) PagerView. At sub-tab boundaries the inner pager's
46
+ * gesture recognizer will not begin, allowing the outer pager to take over.
47
+ * @platform ios
48
+ */
49
+ nestedScrollEnabled?: WithDefault<boolean, false>;
50
+ onPageScroll?: DirectEventHandler<OnPageScrollEventData>;
51
+ onPageSelected?: DirectEventHandler<OnPageSelectedEventData>;
52
+ onPageScrollStateChanged?: DirectEventHandler<OnPageScrollStateChangedEventData>;
53
+ }
54
+
55
+ type PagerViewViewType = HostComponent<NativeProps>;
56
+
57
+ export interface NativeCommands {
58
+ setPage: (
59
+ viewRef: React.ElementRef<PagerViewViewType>,
60
+ selectedPage: Int32
61
+ ) => void;
62
+ setPageWithoutAnimation: (
63
+ viewRef: React.ElementRef<PagerViewViewType>,
64
+ selectedPage: Int32
65
+ ) => void;
66
+ setScrollEnabledImperatively: (
67
+ viewRef: React.ElementRef<PagerViewViewType>,
68
+ scrollEnabled: boolean
69
+ ) => void;
70
+ }
71
+
72
+ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
73
+ supportedCommands: [
74
+ 'setPage',
75
+ 'setPageWithoutAnimation',
76
+ 'setScrollEnabledImperatively',
77
+ ],
78
+ });
79
+
80
+ export default codegenNativeComponent<NativeProps>(
81
+ 'RNCViewPager'
82
+ ) as HostComponent<NativeProps>;
@@ -0,0 +1,28 @@
1
+ declare module 'react-native/Libraries/Types/CodegenTypes' {
2
+ import type { NativeSyntheticEvent } from 'react-native';
3
+
4
+ export type Double = number;
5
+ export type Float = number;
6
+ export type Int32 = number;
7
+ export type WithDefault<T, V> = T;
8
+ export type DirectEventHandler<T> = (
9
+ event: NativeSyntheticEvent<T>
10
+ ) => void;
11
+ export type BubblingEventHandler<T> = (
12
+ event: NativeSyntheticEvent<T>
13
+ ) => void;
14
+ }
15
+
16
+ declare module 'react-native/Libraries/Utilities/codegenNativeComponent' {
17
+ import type { HostComponent } from 'react-native';
18
+
19
+ export default function codegenNativeComponent<P>(
20
+ componentName: string,
21
+ options?: {
22
+ interfaceOnly?: boolean;
23
+ paperComponentName?: string;
24
+ paperComponentNameDeprecated?: string;
25
+ excludedPlatforms?: ReadonlyArray<'iOS' | 'android'>;
26
+ }
27
+ ): HostComponent<P>;
28
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,27 @@
1
+ import type * as ReactNative from 'react-native';
2
+ import { PagerView } from './PagerView';
3
+ export default PagerView;
4
+ export * from './usePagerView';
5
+
6
+ import type {
7
+ OnPageScrollEventData as PagerViewOnPageScrollEventData,
8
+ OnPageSelectedEventData as PagerViewOnPageSelectedEventData,
9
+ OnPageScrollStateChangedEventData as PageScrollStateChangedNativeEventData,
10
+ NativeProps,
11
+ } from './PagerViewNativeComponent';
12
+
13
+ export type {
14
+ PagerViewOnPageScrollEventData,
15
+ PagerViewOnPageSelectedEventData,
16
+ PageScrollStateChangedNativeEventData,
17
+ NativeProps as PagerViewProps,
18
+ };
19
+
20
+ export type PagerViewOnPageScrollEvent =
21
+ ReactNative.NativeSyntheticEvent<PagerViewOnPageScrollEventData>;
22
+
23
+ export type PagerViewOnPageSelectedEvent =
24
+ ReactNative.NativeSyntheticEvent<PagerViewOnPageSelectedEventData>;
25
+
26
+ export type PageScrollStateChangedNativeEvent =
27
+ ReactNative.NativeSyntheticEvent<PageScrollStateChangedNativeEventData>;
@@ -0,0 +1,148 @@
1
+ import type * as ReactNative from 'react-native';
2
+ import type {
3
+ OnPageScrollEventData as PagerViewOnPageScrollEventData,
4
+ OnPageSelectedEventData as PagerViewOnPageSelectedEventData,
5
+ OnPageScrollStateChangedEventData as PageScrollStateChangedNativeEventData,
6
+ } from './PagerViewNativeComponent';
7
+
8
+ type PageScrollStateChangedNativeEvent =
9
+ ReactNative.NativeSyntheticEvent<PageScrollStateChangedNativeEventData>;
10
+
11
+ import { PagerView } from './PagerView';
12
+
13
+ import { Animated } from 'react-native';
14
+ import { useCallback, useMemo, useRef, useState } from 'react';
15
+
16
+ export type UsePagerViewProps = ReturnType<typeof usePagerView>;
17
+
18
+ const AnimatedPagerView = Animated.createAnimatedComponent(PagerView);
19
+
20
+ type UsePagerViewParams = {
21
+ pagesAmount: number;
22
+ };
23
+
24
+ export function usePagerView(
25
+ { pagesAmount }: UsePagerViewParams = { pagesAmount: 0 }
26
+ ) {
27
+ const ref = useRef<PagerView>(null);
28
+ const [pages, setPages] = useState<number[]>(
29
+ new Array(pagesAmount).fill('').map((_v, index) => index)
30
+ );
31
+ const [activePage, setActivePage] = useState(0);
32
+ const [isAnimated, setIsAnimated] = useState(true);
33
+ const [overdragEnabled, setOverdragEnabled] = useState(false);
34
+ const [scrollEnabled, setScrollEnabled] = useState(true);
35
+ const [scrollState, setScrollState] = useState('idle');
36
+ const [progress, setProgress] = useState({ position: 0, offset: 0 });
37
+ const onPageScrollOffset = useRef(new Animated.Value(0)).current;
38
+ const onPageScrollPosition = useRef(new Animated.Value(0)).current;
39
+ const onPageSelectedPosition = useRef(new Animated.Value(0)).current;
40
+
41
+ const setPage = useCallback(
42
+ (page: number) =>
43
+ isAnimated
44
+ ? ref.current?.setPage(page)
45
+ : ref.current?.setPageWithoutAnimation(page),
46
+ [isAnimated]
47
+ );
48
+
49
+ const addPage = useCallback(() => {
50
+ setPages((prevPages) => {
51
+ return [...prevPages, prevPages.length];
52
+ });
53
+ }, []);
54
+
55
+ const removePage = useCallback(() => {
56
+ setPages((prevPages) => {
57
+ if (prevPages.length === 1) {
58
+ return prevPages;
59
+ }
60
+ return prevPages.slice(0, prevPages.length - 1);
61
+ });
62
+ }, []);
63
+
64
+ const toggleAnimation = useCallback(
65
+ () => setIsAnimated((animated) => !animated),
66
+ []
67
+ );
68
+
69
+ const toggleScroll = useCallback(
70
+ () => setScrollEnabled((enabled) => !enabled),
71
+ []
72
+ );
73
+
74
+ const toggleOverdrag = useCallback(
75
+ () => setOverdragEnabled((enabled) => !enabled),
76
+ []
77
+ );
78
+
79
+ const onPageScroll = useMemo(
80
+ () =>
81
+ Animated.event<PagerViewOnPageScrollEventData>(
82
+ [
83
+ {
84
+ nativeEvent: {
85
+ offset: onPageScrollOffset,
86
+ position: onPageScrollPosition,
87
+ },
88
+ },
89
+ ],
90
+ {
91
+ listener: ({ nativeEvent: { offset, position } }) => {
92
+ setProgress({
93
+ position,
94
+ offset,
95
+ });
96
+ },
97
+ useNativeDriver: true,
98
+ }
99
+ ),
100
+ // eslint-disable-next-line react-hooks/exhaustive-deps
101
+ []
102
+ );
103
+
104
+ const onPageSelected = useMemo(
105
+ () =>
106
+ Animated.event<PagerViewOnPageSelectedEventData>(
107
+ [{ nativeEvent: { position: onPageSelectedPosition } }],
108
+ {
109
+ listener: ({ nativeEvent: { position } }) => {
110
+ setActivePage(position);
111
+ },
112
+ useNativeDriver: true,
113
+ }
114
+ ),
115
+ // eslint-disable-next-line react-hooks/exhaustive-deps
116
+ []
117
+ );
118
+
119
+ const onPageScrollStateChanged = useCallback(
120
+ (e: PageScrollStateChangedNativeEvent) => {
121
+ setScrollState(e.nativeEvent.pageScrollState);
122
+ },
123
+ []
124
+ );
125
+
126
+ return {
127
+ ref,
128
+ activePage,
129
+ isAnimated,
130
+ pages,
131
+ scrollState,
132
+ scrollEnabled,
133
+ progress,
134
+ overdragEnabled,
135
+ setPage,
136
+ addPage,
137
+ removePage,
138
+ toggleScroll,
139
+ toggleAnimation,
140
+ setProgress,
141
+ onPageScroll,
142
+ onPageSelected,
143
+ onPageScrollStateChanged,
144
+ toggleOverdrag,
145
+ AnimatedPagerView,
146
+ PagerView,
147
+ };
148
+ }
package/src/utils.tsx ADDED
@@ -0,0 +1,22 @@
1
+ import React, { Children, ReactNode } from 'react';
2
+ import { StyleSheet, View } from 'react-native';
3
+
4
+ export const childrenWithOverriddenStyle = (children?: ReactNode) => {
5
+ return Children.map(children, (child) => {
6
+ if (!React.isValidElement(child)) {
7
+ return null;
8
+ }
9
+
10
+ const element = child as React.ReactElement<any>;
11
+ return (
12
+ // Add a wrapper to ensure layout is calculated correctly
13
+ <View style={StyleSheet.absoluteFill} collapsable={false}>
14
+ {React.cloneElement(element, {
15
+ ...element.props,
16
+ // Override styles so that each page will fill the parent.
17
+ style: [element.props.style, StyleSheet.absoluteFill],
18
+ })}
19
+ </View>
20
+ );
21
+ });
22
+ };