|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + * @flow |
| 9 | + */ |
| 10 | + |
| 11 | +'use strict'; |
| 12 | + |
| 13 | +const requireNativeComponent = require('requireNativeComponent'); |
| 14 | + |
| 15 | +import type {SyntheticEvent} from 'CoreEventTypes'; |
| 16 | +import type {NativeComponent} from 'ReactNative'; |
| 17 | +import type {Node} from 'React'; |
| 18 | +import type {ViewStyleProp} from 'StyleSheet'; |
| 19 | + |
| 20 | +type PageScrollState = 'idle' | 'dragging' | 'settling'; |
| 21 | + |
| 22 | +type PageScrollEvent = SyntheticEvent< |
| 23 | + $ReadOnly<{| |
| 24 | + position: number, |
| 25 | + offset: number, |
| 26 | + |}>, |
| 27 | +>; |
| 28 | + |
| 29 | +type PageScrollStateChangedEvent = SyntheticEvent< |
| 30 | + $ReadOnly<{| |
| 31 | + pageScrollState: PageScrollState, |
| 32 | + |}>, |
| 33 | +>; |
| 34 | + |
| 35 | +type PageSelectedEvent = SyntheticEvent< |
| 36 | + $ReadOnly<{| |
| 37 | + position: number, |
| 38 | + |}>, |
| 39 | +>; |
| 40 | + |
| 41 | +type NativeProps = $ReadOnly<{| |
| 42 | + /** |
| 43 | + * Index of initial page that should be selected. Use `setPage` method to |
| 44 | + * update the page, and `onPageSelected` to monitor page changes |
| 45 | + */ |
| 46 | + initialPage?: ?number, |
| 47 | + |
| 48 | + /** |
| 49 | + * Executed when transitioning between pages (ether because of animation for |
| 50 | + * the requested page change or when user is swiping/dragging between pages) |
| 51 | + * The `event.nativeEvent` object for this callback will carry following data: |
| 52 | + * - position - index of first page from the left that is currently visible |
| 53 | + * - offset - value from range [0,1) describing stage between page transitions. |
| 54 | + * Value x means that (1 - x) fraction of the page at "position" index is |
| 55 | + * visible, and x fraction of the next page is visible. |
| 56 | + */ |
| 57 | + onPageScroll?: ?(e: PageScrollEvent) => void, |
| 58 | + |
| 59 | + /** |
| 60 | + * Function called when the page scrolling state has changed. |
| 61 | + * The page scrolling state can be in 3 states: |
| 62 | + * - idle, meaning there is no interaction with the page scroller happening at the time |
| 63 | + * - dragging, meaning there is currently an interaction with the page scroller |
| 64 | + * - settling, meaning that there was an interaction with the page scroller, and the |
| 65 | + * page scroller is now finishing it's closing or opening animation |
| 66 | + */ |
| 67 | + onPageScrollStateChanged?: ?(e: PageScrollStateChangedEvent) => void, |
| 68 | + |
| 69 | + /** |
| 70 | + * This callback will be called once ViewPager finish navigating to selected page |
| 71 | + * (when user swipes between pages). The `event.nativeEvent` object passed to this |
| 72 | + * callback will have following fields: |
| 73 | + * - position - index of page that has been selected |
| 74 | + */ |
| 75 | + onPageSelected?: ?(e: PageSelectedEvent) => void, |
| 76 | + |
| 77 | + /** |
| 78 | + * Blank space to show between pages. This is only visible while scrolling, pages are still |
| 79 | + * edge-to-edge. |
| 80 | + */ |
| 81 | + pageMargin?: ?number, |
| 82 | + |
| 83 | + /** |
| 84 | + * Whether enable showing peekFraction or not. If this is true, the preview of |
| 85 | + * last and next page will show in current screen. Defaults to false. |
| 86 | + */ |
| 87 | + |
| 88 | + peekEnabled?: ?boolean, |
| 89 | + |
| 90 | + /** |
| 91 | + * Determines whether the keyboard gets dismissed in response to a drag. |
| 92 | + * - 'none' (the default), drags do not dismiss the keyboard. |
| 93 | + * - 'on-drag', the keyboard is dismissed when a drag begins. |
| 94 | + */ |
| 95 | + keyboardDismissMode?: ?('none' | 'on-drag'), |
| 96 | + |
| 97 | + /** |
| 98 | + * When false, the content does not scroll. |
| 99 | + * The default value is true. |
| 100 | + */ |
| 101 | + scrollEnabled?: ?boolean, |
| 102 | + |
| 103 | + children?: Node, |
| 104 | + |
| 105 | + style?: ?ViewStyleProp, |
| 106 | +|}>; |
| 107 | + |
| 108 | +type ViewPagerNativeType = Class<NativeComponent<NativeProps>>; |
| 109 | + |
| 110 | +module.exports = ((requireNativeComponent( |
| 111 | + 'AndroidViewPager', |
| 112 | +): any): ViewPagerNativeType); |
0 commit comments