diff --git a/.eslintignore b/.eslintignore index b3fb5252d99..5a62500ec7f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,6 +4,7 @@ # These are purely type definitions, no runtime code. Most of them # are third-party code, too, so naturally don't match our style. **/flow-typed/** +types/@react-navigation # These are type-tests, made up of code that gets type-checked but # never actually run. They're naturally full of dead code which diff --git a/.flowconfig b/.flowconfig index ef282554985..894d3757b87 100644 --- a/.flowconfig +++ b/.flowconfig @@ -120,7 +120,7 @@ module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' # This lets us write .js.flow files instead of libdefs. # Add more libraries as needed to this pattern with `\|`: `foo\|bar\|…`. -module.name_mapper='^\(sqlite3\)$' -> '/types/\0' +module.name_mapper='^\(sqlite3\|@react-navigation/bottom-tabs\)$' -> '/types/\0' suppress_type=$FlowIssue suppress_type=$FlowFixMe diff --git a/.prettierignore b/.prettierignore index 595a854ea03..88443ea1e3c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,6 +9,7 @@ flow-typed/@react-navigation # These are purely type definitions, no runtime code. Most of them # are third-party code, too, so naturally don't match our style. **/flow-typed/** +types/@react-navigation # Third-party code: react-native. We leave this code in the style we # received it in. diff --git a/__libdef-tests__/drawer_v5.x.x-test.js b/__libdef-tests__/drawer_v5.x.x-test.js new file mode 100644 index 00000000000..3c0a3a9d736 --- /dev/null +++ b/__libdef-tests__/drawer_v5.x.x-test.js @@ -0,0 +1,36 @@ +/* @flow strict-local */ +import { type NavigationProp } from '@react-navigation/drawer'; + +/* eslint-disable no-unused-vars */ + +function test_setParams() { + type NavProp

= NavigationProp<{| r: P |}, 'r'>; + + function test_happy(navigation: NavProp<{| a: number |}>) { + navigation.setParams({ a: 1 }); + } + + function test_accepts_missing(navigation: NavProp<{| a: number, b: number |}>) { + navigation.setParams({ a: 1 }); + } + + function test_rejects_extra(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[prop-missing] + navigation.setParams({ b: 1 }); + } + + function test_rejects_mismatch(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[incompatible-call] + navigation.setParams({ a: 'a' }); + } + + function test_rejects_object_to_void(navigation: NavProp) { + // $FlowExpectedError[incompatible-call] + navigation.setParams({ a: 1 }); + } + + function test_rejects_void_to_object(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[incompatible-call] + navigation.setParams(); + } +} diff --git a/__libdef-tests__/material-top-tabs_v5.x.x-test.js b/__libdef-tests__/material-top-tabs_v5.x.x-test.js new file mode 100644 index 00000000000..5b5a0b4a03f --- /dev/null +++ b/__libdef-tests__/material-top-tabs_v5.x.x-test.js @@ -0,0 +1,36 @@ +/* @flow strict-local */ +import { type NavigationProp } from '@react-navigation/material-top-tabs'; + +/* eslint-disable no-unused-vars */ + +function test_setParams() { + type NavProp

= NavigationProp<{| r: P |}, 'r'>; + + function test_happy(navigation: NavProp<{| a: number |}>) { + navigation.setParams({ a: 1 }); + } + + function test_accepts_missing(navigation: NavProp<{| a: number, b: number |}>) { + navigation.setParams({ a: 1 }); + } + + function test_rejects_extra(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[prop-missing] + navigation.setParams({ b: 1 }); + } + + function test_rejects_mismatch(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[incompatible-call] + navigation.setParams({ a: 'a' }); + } + + function test_rejects_object_to_void(navigation: NavProp) { + // $FlowExpectedError[incompatible-call] + navigation.setParams({ a: 1 }); + } + + function test_rejects_void_to_object(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[incompatible-call] + navigation.setParams(); + } +} diff --git a/__libdef-tests__/native_v5.x.x-test.js b/__libdef-tests__/native_v5.x.x-test.js new file mode 100644 index 00000000000..6ff0aec1e99 --- /dev/null +++ b/__libdef-tests__/native_v5.x.x-test.js @@ -0,0 +1,36 @@ +/* @flow strict-local */ +import { type NavigationProp } from '@react-navigation/native'; + +/* eslint-disable no-unused-vars */ + +function test_setParams() { + type NavProp

= NavigationProp<{| r: P |}, 'r'>; + + function test_happy(navigation: NavProp<{| a: number |}>) { + navigation.setParams({ a: 1 }); + } + + function test_accepts_missing(navigation: NavProp<{| a: number, b: number |}>) { + navigation.setParams({ a: 1 }); + } + + function test_rejects_extra(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[prop-missing] + navigation.setParams({ b: 1 }); + } + + function test_rejects_mismatch(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[incompatible-call] + navigation.setParams({ a: 'a' }); + } + + function test_rejects_object_to_void(navigation: NavProp) { + // $FlowExpectedError[incompatible-call] + navigation.setParams({ a: 1 }); + } + + function test_rejects_void_to_object(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[incompatible-call] + navigation.setParams(); + } +} diff --git a/flow-typed/@react-navigation/bottom-tabs_v5.x.x.js b/flow-typed/@react-navigation/bottom-tabs_v5.x.x.js deleted file mode 100644 index eceffc47a96..00000000000 --- a/flow-typed/@react-navigation/bottom-tabs_v5.x.x.js +++ /dev/null @@ -1,2042 +0,0 @@ -// flow-typed signature: e37ac5b72f5fe9ae743fbc011032560b -// flow-typed version: 3c17c8ecd5/@react-navigation/bottom-tabs_v5.x.x/flow_>=v0.104.x - -declare module '@react-navigation/bottom-tabs' { - - //--------------------------------------------------------------------------- - // SECTION 1: IDENTICAL TYPE DEFINITIONS - // This section is identical across all React Navigation libdefs and contains - // shared definitions. We wish we could make it DRY and import from a shared - // definition, but that isn't yet possible. - //--------------------------------------------------------------------------- - - /** - * We start with some definitions that we have copy-pasted from React Native - * source files. - */ - - // This is a bastardization of the true StyleObj type located in - // react-native/Libraries/StyleSheet/StyleSheetTypes. We unfortunately can't - // import that here, and it's too lengthy (and consequently too brittle) to - // copy-paste here either. - declare type StyleObj = - | null - | void - | number - | false - | '' - | $ReadOnlyArray - | {| [name: string]: any |}; - declare type ViewStyleProp = StyleObj; - declare type TextStyleProp = StyleObj; - declare type AnimatedViewStyleProp = StyleObj; - declare type AnimatedTextStyleProp = StyleObj; - - // Vaguely copied from - // react-native/Libraries/Animated/src/animations/Animation.js - declare type EndResult = { finished: boolean, ... }; - declare type EndCallback = (result: EndResult) => void; - declare interface Animation { - start( - fromValue: number, - onUpdate: (value: number) => void, - onEnd: ?EndCallback, - previousAnimation: ?Animation, - animatedValue: AnimatedValue, - ): void; - stop(): void; - } - declare type AnimationConfig = { - isInteraction?: boolean, - useNativeDriver: boolean, - onComplete?: ?EndCallback, - iterations?: number, - ... - }; - - // Vaguely copied from - // react-native/Libraries/Animated/src/nodes/AnimatedTracking.js - declare interface AnimatedTracking { - constructor( - value: AnimatedValue, - parent: any, - animationClass: any, - animationConfig: Object, - callback?: ?EndCallback, - ): void; - update(): void; - } - - // Vaguely copied from - // react-native/Libraries/Animated/nodes/AnimatedValue.js - declare type ValueListenerCallback = (state: { value: number, ... }) => void; - declare interface AnimatedValue { - constructor(value: number): void; - setValue(value: number): void; - setOffset(offset: number): void; - flattenOffset(): void; - extractOffset(): void; - addListener(callback: ValueListenerCallback): string; - removeListener(id: string): void; - removeAllListeners(): void; - stopAnimation(callback?: ?(value: number) => void): void; - resetAnimation(callback?: ?(value: number) => void): void; - interpolate(config: InterpolationConfigType): AnimatedInterpolation; - animate(animation: Animation, callback: ?EndCallback): void; - stopTracking(): void; - track(tracking: AnimatedTracking): void; - } - - // Copied from - // react-native/Libraries/Animated/src/animations/TimingAnimation.js - declare type TimingAnimationConfigSingle = AnimationConfig & { - toValue: number | AnimatedValue, - easing?: (value: number) => number, - duration?: number, - delay?: number, - ... - }; - - // Copied from - // react-native/Libraries/Animated/src/animations/SpringAnimation.js - declare type SpringAnimationConfigSingle = AnimationConfig & { - toValue: number | AnimatedValue, - overshootClamping?: boolean, - restDisplacementThreshold?: number, - restSpeedThreshold?: number, - velocity?: number, - bounciness?: number, - speed?: number, - tension?: number, - friction?: number, - stiffness?: number, - damping?: number, - mass?: number, - delay?: number, - ... - }; - - // Copied from react-native/Libraries/Types/CoreEventTypes.js - declare type SyntheticEvent = $ReadOnly<{| - bubbles: ?boolean, - cancelable: ?boolean, - currentTarget: number, - defaultPrevented: ?boolean, - dispatchConfig: $ReadOnly<{| - registrationName: string, - |}>, - eventPhase: ?number, - preventDefault: () => void, - isDefaultPrevented: () => boolean, - stopPropagation: () => void, - isPropagationStopped: () => boolean, - isTrusted: ?boolean, - nativeEvent: T, - persist: () => void, - target: ?number, - timeStamp: number, - type: ?string, - |}>; - declare type Layout = $ReadOnly<{| - x: number, - y: number, - width: number, - height: number, - |}>; - declare type LayoutEvent = SyntheticEvent< - $ReadOnly<{| - layout: Layout, - |}>, - >; - declare type BlurEvent = SyntheticEvent< - $ReadOnly<{| - target: number, - |}>, - >; - declare type FocusEvent = SyntheticEvent< - $ReadOnly<{| - target: number, - |}>, - >; - declare type ResponderSyntheticEvent = $ReadOnly<{| - ...SyntheticEvent, - touchHistory: $ReadOnly<{| - indexOfSingleActiveTouch: number, - mostRecentTimeStamp: number, - numberActiveTouches: number, - touchBank: $ReadOnlyArray< - $ReadOnly<{| - touchActive: boolean, - startPageX: number, - startPageY: number, - startTimeStamp: number, - currentPageX: number, - currentPageY: number, - currentTimeStamp: number, - previousPageX: number, - previousPageY: number, - previousTimeStamp: number, - |}>, - >, - |}>, - |}>; - declare type PressEvent = ResponderSyntheticEvent< - $ReadOnly<{| - changedTouches: $ReadOnlyArray<$PropertyType>, - force: number, - identifier: number, - locationX: number, - locationY: number, - pageX: number, - pageY: number, - target: ?number, - timestamp: number, - touches: $ReadOnlyArray<$PropertyType>, - |}>, - >; - - // Vaguely copied from - // react-native/Libraries/Animated/src/nodes/AnimatedInterpolation.js - declare type ExtrapolateType = 'extend' | 'identity' | 'clamp'; - declare type InterpolationConfigType = { - inputRange: Array, - outputRange: Array | Array, - easing?: (input: number) => number, - extrapolate?: ExtrapolateType, - extrapolateLeft?: ExtrapolateType, - extrapolateRight?: ExtrapolateType, - ... - }; - declare interface AnimatedInterpolation { - interpolate(config: InterpolationConfigType): AnimatedInterpolation; - } - - // Copied from react-native/Libraries/Components/View/ViewAccessibility.js - declare type AccessibilityRole = - | 'none' - | 'button' - | 'link' - | 'search' - | 'image' - | 'keyboardkey' - | 'text' - | 'adjustable' - | 'imagebutton' - | 'header' - | 'summary' - | 'alert' - | 'checkbox' - | 'combobox' - | 'menu' - | 'menubar' - | 'menuitem' - | 'progressbar' - | 'radio' - | 'radiogroup' - | 'scrollbar' - | 'spinbutton' - | 'switch' - | 'tab' - | 'tablist' - | 'timer' - | 'toolbar'; - declare type AccessibilityActionInfo = $ReadOnly<{ - name: string, - label?: string, - ... - }>; - declare type AccessibilityActionEvent = SyntheticEvent< - $ReadOnly<{actionName: string, ...}>, - >; - declare type AccessibilityState = { - disabled?: boolean, - selected?: boolean, - checked?: ?boolean | 'mixed', - busy?: boolean, - expanded?: boolean, - ... - }; - declare type AccessibilityValue = $ReadOnly<{| - min?: number, - max?: number, - now?: number, - text?: string, - |}>; - - // Copied from - // react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js - declare type Stringish = string; - declare type EdgeInsetsProp = $ReadOnly<$Shape>; - declare type TouchableWithoutFeedbackProps = $ReadOnly<{| - accessibilityActions?: ?$ReadOnlyArray, - accessibilityElementsHidden?: ?boolean, - accessibilityHint?: ?Stringish, - accessibilityIgnoresInvertColors?: ?boolean, - accessibilityLabel?: ?Stringish, - accessibilityLiveRegion?: ?('none' | 'polite' | 'assertive'), - accessibilityRole?: ?AccessibilityRole, - accessibilityState?: ?AccessibilityState, - accessibilityValue?: ?AccessibilityValue, - accessibilityViewIsModal?: ?boolean, - accessible?: ?boolean, - children?: ?React$Node, - delayLongPress?: ?number, - delayPressIn?: ?number, - delayPressOut?: ?number, - disabled?: ?boolean, - focusable?: ?boolean, - hitSlop?: ?EdgeInsetsProp, - importantForAccessibility?: ?('auto' | 'yes' | 'no' | 'no-hide-descendants'), - nativeID?: ?string, - onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed, - onBlur?: ?(event: BlurEvent) => mixed, - onFocus?: ?(event: FocusEvent) => mixed, - onLayout?: ?(event: LayoutEvent) => mixed, - onLongPress?: ?(event: PressEvent) => mixed, - onPress?: ?(event: PressEvent) => mixed, - onPressIn?: ?(event: PressEvent) => mixed, - onPressOut?: ?(event: PressEvent) => mixed, - pressRetentionOffset?: ?EdgeInsetsProp, - rejectResponderTermination?: ?boolean, - testID?: ?string, - touchSoundDisabled?: ?boolean, - |}>; - - // Copied from react-native/Libraries/Image/ImageSource.js - declare type ImageURISource = $ReadOnly<{ - uri?: ?string, - bundle?: ?string, - method?: ?string, - headers?: ?Object, - body?: ?string, - cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'), - width?: ?number, - height?: ?number, - scale?: ?number, - ... - }>; - - /** - * The following is copied from react-native-gesture-handler's libdef - */ - - declare type $EventHandlers = {| - onGestureEvent?: ($Event) => mixed, - onHandlerStateChange?: ($Event) => mixed, - onBegan?: ($Event) => mixed, - onFailed?: ($Event) => mixed, - onCancelled?: ($Event) => mixed, - onActivated?: ($Event) => mixed, - onEnded?: ($Event) => mixed, - |}; - - declare type HitSlop = - | number - | {| - left?: number, - top?: number, - right?: number, - bottom?: number, - vertical?: number, - horizontal?: number, - width?: number, - height?: number, - |} - | {| - width: number, - left: number, - |} - | {| - width: number, - right: number, - |} - | {| - height: number, - top: number, - |} - | {| - height: number, - bottom: number, - |}; - - declare type $GestureHandlerProps< - AdditionalProps: {...}, - ExtraEventsProps: {...} - > = $ReadOnly<{| - ...$Exact, - ...$EventHandlers, - id?: string, - enabled?: boolean, - waitFor?: React$Ref | Array>, - simultaneousHandlers?: React$Ref | Array>, - shouldCancelWhenOutside?: boolean, - minPointers?: number, - hitSlop?: HitSlop, - children?: React$Node, - |}>; - - declare type PanGestureHandlerProps = $GestureHandlerProps< - { - activeOffsetY?: number | [number, number], - activeOffsetX?: number | [number, number], - failOffsetY?: number | [number, number], - failOffsetX?: number | [number, number], - minDist?: number, - minVelocity?: number, - minVelocityX?: number, - minVelocityY?: number, - minPointers?: number, - maxPointers?: number, - avgTouches?: boolean, - ... - }, - { - x: number, - y: number, - absoluteX: number, - absoluteY: number, - translationX: number, - translationY: number, - velocityX: number, - velocityY: number, - ... - } - >; - - /** - * MAGIC - */ - - declare type $If = $Call< - ((true, Then, Else) => Then) & ((false, Then, Else) => Else), - Test, - Then, - Else, - >; - declare type $IsA = $Call< - (Y => true) & (mixed => false), - X, - >; - declare type $IsUndefined = $IsA; - - declare type $Partial = $Rest; - - /** - * Actions, state, etc. - */ - - declare export type ScreenParams = {| +[key: string]: mixed |}; - - declare export type BackAction = {| - +type: 'GO_BACK', - +source?: string, - +target?: string, - |}; - declare export type NavigateAction = {| - +type: 'NAVIGATE', - +payload: - | {| +key: string, +params?: ScreenParams |} - | {| +name: string, +key?: string, +params?: ScreenParams |}, - +source?: string, - +target?: string, - |}; - declare export type ResetAction = {| - +type: 'RESET', - +payload: StaleNavigationState, - +source?: string, - +target?: string, - |}; - declare export type SetParamsAction = {| - +type: 'SET_PARAMS', - +payload: {| +params?: ScreenParams |}, - +source?: string, - +target?: string, - |}; - declare export type CommonAction = - | BackAction - | NavigateAction - | ResetAction - | SetParamsAction; - - declare type NavigateActionCreator = {| - (routeName: string, params?: ScreenParams): NavigateAction, - ( - | {| +key: string, +params?: ScreenParams |} - | {| +name: string, +key?: string, +params?: ScreenParams |}, - ): NavigateAction, - |}; - declare export type CommonActionsType = {| - +navigate: NavigateActionCreator, - +goBack: () => BackAction, - +reset: (state: PossiblyStaleNavigationState) => ResetAction, - +setParams: (params: ScreenParams) => SetParamsAction, - |}; - - declare export type GenericNavigationAction = {| - +type: string, - +payload?: {| +[key: string]: mixed |}, - +source?: string, - +target?: string, - |}; - - declare export type LeafRoute = {| - +key: string, - +name: RouteName, - +params?: ScreenParams, - |}; - declare export type StateRoute = {| - ...LeafRoute, - +state: NavigationState | StaleNavigationState, - |}; - declare export type Route = - | LeafRoute - | StateRoute; - - declare export type NavigationState = {| - +key: string, - +index: number, - +routeNames: $ReadOnlyArray, - +history?: $ReadOnlyArray, - +routes: $ReadOnlyArray>, - +type: string, - +stale: false, - |}; - - declare export type StaleLeafRoute = {| - +key?: string, - +name: RouteName, - +params?: ScreenParams, - |}; - declare export type StaleStateRoute = {| - ...StaleLeafRoute, - +state: StaleNavigationState, - |}; - declare export type StaleRoute = - | StaleLeafRoute - | StaleStateRoute; - declare export type StaleNavigationState = {| - // It's possible to pass React Nav a StaleNavigationState with an undefined - // index, but React Nav will always return one with the index set. This is - // the same as for the type property below, but in the case of index we tend - // to rely on it being set more... - +index: number, - +history?: $ReadOnlyArray, - +routes: $ReadOnlyArray>, - +type?: string, - +stale?: true, - |}; - - declare export type PossiblyStaleNavigationState = - | NavigationState - | StaleNavigationState; - declare export type PossiblyStaleRoute = - | Route - | StaleRoute; - - /** - * Routers - */ - - declare type ActionCreators< - State: NavigationState, - Action: GenericNavigationAction, - > = {| - +[key: string]: (...args: any) => (Action | State => Action), - |}; - - declare export type DefaultRouterOptions = { - +initialRouteName?: string, - ... - }; - - declare export type RouterFactory< - State: NavigationState, - Action: GenericNavigationAction, - RouterOptions: DefaultRouterOptions, - > = (options: RouterOptions) => Router; - - declare export type ParamListBase = {| +[key: string]: ?ScreenParams |}; - - declare export type RouterConfigOptions = {| - +routeNames: $ReadOnlyArray, - +routeParamList: ParamListBase, - |}; - - declare export type Router< - State: NavigationState, - Action: GenericNavigationAction, - > = {| - +type: $PropertyType, - +getInitialState: (options: RouterConfigOptions) => State, - +getRehydratedState: ( - partialState: PossibleStaleNavigationState, - options: RouterConfigOptions, - ) => State, - +getStateForRouteNamesChange: ( - state: State, - options: RouterConfigOptions, - ) => State, - +getStateForRouteFocus: (state: State, key: string) => State, - +getStateForAction: ( - state: State, - action: Action, - options: RouterConfigOptions, - ) => ?PossiblyStaleNavigationState; - +shouldActionChangeFocus: (action: GenericNavigationAction) => boolean, - +actionCreators?: ActionCreators, - |}; - - /** - * Stack actions and router - */ - - declare export type StackNavigationState = {| - ...NavigationState, - +type: 'stack', - |}; - - declare export type ReplaceAction = {| - +type: 'REPLACE', - +payload: {| +name: string, +key?: ?string, +params?: ScreenParams |}, - +source?: string, - +target?: string, - |}; - declare export type PushAction = {| - +type: 'PUSH', - +payload: {| +name: string, +key?: ?string, +params?: ScreenParams |}, - +source?: string, - +target?: string, - |}; - declare export type PopAction = {| - +type: 'POP', - +payload: {| +count: number |}, - +source?: string, - +target?: string, - |}; - declare export type PopToTopAction = {| - +type: 'POP_TO_TOP', - +source?: string, - +target?: string, - |}; - declare export type StackAction = - | CommonAction - | ReplaceAction - | PushAction - | PopAction - | PopToTopAction; - - declare export type StackActionsType = {| - +replace: (routeName: string, params?: ScreenParams) => ReplaceAction, - +push: (routeName: string, params?: ScreenParams) => PushAction, - +pop: (count?: number) => PopAction, - +popToTop: () => PopToTopAction, - |}; - - declare export type StackRouterOptions = $Exact; - - /** - * Tab actions and router - */ - - declare export type TabNavigationState = {| - ...NavigationState, - +type: 'tab', - +history: $ReadOnlyArray<{| type: 'route', key: string |}>, - |}; - - declare export type JumpToAction = {| - +type: 'JUMP_TO', - +payload: {| +name: string, +params?: ScreenParams |}, - +source?: string, - +target?: string, - |}; - declare export type TabAction = - | CommonAction - | JumpToAction; - - declare export type TabActionsType = {| - +jumpTo: string => JumpToAction, - |}; - - declare export type TabRouterOptions = {| - ...$Exact, - +backBehavior?: 'initialRoute' | 'order' | 'history' | 'none', - |}; - - /** - * Drawer actions and router - */ - - declare type DrawerHistoryEntry = - | {| +type: 'route', +key: string |} - | {| +type: 'drawer' |}; - declare export type DrawerNavigationState = {| - ...NavigationState, - +type: 'drawer', - +history: $ReadOnlyArray, - |}; - - declare export type OpenDrawerAction = {| - +type: 'OPEN_DRAWER', - +source?: string, - +target?: string, - |}; - declare export type CloseDrawerAction = {| - +type: 'CLOSE_DRAWER', - +source?: string, - +target?: string, - |}; - declare export type ToggleDrawerAction = {| - +type: 'TOGGLE_DRAWER', - +source?: string, - +target?: string, - |}; - declare export type DrawerAction = - | TabAction - | OpenDrawerAction - | CloseDrawerAction - | ToggleDrawerAction; - - declare export type DrawerActionsType = {| - ...TabActionsType, - +openDrawer: () => OpenDrawerAction, - +closeDrawer: () => CloseDrawerAction, - +toggleDrawer: () => ToggleDrawerAction, - |}; - - declare export type DrawerRouterOptions = {| - ...TabRouterOptions, - +openByDefault?: boolean, - |}; - - /** - * Events - */ - - declare export type EventMapBase = {| - +[name: string]: {| - +data?: mixed, - +canPreventDefault?: boolean, - |}, - |}; - declare type EventPreventDefaultProperties = $If< - Test, - {| +defaultPrevented: boolean, +preventDefault: () => void |}, - {| |}, - >; - declare type EventDataProperties = $If< - $IsUndefined, - {| |}, - {| +data: Data |}, - >; - declare type EventArg< - EventName: string, - CanPreventDefault: ?boolean = false, - Data = void, - > = {| - ...EventPreventDefaultProperties, - ...EventDataProperties, - +type: EventName, - +target?: string, - |}; - declare type GlobalEventMap = {| - +state: {| +data: {| +state: State |}, +canPreventDefault: false |}, - |}; - declare type EventMapCore = {| - ...GlobalEventMap, - +focus: {| +data: void, +canPreventDefault: false |}, - +blur: {| +data: void, +canPreventDefault: false |}, - |}; - declare type EventListenerCallback< - EventName: string, - State: PossiblyStaleNavigationState = NavigationState, - EventMap: EventMapBase = EventMapCore, - > = (e: EventArg< - EventName, - $PropertyType< - $ElementType< - {| ...EventMap, ...EventMapCore |}, - EventName, - >, - 'canPreventDefault', - >, - $PropertyType< - $ElementType< - {| ...EventMap, ...EventMapCore |}, - EventName, - >, - 'data', - >, - >) => mixed; - - /** - * Navigation prop - */ - - declare export type SimpleNavigate = - >( - routeName: DestinationRouteName, - params: $ElementType, - ) => void; - - declare export type Navigate = - & SimpleNavigate - & >( - route: - | {| - key: string, - params?: $ElementType, - |} - | {| - name: DestinationRouteName, - key?: string, - params?: $ElementType, - |}, - ) => void; - - declare type NavigationHelpers< - ParamList: ParamListBase, - State: PossiblyStaleNavigationState = PossiblyStaleNavigationState, - EventMap: EventMapBase = EventMapCore, - > = { - +navigate: Navigate, - +dispatch: ( - action: - | GenericNavigationAction - | (State => GenericNavigationAction), - ) => void, - +reset: PossiblyStaleNavigationState => void, - +goBack: () => void, - +isFocused: () => boolean, - +canGoBack: () => boolean, - +dangerouslyGetParent: >() => ?Parent, - +dangerouslyGetState: () => NavigationState, - +addListener: |}, - >>( - name: EventName, - callback: EventListenerCallback, - ) => () => void, - +removeListener: |}, - >>( - name: EventName, - callback: EventListenerCallback, - ) => void, - ... - }; - - declare export type NavigationProp< - ParamList: ParamListBase, - +RouteName: $Keys = $Keys, - State: PossiblyStaleNavigationState = PossiblyStaleNavigationState, - ScreenOptions: {...} = {...}, - EventMap: EventMapBase = EventMapCore, - > = { - ...$Exact>, - +setOptions: (options: $Shape) => void, - +setParams: ( - params: $If< - $IsUndefined<$ElementType>, - empty, - $Shape<$NonMaybeType<$ElementType>>, - >, - ) => void, - ... - }; - - /** - * CreateNavigator - */ - - declare export type RouteProp< - ParamList: ParamListBase, - RouteName: $Keys, - > = {| - ...LeafRoute, - +params: $ElementType, - |}; - - declare export type ScreenListeners< - EventMap: EventMapBase = EventMapCore, - State: NavigationState = NavigationState, - > = $ObjMapi< - {| [name: $Keys]: empty |}, - >(K, empty) => EventListenerCallback, - >; - - declare type BaseScreenProps< - ParamList: ParamListBase, - NavProp, - RouteName: $Keys = $Keys, - State: NavigationState = NavigationState, - ScreenOptions: {...} = {...}, - EventMap: EventMapBase = EventMapCore, - > = {| - +name: RouteName, - +options?: - | ScreenOptions - | ({| - route: RouteProp, - navigation: NavProp, - |}) => ScreenOptions, - +listeners?: - | ScreenListeners - | ({| - route: RouteProp, - navigation: NavProp, - |}) => ScreenListeners, - +initialParams?: $Shape<$ElementType>, - |}; - - declare export type ScreenProps< - ParamList: ParamListBase, - NavProp, - RouteName: $Keys = $Keys, - State: NavigationState = NavigationState, - ScreenOptions: {...} = {...}, - EventMap: EventMapBase = EventMapCore, - > = - | {| - ...BaseScreenProps< - ParamList, - NavProp, - RouteName, - State, - ScreenOptions, - EventMap, - >, - +component: React$ComponentType<{| - route: RouteProp, - navigation: NavProp, - |}>, - |} - | {| - ...BaseScreenProps< - ParamList, - NavProp, - RouteName, - State, - ScreenOptions, - EventMap, - >, - +children: ({| - route: RouteProp, - navigation: NavProp, - |}) => React$Node, - |}; - - declare export type ScreenComponent< - GlobalParamList: ParamListBase, - ParamList: ParamListBase, - State: NavigationState = NavigationState, - ScreenOptions: {...} = {...}, - EventMap: EventMapBase = EventMapCore, - > = < - RouteName: $Keys, - NavProp: NavigationProp< - GlobalParamList, - RouteName, - State, - ScreenOptions, - EventMap, - >, - >(props: ScreenProps< - ParamList, - NavProp, - RouteName, - State, - ScreenOptions, - EventMap, - >) => React$Node; - - declare type ScreenOptionsProp = {| - +screenOptions?: - | ScreenOptions - | ({| route: LeafRoute<>, navigation: NavProp |}) => ScreenOptions, - |}; - declare export type ExtraNavigatorPropsBase = { - ...$Exact, - +children?: React$Node, - ... - }; - declare export type NavigatorPropsBase = { - ...$Exact, - ...ScreenOptionsProp, - ... - }; - - declare export type CreateNavigator< - State: NavigationState, - ScreenOptions: {...}, - EventMap: EventMapBase, - ExtraNavigatorProps: ExtraNavigatorPropsBase, - > = < - GlobalParamList: ParamListBase, - ParamList: ParamListBase, - NavProp: NavigationHelpers< - GlobalParamList, - State, - EventMap, - >, - >() => {| - +Screen: ScreenComponent< - GlobalParamList, - ParamList, - State, - ScreenOptions, - EventMap, - >, - +Navigator: React$ComponentType<{| - ...$Exact, - ...ScreenOptionsProp, - |}>, - |}; - - declare export type CreateNavigatorFactory = < - State: NavigationState, - ScreenOptions: {...}, - EventMap: EventMapBase, - NavProp: NavigationHelpers< - ParamListBase, - State, - EventMap, - >, - ExtraNavigatorProps: ExtraNavigatorPropsBase, - >( - navigator: React$ComponentType<{| - ...$Exact, - ...ScreenOptionsProp, - |}>, - ) => CreateNavigator; - - /** - * useNavigationBuilder - */ - - declare export type Descriptor< - NavProp, - ScreenOptions: {...} = {...}, - > = {| - +render: () => React$Node, - +options: $ReadOnly, - +navigation: NavProp, - |}; - - declare export type UseNavigationBuilder = < - State: NavigationState, - Action: GenericNavigationAction, - ScreenOptions: {...}, - RouterOptions: DefaultRouterOptions, - NavProp, - >( - routerFactory: RouterFactory, - options: {| - ...$Exact, - ...ScreenOptionsProp, - +children?: React$Node, - |}, - ) => {| - +state: State, - +descriptors: {| +[key: string]: Descriptor |}, - +navigation: NavProp, - |}; - - /** - * EdgeInsets - */ - - declare type EdgeInsets = {| - +top: number, - +right: number, - +bottom: number, - +left: number, - |}; - - /** - * TransitionPreset - */ - - declare export type TransitionSpec = - | {| - animation: 'spring', - config: $Diff< - SpringAnimationConfigSingle, - { toValue: number | AnimatedValue, ... }, - >, - |} - | {| - animation: 'timing', - config: $Diff< - TimingAnimationConfigSingle, - { toValue: number | AnimatedValue, ... }, - >, - |}; - - declare export type StackCardInterpolationProps = {| - +current: {| - +progress: AnimatedInterpolation, - |}, - +next?: {| - +progress: AnimatedInterpolation, - |}, - +index: number, - +closing: AnimatedInterpolation, - +swiping: AnimatedInterpolation, - +inverted: AnimatedInterpolation, - +layouts: {| - +screen: {| +width: number, +height: number |}, - |}, - +insets: EdgeInsets, - |}; - declare export type StackCardInterpolatedStyle = {| - containerStyle?: AnimatedViewStyleProp, - cardStyle?: AnimatedViewStyleProp, - overlayStyle?: AnimatedViewStyleProp, - shadowStyle?: AnimatedViewStyleProp, - |}; - declare export type StackCardStyleInterpolator = ( - props: StackCardInterpolationProps, - ) => StackCardInterpolatedStyle; - - declare export type StackHeaderInterpolationProps = {| - +current: {| - +progress: AnimatedInterpolation, - |}, - +next?: {| - +progress: AnimatedInterpolation, - |}, - +layouts: {| - +header: {| +width: number, +height: number |}, - +screen: {| +width: number, +height: number |}, - +title?: {| +width: number, +height: number |}, - +leftLabel?: {| +width: number, +height: number |}, - |}, - |}; - declare export type StackHeaderInterpolatedStyle = {| - leftLabelStyle?: AnimatedViewStyleProp, - leftButtonStyle?: AnimatedViewStyleProp, - rightButtonStyle?: AnimatedViewStyleProp, - titleStyle?: AnimatedViewStyleProp, - backgroundStyle?: AnimatedViewStyleProp, - |}; - declare export type StackHeaderStyleInterpolator = ( - props: StackHeaderInterpolationProps, - ) => StackHeaderInterpolatedStyle; - - declare type GestureDirection = - | 'horizontal' - | 'horizontal-inverted' - | 'vertical' - | 'vertical-inverted'; - - declare export type TransitionPreset = {| - +gestureDirection: GestureDirection, - +transitionSpec: {| - +open: TransitionSpec, - +close: TransitionSpec, - |}, - +cardStyleInterpolator: StackCardStyleInterpolator, - +headerStyleInterpolator: StackHeaderStyleInterpolator, - |}; - - /** - * Stack options - */ - - declare export type StackDescriptor = Descriptor< - StackNavigationProp<>, - StackOptions, - >; - - declare type Scene = {| - +route: T, - +descriptor: StackDescriptor, - +progress: {| - +current: AnimatedInterpolation, - +next?: AnimatedInterpolation, - +previous?: AnimatedInterpolation, - |}, - |}; - - declare export type StackHeaderProps = {| - +mode: 'float' | 'screen', - +layout: {| +width: number, +height: number |}, - +insets: EdgeInsets, - +scene: Scene>, - +previous?: Scene>, - +navigation: StackNavigationProp, - +styleInterpolator: StackHeaderStyleInterpolator, - |}; - - declare export type StackHeaderLeftButtonProps = $Shape<{| - +onPress: (() => void), - +pressColorAndroid: string; - +backImage: (props: {| tintColor: string |}) => React$Node, - +tintColor: string, - +label: string, - +truncatedLabel: string, - +labelVisible: boolean, - +labelStyle: AnimatedTextStyleProp, - +allowFontScaling: boolean, - +onLabelLayout: LayoutEvent => void, - +screenLayout: {| +width: number, +height: number |}, - +titleLayout: {| +width: number, +height: number |}, - +canGoBack: boolean, - |}>; - - declare type StackHeaderTitleInputBase = { - +onLayout: LayoutEvent => void, - +children: string, - +allowFontScaling: ?boolean, - +tintColor: ?string, - +style: ?AnimatedTextStyleProp, - ... - }; - - declare export type StackHeaderTitleInputProps = - $Exact; - - declare export type StackOptions = $Shape<{| - +title: string, - +header: StackHeaderProps => React$Node, - +headerShown: boolean, - +cardShadowEnabled: boolean, - +cardOverlayEnabled: boolean, - +cardOverlay: {| style: ViewStyleProp |} => React$Node, - +cardStyle: ViewStyleProp, - +animationEnabled: boolean, - +animationTypeForReplace: 'push' | 'pop', - +gestureEnabled: boolean, - +gestureResponseDistance: {| vertical?: number, horizontal?: number |}, - +gestureVelocityImpact: number, - +safeAreaInsets: $Shape, - // Transition - ...TransitionPreset, - // Header - +headerTitle: string | (StackHeaderTitleInputProps => React$Node), - +headerTitleAlign: 'left' | 'center', - +headerTitleStyle: AnimatedTextStyleProp, - +headerTitleContainerStyle: ViewStyleProp, - +headerTintColor: string, - +headerTitleAllowFontScaling: boolean, - +headerBackAllowFontScaling: boolean, - +headerBackTitle: string | null, - +headerBackTitleStyle: TextStyleProp, - +headerBackTitleVisible: boolean, - +headerTruncatedBackTitle: string, - +headerLeft: StackHeaderLeftButtonProps => React$Node, - +headerLeftContainerStyle: ViewStyleProp, - +headerRight: {| tintColor?: string |} => React$Node, - +headerRightContainerStyle: ViewStyleProp, - +headerBackImage: $PropertyType, - +headerPressColorAndroid: string, - +headerBackground: ({| style: ViewStyleProp |}) => React$Node, - +headerStyle: ViewStyleProp, - +headerTransparent: boolean, - +headerStatusBarHeight: number, - |}>; - - /** - * Stack navigation prop - */ - - declare export type StackNavigationEventMap = {| - ...EventMapCore, - +transitionStart: {| - +data: {| +closing: boolean |}, - +canPreventDefault: false, - |}, - +transitionEnd: {| - +data: {| +closing: boolean |}, - +canPreventDefault: false, - |}, - |}; - - declare type InexactStackNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = StackOptions, - EventMap: EventMapBase = StackNavigationEventMap, - > = { - ...$Exact>, - +replace: SimpleNavigate, - +push: SimpleNavigate, - +pop: (count?: number) => void, - +popToTop: () => void, - ... - }; - - declare export type StackNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = StackOptions, - EventMap: EventMapBase = StackNavigationEventMap, - > = $Exact>; - - /** - * Miscellaneous stack exports - */ - - declare type StackNavigationConfig = {| - +mode?: 'card' | 'modal', - +headerMode?: 'float' | 'screen' | 'none', - +keyboardHandlingEnabled?: boolean, - |}; - - declare export type ExtraStackNavigatorProps = {| - ...$Exact, - ...StackRouterOptions, - ...StackNavigationConfig, - |}; - - declare export type StackNavigatorProps< - NavProp: InexactStackNavigationProp<> = StackNavigationProp<>, - > = {| - ...ExtraStackNavigatorProps, - ...ScreenOptionsProp, - |}; - - /** - * Bottom tab options - */ - - declare export type BottomTabBarButtonProps = {| - ...$Diff< - TouchableWithoutFeedbackProps, - {| onPress?: ?(event: PressEvent) => mixed |}, - >, - +to?: string, - +children: React$Node, - +onPress?: (MouseEvent | PressEvent) => void, - |}; - - declare export type BottomTabOptions = $Shape<{| - +title: string, - +tabBarLabel: - | string - | ({| focused: boolean, color: string |}) => React$Node, - +tabBarIcon: ({| - focused: boolean, - color: string, - size: number, - |}) => React$Node, - +tabBarBadge?: number | string; - +tabBarBadgeStyle?: TextStyleProp; - +tabBarAccessibilityLabel: string, - +tabBarTestID: string, - +tabBarVisible: boolean, - +tabBarButton: BottomTabBarButtonProps => React$Node, - +unmountOnBlur: boolean, - |}>; - - /** - * Bottom tab navigation prop - */ - - declare export type BottomTabNavigationEventMap = {| - ...EventMapCore, - +tabPress: {| +data: void, +canPreventDefault: true |}, - +tabLongPress: {| +data: void, +canPreventDefault: false |}, - |}; - - declare type InexactTabNavigationProp< - ParamList: ParamListBase, - +RouteName: $Keys, - Options: {...}, - EventMap: EventMapBase, - > = { - ...$Exact>, - +jumpTo: SimpleNavigate, - ... - }; - - declare export type InexactBottomTabNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = BottomTabOptions, - EventMap: EventMapBase = BottomTabNavigationEventMap, - > = InexactTabNavigationProp< - ParamList, - RouteName, - Options, - EventMap, - >; - - declare export type BottomTabNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = BottomTabOptions, - EventMap: EventMapBase = BottomTabNavigationEventMap, - > = $Exact>; - - /** - * Miscellaneous bottom tab exports - */ - - declare export type BottomTabDescriptor = Descriptor< - BottomTabNavigationProp<>, - BottomTabOptions, - >; - - declare export type BottomTabBarOptions = $Shape<{| - +keyboardHidesTabBar: boolean, - +activeTintColor: string, - +inactiveTintColor: string, - +activeBackgroundColor: string, - +inactiveBackgroundColor: string, - +allowFontScaling: boolean, - +showLabel: boolean, - +showIcon: boolean, - +labelStyle: TextStyleProp, - +iconStyle: TextStyleProp, - +tabStyle: ViewStyleProp, - +labelPosition: 'beside-icon' | 'below-icon', - +adaptive: boolean, - +safeAreaInsets: $Shape, - +style: ViewStyleProp, - |}>; - - declare type BottomTabNavigationBuilderResult = {| - +state: TabNavigationState, - +navigation: BottomTabNavigationProp<>, - +descriptors: {| +[key: string]: BottomTabDescriptor |}, - |}; - - declare export type BottomTabBarProps = {| - ...BottomTabBarOptions, - ...BottomTabNavigationBuilderResult, - |} - - declare type BottomTabNavigationConfig = {| - +lazy?: boolean, - +tabBar?: BottomTabBarProps => React$Node, - +tabBarOptions?: BottomTabBarOptions, - |}; - - declare export type ExtraBottomTabNavigatorProps = {| - ...$Exact, - ...TabRouterOptions, - ...BottomTabNavigationConfig, - |}; - - declare export type BottomTabNavigatorProps< - NavProp: InexactBottomTabNavigationProp<> = BottomTabNavigationProp<>, - > = {| - ...ExtraBottomTabNavigatorProps, - ...ScreenOptionsProp, - |}; - - /** - * Material bottom tab options - */ - - declare export type MaterialBottomTabOptions = $Shape<{| - +title: string, - +tabBarColor: string, - +tabBarLabel: string, - +tabBarIcon: - | string - | ({| +focused: boolean, +color: string |}) => React$Node, - +tabBarBadge: boolean | number | string, - +tabBarAccessibilityLabel: string, - +tabBarTestID: string, - |}>; - - /** - * Material bottom tab navigation prop - */ - - declare export type MaterialBottomTabNavigationEventMap = {| - ...EventMapCore, - +tabPress: {| +data: void, +canPreventDefault: true |}, - |}; - - declare export type InexactMaterialBottomTabNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = MaterialBottomTabOptions, - EventMap: EventMapBase = MaterialBottomTabNavigationEventMap, - > = InexactTabNavigationProp< - ParamList, - RouteName, - Options, - EventMap, - >; - - declare export type MaterialBottomTabNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = MaterialBottomTabOptions, - EventMap: EventMapBase = MaterialBottomTabNavigationEventMap, - > = $Exact>; - - /** - * Miscellaneous material bottom tab exports - */ - - declare export type PaperFont = {| - +fontFamily: string, - +fontWeight?: - | 'normal' - | 'bold' - | '100' - | '200' - | '300' - | '400' - | '500' - | '600' - | '700' - | '800' - | '900', - |}; - - declare export type PaperFonts = {| - +regular: Font, - +medium: Font, - +light: Font, - +thin: Font, - |}; - - declare export type PaperTheme = {| - +dark: boolean, - +mode?: 'adaptive' | 'exact', - +roundness: number, - +colors: {| - +primary: string, - +background: string, - +surface: string, - +accent: string, - +error: string, - +text: string, - +onSurface: string, - +onBackground: string, - +disabled: string, - +placeholder: string, - +backdrop: string, - +notification: string, - |}, - +fonts: PaperFonts, - +animation: {| - +scale: number, - |}, - |}; - - declare export type PaperRoute = {| - +key: string, - +title?: string, - +icon?: any, - +badge?: string | number | boolean, - +color?: string, - +accessibilityLabel?: string, - +testID?: string, - |}; - - declare export type PaperTouchableProps = {| - ...TouchableWithoutFeedbackProps, - +key: string, - +route: PaperRoute, - +children: React$Node, - +borderless?: boolean, - +centered?: boolean, - +rippleColor?: string, - |}; - - declare export type MaterialBottomTabNavigationConfig = {| - +shifting?: boolean, - +labeled?: boolean, - +renderTouchable?: PaperTouchableProps => React$Node, - +activeColor?: string, - +inactiveColor?: string, - +sceneAnimationEnabled?: boolean, - +keyboardHidesNavigationBar?: boolean, - +barStyle?: ViewStyleProp, - +style?: ViewStyleProp, - +theme?: PaperTheme, - |}; - - declare export type ExtraMaterialBottomTabNavigatorProps = {| - ...$Exact, - ...TabRouterOptions, - ...MaterialBottomTabNavigationConfig, - |}; - - declare export type MaterialBottomTabNavigatorProps< - NavProp: InexactMaterialBottomTabNavigationProp<> = - MaterialBottomTabNavigationProp<>, - > = {| - ...ExtraMaterialBottomTabNavigatorProps, - ...ScreenOptionsProp, - |}; - - /** - * Material top tab options - */ - - declare export type MaterialTopTabOptions = $Shape<{| - +title: string, - +tabBarLabel: - | string - | ({| +focused: boolean, +color: string |}) => React$Node, - +tabBarIcon: ({| +focused: boolean, +color: string |}) => React$Node, - +tabBarAccessibilityLabel: string, - +tabBarTestID: string, - |}>; - - /** - * Material top tab navigation prop - */ - - declare export type MaterialTopTabNavigationEventMap = {| - ...EventMapCore, - +tabPress: {| +data: void, +canPreventDefault: true |}, - +tabLongPress: {| +data: void, +canPreventDefault: false |}, - +swipeStart: {| +data: void, +canPreventDefault: false |}, - +swipeEnd: {| +data: void, +canPreventDefault: false |}, - |}; - - declare export type InexactMaterialTopTabNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = MaterialTopTabOptions, - EventMap: EventMapBase = MaterialTopTabNavigationEventMap, - > = InexactTabNavigationProp< - ParamList, - RouteName, - Options, - EventMap, - >; - - declare export type MaterialTopTabNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = MaterialTopTabOptions, - EventMap: EventMapBase = MaterialTopTabNavigationEventMap, - > = $Exact>; - - /** - * Miscellaneous material top tab exports - */ - - declare type MaterialTopTabPagerCommonProps = {| - +keyboardDismissMode: 'none' | 'on-drag' | 'auto', - +swipeEnabled: boolean, - +swipeVelocityImpact?: number, - +springVelocityScale?: number, - +springConfig: $Shape<{| - +damping: number, - +mass: number, - +stiffness: number, - +restSpeedThreshold: number, - +restDisplacementThreshold: number, - |}>, - +timingConfig: $Shape<{| - +duration: number, - |}>, - |}; - - declare export type MaterialTopTabPagerProps = {| - ...MaterialTopTabPagerCommonProps, - +onSwipeStart?: () => void, - +onSwipeEnd?: () => void, - +onIndexChange: (index: number) => void, - +navigationState: TabNavigationState, - +layout: {| +width: number, +height: number |}, - +removeClippedSubviews: boolean, - +children: ({| - +addListener: (type: 'enter', listener: number => void) => void, - +removeListener: (type: 'enter', listener: number => void) => void, - +position: any, // Reanimated.Node - +render: React$Node => React$Node, - +jumpTo: string => void, - |}) => React$Node, - +gestureHandlerProps: PanGestureHandlerProps, - |}; - - declare export type MaterialTopTabBarIndicatorProps = {| - +navigationState: TabNavigationState, - +width: string, - +style?: ViewStyleProp, - +getTabWidth: number => number, - |}; - - declare export type MaterialTopTabBarOptions = $Shape<{| - +scrollEnabled: boolean, - +bounces: boolean, - +pressColor: string, - +pressOpacity: number, - +getAccessible: ({| +route: Route<> |}) => boolean, - +renderBadge: ({| +route: Route<> |}) => React$Node, - +renderIndicator: MaterialTopTabBarIndicatorProps => React$Node, - +tabStyle: ViewStyleProp, - +indicatorStyle: ViewStyleProp, - +indicatorContainerStyle: ViewStyleProp, - +labelStyle: TextStyleProp, - +contentContainerStyle: ViewStyleProp, - +style: ViewStyleProp, - +activeTintColor: string, - +inactiveTintColor: string, - +iconStyle: ViewStyleProp, - +labelStyle: TextStyleProp, - +showLabel: boolean, - +showIcon: boolean, - +allowFontScaling: boolean, - |}>; - - declare export type MaterialTopTabDescriptor = Descriptor< - MaterialBottomTabNavigationProp<>, - MaterialBottomTabOptions, - >; - - declare type MaterialTopTabNavigationBuilderResult = {| - +state: TabNavigationState, - +navigation: MaterialTopTabNavigationProp<>, - +descriptors: {| +[key: string]: MaterialTopTabDescriptor |}, - |}; - - declare export type MaterialTopTabBarProps = {| - ...MaterialTopTabBarOptions, - ...MaterialTopTabNavigationBuilderResult, - +layout: {| +width: number, +height: number |}, - +position: any, // Reanimated.Node - +jumpTo: string => void, - |}; - - declare export type MaterialTopTabNavigationConfig = {| - ...$Partial, - +position?: any, // Reanimated.Value - +tabBarPosition?: 'top' | 'bottom', - +initialLayout?: $Shape<{| +width: number, +height: number |}>, - +lazy?: boolean, - +lazyPreloadDistance?: number, - +removeClippedSubviews?: boolean, - +sceneContainerStyle?: ViewStyleProp, - +style?: ViewStyleProp, - +gestureHandlerProps?: PanGestureHandlerProps, - +pager?: MaterialTopTabPagerProps => React$Node, - +lazyPlaceholder?: ({| +route: Route<> |}) => React$Node, - +tabBar?: MaterialTopTabBarProps => React$Node, - +tabBarOptions?: MaterialTopTabBarOptions, - |}; - - declare export type ExtraMaterialTopTabNavigatorProps = {| - ...$Exact, - ...TabRouterOptions, - ...MaterialTopTabNavigationConfig, - |}; - - declare export type MaterialTopTabNavigatorProps< - NavProp: InexactMaterialTopTabNavigationProp<> = - MaterialTopTabNavigationProp<>, - > = {| - ...ExtraMaterialTopTabNavigatorProps, - ...ScreenOptionsProp, - |}; - - /** - * Drawer options - */ - - declare export type DrawerOptions = $Shape<{| - title: string, - drawerLabel: - | string - | ({| +color: string, +focused: boolean |}) => React$Node, - drawerIcon: ({| - +color: string, - +size: number, - +focused: boolean, - |}) => React$Node, - gestureEnabled: boolean, - swipeEnabled: boolean, - unmountOnBlur: boolean, - |}>; - - /** - * Drawer navigation prop - */ - - declare export type DrawerNavigationEventMap = {| - ...EventMapCore, - +drawerOpen: {| +data: void, +canPreventDefault: false |}, - +drawerClose: {| +data: void, +canPreventDefault: false |}, - |}; - - declare export type InexactDrawerNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = DrawerOptions, - EventMap: EventMapBase = DrawerNavigationEventMap, - > = { - ...$Exact>, - +jumpTo: SimpleNavigate, - +openDrawer: () => void, - +closeDrawer: () => void, - +toggleDrawer: () => void, - ... - }; - - declare export type DrawerNavigationProp< - ParamList: ParamListBase = ParamListBase, - +RouteName: $Keys = $Keys, - Options: {...} = DrawerOptions, - EventMap: EventMapBase = DrawerNavigationEventMap, - > = $Exact>; - - /** - * Miscellaneous drawer exports - */ - - declare export type DrawerDescriptor = Descriptor< - DrawerNavigationProp<>, - DrawerOptions, - >; - - declare export type DrawerItemListBaseOptions = $Shape<{| - +activeTintColor: string, - +activeBackgroundColor: string, - +inactiveTintColor: string, - +inactiveBackgroundColor: string, - +itemStyle: ViewStyleProp, - +labelStyle: TextStyleProp, - |}>; - - declare export type DrawerContentOptions = $Shape<{| - ...DrawerItemListBaseOptions, - +contentContainerStyle: ViewStyleProp, - +style: ViewStyleProp, - |}>; - - declare type DrawerNavigationBuilderResult = {| - +state: DrawerNavigationState, - +navigation: DrawerNavigationProp<>, - +descriptors: {| +[key: string]: DrawerDescriptor |}, - |}; - - declare export type DrawerContentProps = {| - ...DrawerContentOptions, - ...DrawerNavigationBuilderResult, - +progress: any, // Reanimated.Node - |}; - - declare export type DrawerNavigationConfig = {| - +drawerPosition?: 'left' | 'right', - +drawerType?: 'front' | 'back' | 'slide' | 'permanent', - +edgeWidth?: number, - +hideStatusBar?: boolean, - +keyboardDismissMode?: 'on-drag' | 'none', - +minSwipeDistance?: number, - +overlayColor?: string, - +statusBarAnimation?: 'slide' | 'none' | 'fade', - +gestureHandlerProps?: PanGestureHandlerProps, - +lazy?: boolean, - +drawerContent?: DrawerContentProps => React$Node, - +drawerContentOptions?: DrawerContentOptions, - +sceneContainerStyle?: ViewStyleProp, - +drawerStyle?: ViewStyleProp, - |}; - - declare export type ExtraDrawerNavigatorProps = {| - ...$Exact, - ...DrawerRouterOptions, - ...DrawerNavigationConfig, - |}; - - declare export type DrawerNavigatorProps< - NavProp: InexactDrawerNavigationProp<> = DrawerNavigationProp<>, - > = {| - ...ExtraDrawerNavigatorProps, - ...ScreenOptionsProp, - |}; - - /** - * BaseNavigationContainer - */ - - declare export type BaseNavigationContainerProps = {| - +children: React$Node, - +initialState?: PossiblyStaleNavigationState, - +onStateChange?: (state: ?PossiblyStaleNavigationState) => void, - +independent?: boolean, - |}; - - declare export type ContainerEventMap = {| - ...GlobalEventMap, - +options: {| - +data: {| +options: {| +[key: string]: mixed |} |}, - +canPreventDefault: false, - |}, - +__unsafe_action__: {| - +data: {| - +action: GenericNavigationAction, - +noop: boolean, - |}, - +canPreventDefault: false, - |}, - |}; - - declare export type BaseNavigationContainerInterface = {| - ...$Exact>, - +setParams: (params: ScreenParams) => void, - +resetRoot: (state?: ?PossiblyStaleNavigationState) => void, - +getRootState: () => NavigationState, - |}; - - /** - * State utils - */ - - declare export type GetStateFromPath = ( - path: string, - options?: LinkingConfig, - ) => PossiblyStaleNavigationState; - - declare export type GetPathFromState = ( - state?: ?PossiblyStaleNavigationState, - options?: LinkingConfig, - ) => string; - - declare export type GetFocusedRouteNameFromRoute = - PossiblyStaleRoute => ?string; - - /** - * Linking - */ - - declare export type ScreenLinkingConfig = {| - +path?: string, - +exact?: boolean, - +parse?: {| +[param: string]: string => mixed |}, - +stringify?: {| +[param: string]: mixed => string |}, - +screens?: ScreenLinkingConfigMap, - +initialRouteName?: string, - |}; - - declare export type ScreenLinkingConfigMap = {| - +[routeName: string]: string | ScreenLinkingConfig, - |}; - - declare export type LinkingConfig = {| - +initialRouteName?: string, - +screens: ScreenLinkingConfigMap, - |}; - - declare export type LinkingOptions = {| - +enabled?: boolean, - +prefixes: $ReadOnlyArray, - +config?: LinkingConfig, - +getStateFromPath?: GetStateFromPath, - +getPathFromState?: GetPathFromState, - |}; - - /** - * NavigationContainer - */ - - declare export type Theme = {| - +dark: boolean, - +colors: {| - +primary: string, - +background: string, - +card: string, - +text: string, - +border: string, - |}, - |}; - - declare export type NavigationContainerType = React$AbstractComponent< - {| - ...BaseNavigationContainerProps, - +theme?: Theme, - +linking?: LinkingOptions, - +fallback?: React$Node, - +onReady?: () => mixed, - |}, - BaseNavigationContainerInterface, - >; - - //--------------------------------------------------------------------------- - // SECTION 2: EXPORTED MODULE - // This section defines the module exports and contains exported types that - // are not present in any other React Navigation libdef. - //--------------------------------------------------------------------------- - - /** - * createBottomTabNavigator - */ - - declare export var createBottomTabNavigator: CreateNavigator< - TabNavigationState, - BottomTabOptions, - BottomTabNavigationEventMap, - ExtraBottomTabNavigatorProps, - >; - - /** - * BottomTabBar - */ - - declare export var BottomTabBar: React$ComponentType; - - /** - * BottomTabView - */ - - declare export type BottomTabViewProps = {| - ...BottomTabNavigationConfig, - ...BottomTabNavigationBuilderResult, - |}; - declare export var BottomTabView: React$ComponentType; - -} diff --git a/flow-typed/@react-navigation/drawer_v5.x.x.js b/flow-typed/@react-navigation/drawer_v5.x.x.js index be7acac6e06..f3929f73d10 100644 --- a/flow-typed/@react-navigation/drawer_v5.x.x.js +++ b/flow-typed/@react-navigation/drawer_v5.x.x.js @@ -26,7 +26,7 @@ declare module '@react-navigation/drawer' { | false | '' | $ReadOnlyArray - | {| [name: string]: any |}; + | {| [name: string]: $FlowFixMe |}; declare type ViewStyleProp = StyleObj; declare type TextStyleProp = StyleObj; declare type AnimatedViewStyleProp = StyleObj; @@ -59,9 +59,9 @@ declare module '@react-navigation/drawer' { declare interface AnimatedTracking { constructor( value: AnimatedValue, - parent: any, - animationClass: any, - animationConfig: Object, + parent: $FlowFixMe, + animationClass: $FlowFixMe, + animationConfig: $FlowFixMe, callback?: ?EndCallback, ): void; update(): void; @@ -307,7 +307,7 @@ declare module '@react-navigation/drawer' { uri?: ?string, bundle?: ?string, method?: ?string, - headers?: ?Object, + headers?: ?$FlowFixMe, body?: ?string, cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'), width?: ?number, @@ -367,8 +367,8 @@ declare module '@react-navigation/drawer' { ...$EventHandlers, id?: string, enabled?: boolean, - waitFor?: React$Ref | Array>, - simultaneousHandlers?: React$Ref | Array>, + waitFor?: React$Ref<$FlowFixMe> | Array>, + simultaneousHandlers?: React$Ref<$FlowFixMe> | Array>, shouldCancelWhenOutside?: boolean, minPointers?: number, hitSlop?: HitSlop, @@ -541,7 +541,7 @@ declare module '@react-navigation/drawer' { State: NavigationState, Action: GenericNavigationAction, > = {| - +[key: string]: (...args: any) => (Action | State => Action), + +[key: string]: (...args: $FlowFixMe) => (Action | State => Action), |}; declare export type DefaultRouterOptions = { @@ -569,7 +569,7 @@ declare module '@react-navigation/drawer' { +type: $PropertyType, +getInitialState: (options: RouterConfigOptions) => State, +getRehydratedState: ( - partialState: PossibleStaleNavigationState, + partialState: PossiblyStaleNavigationState, options: RouterConfigOptions, ) => State, +getStateForRouteNamesChange: ( @@ -840,11 +840,13 @@ declare module '@react-navigation/drawer' { >>, +setOptions: (options: $Shape) => void, +setParams: ( - params: $If< - $IsUndefined<$ElementType>, - empty, - $Shape<$NonMaybeType<$ElementType>>, - >, + // We've edited this to be less complicated, so Flow in types-first + // mode can handle it. + // + // The complicated version appears to have been a workaround for the + // brokenness of $Shape: `$Shape` is `{ ... }`. `$Partial` is + // basically the fixed `$Shape`, and makes the complexity unneeded. + params: $Partial<$NonMaybeType<$ElementType>>, ) => void, ... }; @@ -862,8 +864,8 @@ declare module '@react-navigation/drawer' { |}; declare export type ScreenListeners< - EventMap: EventMapBase = EventMapCore, State: NavigationState = NavigationState, + EventMap: EventMapBase = EventMapCore, > = $ObjMapi< {| [name: $Keys]: empty |}, >(K, empty) => EventListenerCallback, @@ -885,11 +887,11 @@ declare module '@react-navigation/drawer' { navigation: NavProp, |}) => ScreenOptions, +listeners?: - | ScreenListeners + | ScreenListeners | ({| route: RouteProp, navigation: NavProp, - |}) => ScreenListeners, + |}) => ScreenListeners, +initialParams?: $Shape<$ElementType>, |}; @@ -1554,7 +1556,7 @@ declare module '@react-navigation/drawer' { declare export type PaperRoute = {| +key: string, +title?: string, - +icon?: any, + +icon?: $FlowFixMe, +badge?: string | number | boolean, +color?: string, +accessibilityLabel?: string, @@ -1680,7 +1682,7 @@ declare module '@react-navigation/drawer' { +children: ({| +addListener: (type: 'enter', listener: number => void) => void, +removeListener: (type: 'enter', listener: number => void) => void, - +position: any, // Reanimated.Node + +position: $FlowFixMe, // Reanimated.Node +render: React$Node => React$Node, +jumpTo: string => void, |}) => React$Node, @@ -1732,13 +1734,13 @@ declare module '@react-navigation/drawer' { ...MaterialTopTabBarOptions, ...MaterialTopTabNavigationBuilderResult, +layout: {| +width: number, +height: number |}, - +position: any, // Reanimated.Node + +position: $FlowFixMe, // Reanimated.Node +jumpTo: string => void, |}; declare export type MaterialTopTabNavigationConfig = {| ...$Partial, - +position?: any, // Reanimated.Value + +position?: $FlowFixMe, // Reanimated.Value +tabBarPosition?: 'top' | 'bottom', +initialLayout?: $Shape<{| +width: number, +height: number |}>, +lazy?: boolean, @@ -1861,7 +1863,7 @@ declare module '@react-navigation/drawer' { declare export type DrawerContentProps = {| ...DrawerContentOptions, ...DrawerNavigationBuilderResult, - +progress: any, // Reanimated.Node + +progress: $FlowFixMe, // Reanimated.Node |}; declare export type DrawerNavigationConfig = {| diff --git a/flow-typed/@react-navigation/material-top-tabs_v5.x.x.js b/flow-typed/@react-navigation/material-top-tabs_v5.x.x.js index 1a7d2aeda0a..46163959819 100644 --- a/flow-typed/@react-navigation/material-top-tabs_v5.x.x.js +++ b/flow-typed/@react-navigation/material-top-tabs_v5.x.x.js @@ -26,7 +26,7 @@ declare module '@react-navigation/material-top-tabs' { | false | '' | $ReadOnlyArray - | {| [name: string]: any |}; + | {| [name: string]: $FlowFixMe |}; declare type ViewStyleProp = StyleObj; declare type TextStyleProp = StyleObj; declare type AnimatedViewStyleProp = StyleObj; @@ -59,9 +59,9 @@ declare module '@react-navigation/material-top-tabs' { declare interface AnimatedTracking { constructor( value: AnimatedValue, - parent: any, - animationClass: any, - animationConfig: Object, + parent: $FlowFixMe, + animationClass: $FlowFixMe, + animationConfig: $FlowFixMe, callback?: ?EndCallback, ): void; update(): void; @@ -307,7 +307,7 @@ declare module '@react-navigation/material-top-tabs' { uri?: ?string, bundle?: ?string, method?: ?string, - headers?: ?Object, + headers?: ?$FlowFixMe, body?: ?string, cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'), width?: ?number, @@ -367,8 +367,8 @@ declare module '@react-navigation/material-top-tabs' { ...$EventHandlers, id?: string, enabled?: boolean, - waitFor?: React$Ref | Array>, - simultaneousHandlers?: React$Ref | Array>, + waitFor?: React$Ref<$FlowFixMe> | Array>, + simultaneousHandlers?: React$Ref<$FlowFixMe> | Array>, shouldCancelWhenOutside?: boolean, minPointers?: number, hitSlop?: HitSlop, @@ -541,7 +541,7 @@ declare module '@react-navigation/material-top-tabs' { State: NavigationState, Action: GenericNavigationAction, > = {| - +[key: string]: (...args: any) => (Action | State => Action), + +[key: string]: (...args: $FlowFixMe) => (Action | State => Action), |}; declare export type DefaultRouterOptions = { @@ -569,7 +569,7 @@ declare module '@react-navigation/material-top-tabs' { +type: $PropertyType, +getInitialState: (options: RouterConfigOptions) => State, +getRehydratedState: ( - partialState: PossibleStaleNavigationState, + partialState: PossiblyStaleNavigationState, options: RouterConfigOptions, ) => State, +getStateForRouteNamesChange: ( @@ -840,11 +840,13 @@ declare module '@react-navigation/material-top-tabs' { >>, +setOptions: (options: $Shape) => void, +setParams: ( - params: $If< - $IsUndefined<$ElementType>, - empty, - $Shape<$NonMaybeType<$ElementType>>, - >, + // We've edited this to be less complicated, so Flow in types-first + // mode can handle it. + // + // The complicated version appears to have been a workaround for the + // brokenness of $Shape: `$Shape` is `{ ... }`. `$Partial` is + // basically the fixed `$Shape`, and makes the complexity unneeded. + params: $Partial<$NonMaybeType<$ElementType>>, ) => void, ... }; @@ -862,8 +864,8 @@ declare module '@react-navigation/material-top-tabs' { |}; declare export type ScreenListeners< - EventMap: EventMapBase = EventMapCore, State: NavigationState = NavigationState, + EventMap: EventMapBase = EventMapCore, > = $ObjMapi< {| [name: $Keys]: empty |}, >(K, empty) => EventListenerCallback, @@ -885,11 +887,11 @@ declare module '@react-navigation/material-top-tabs' { navigation: NavProp, |}) => ScreenOptions, +listeners?: - | ScreenListeners + | ScreenListeners | ({| route: RouteProp, navigation: NavProp, - |}) => ScreenListeners, + |}) => ScreenListeners, +initialParams?: $Shape<$ElementType>, |}; @@ -1554,7 +1556,7 @@ declare module '@react-navigation/material-top-tabs' { declare export type PaperRoute = {| +key: string, +title?: string, - +icon?: any, + +icon?: $FlowFixMe, +badge?: string | number | boolean, +color?: string, +accessibilityLabel?: string, @@ -1680,7 +1682,7 @@ declare module '@react-navigation/material-top-tabs' { +children: ({| +addListener: (type: 'enter', listener: number => void) => void, +removeListener: (type: 'enter', listener: number => void) => void, - +position: any, // Reanimated.Node + +position: $FlowFixMe, // Reanimated.Node +render: React$Node => React$Node, +jumpTo: string => void, |}) => React$Node, @@ -1732,13 +1734,13 @@ declare module '@react-navigation/material-top-tabs' { ...MaterialTopTabBarOptions, ...MaterialTopTabNavigationBuilderResult, +layout: {| +width: number, +height: number |}, - +position: any, // Reanimated.Node + +position: $FlowFixMe, // Reanimated.Node +jumpTo: string => void, |}; declare export type MaterialTopTabNavigationConfig = {| ...$Partial, - +position?: any, // Reanimated.Value + +position?: $FlowFixMe, // Reanimated.Value +tabBarPosition?: 'top' | 'bottom', +initialLayout?: $Shape<{| +width: number, +height: number |}>, +lazy?: boolean, @@ -1861,7 +1863,7 @@ declare module '@react-navigation/material-top-tabs' { declare export type DrawerContentProps = {| ...DrawerContentOptions, ...DrawerNavigationBuilderResult, - +progress: any, // Reanimated.Node + +progress: $FlowFixMe, // Reanimated.Node |}; declare export type DrawerNavigationConfig = {| diff --git a/flow-typed/@react-navigation/native_v5.x.x.js b/flow-typed/@react-navigation/native_v5.x.x.js index 2c4c3813968..e54f9f5375a 100644 --- a/flow-typed/@react-navigation/native_v5.x.x.js +++ b/flow-typed/@react-navigation/native_v5.x.x.js @@ -26,7 +26,7 @@ declare module '@react-navigation/native' { | false | '' | $ReadOnlyArray - | {| [name: string]: any |}; + | {| [name: string]: $FlowFixMe |}; declare type ViewStyleProp = StyleObj; declare type TextStyleProp = StyleObj; declare type AnimatedViewStyleProp = StyleObj; @@ -59,9 +59,9 @@ declare module '@react-navigation/native' { declare interface AnimatedTracking { constructor( value: AnimatedValue, - parent: any, - animationClass: any, - animationConfig: Object, + parent: $FlowFixMe, + animationClass: $FlowFixMe, + animationConfig: $FlowFixMe, callback?: ?EndCallback, ): void; update(): void; @@ -307,7 +307,7 @@ declare module '@react-navigation/native' { uri?: ?string, bundle?: ?string, method?: ?string, - headers?: ?Object, + headers?: ?$FlowFixMe, body?: ?string, cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'), width?: ?number, @@ -367,8 +367,8 @@ declare module '@react-navigation/native' { ...$EventHandlers, id?: string, enabled?: boolean, - waitFor?: React$Ref | Array>, - simultaneousHandlers?: React$Ref | Array>, + waitFor?: React$Ref<$FlowFixMe> | Array>, + simultaneousHandlers?: React$Ref<$FlowFixMe> | Array>, shouldCancelWhenOutside?: boolean, minPointers?: number, hitSlop?: HitSlop, @@ -541,7 +541,7 @@ declare module '@react-navigation/native' { State: NavigationState, Action: GenericNavigationAction, > = {| - +[key: string]: (...args: any) => (Action | State => Action), + +[key: string]: (...args: $FlowFixMe) => (Action | State => Action), |}; declare export type DefaultRouterOptions = { @@ -569,7 +569,7 @@ declare module '@react-navigation/native' { +type: $PropertyType, +getInitialState: (options: RouterConfigOptions) => State, +getRehydratedState: ( - partialState: PossibleStaleNavigationState, + partialState: PossiblyStaleNavigationState, options: RouterConfigOptions, ) => State, +getStateForRouteNamesChange: ( @@ -840,11 +840,13 @@ declare module '@react-navigation/native' { >>, +setOptions: (options: $Shape) => void, +setParams: ( - params: $If< - $IsUndefined<$ElementType>, - empty, - $Shape<$NonMaybeType<$ElementType>>, - >, + // We've edited this to be less complicated, so Flow in types-first + // mode can handle it. + // + // The complicated version appears to have been a workaround for the + // brokenness of $Shape: `$Shape` is `{ ... }`. `$Partial` is + // basically the fixed `$Shape`, and makes the complexity unneeded. + params: $Partial<$NonMaybeType<$ElementType>>, ) => void, ... }; @@ -862,8 +864,8 @@ declare module '@react-navigation/native' { |}; declare export type ScreenListeners< - EventMap: EventMapBase = EventMapCore, State: NavigationState = NavigationState, + EventMap: EventMapBase = EventMapCore, > = $ObjMapi< {| [name: $Keys]: empty |}, >(K, empty) => EventListenerCallback, @@ -885,11 +887,11 @@ declare module '@react-navigation/native' { navigation: NavProp, |}) => ScreenOptions, +listeners?: - | ScreenListeners + | ScreenListeners | ({| route: RouteProp, navigation: NavProp, - |}) => ScreenListeners, + |}) => ScreenListeners, +initialParams?: $Shape<$ElementType>, |}; @@ -1554,7 +1556,7 @@ declare module '@react-navigation/native' { declare export type PaperRoute = {| +key: string, +title?: string, - +icon?: any, + +icon?: $FlowFixMe, +badge?: string | number | boolean, +color?: string, +accessibilityLabel?: string, @@ -1680,7 +1682,7 @@ declare module '@react-navigation/native' { +children: ({| +addListener: (type: 'enter', listener: number => void) => void, +removeListener: (type: 'enter', listener: number => void) => void, - +position: any, // Reanimated.Node + +position: $FlowFixMe, // Reanimated.Node +render: React$Node => React$Node, +jumpTo: string => void, |}) => React$Node, @@ -1732,13 +1734,13 @@ declare module '@react-navigation/native' { ...MaterialTopTabBarOptions, ...MaterialTopTabNavigationBuilderResult, +layout: {| +width: number, +height: number |}, - +position: any, // Reanimated.Node + +position: $FlowFixMe, // Reanimated.Node +jumpTo: string => void, |}; declare export type MaterialTopTabNavigationConfig = {| ...$Partial, - +position?: any, // Reanimated.Value + +position?: $FlowFixMe, // Reanimated.Value +tabBarPosition?: 'top' | 'bottom', +initialLayout?: $Shape<{| +width: number, +height: number |}>, +lazy?: boolean, @@ -1861,7 +1863,7 @@ declare module '@react-navigation/native' { declare export type DrawerContentProps = {| ...DrawerContentOptions, ...DrawerNavigationBuilderResult, - +progress: any, // Reanimated.Node + +progress: $FlowFixMe, // Reanimated.Node |}; declare export type DrawerNavigationConfig = {| diff --git a/flow-typed/@react-navigation/stack_v5.x.x.js b/flow-typed/@react-navigation/stack_v5.x.x.js index 5359d011134..619d4ada0d2 100644 --- a/flow-typed/@react-navigation/stack_v5.x.x.js +++ b/flow-typed/@react-navigation/stack_v5.x.x.js @@ -26,7 +26,7 @@ declare module '@react-navigation/stack' { | false | '' | $ReadOnlyArray - | {| [name: string]: any |}; + | {| [name: string]: $FlowFixMe |}; declare type ViewStyleProp = StyleObj; declare type TextStyleProp = StyleObj; declare type AnimatedViewStyleProp = StyleObj; @@ -59,9 +59,9 @@ declare module '@react-navigation/stack' { declare interface AnimatedTracking { constructor( value: AnimatedValue, - parent: any, - animationClass: any, - animationConfig: Object, + parent: $FlowFixMe, + animationClass: $FlowFixMe, + animationConfig: $FlowFixMe, callback?: ?EndCallback, ): void; update(): void; @@ -307,7 +307,7 @@ declare module '@react-navigation/stack' { uri?: ?string, bundle?: ?string, method?: ?string, - headers?: ?Object, + headers?: ?$FlowFixMe, body?: ?string, cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'), width?: ?number, @@ -367,8 +367,8 @@ declare module '@react-navigation/stack' { ...$EventHandlers, id?: string, enabled?: boolean, - waitFor?: React$Ref | Array>, - simultaneousHandlers?: React$Ref | Array>, + waitFor?: React$Ref<$FlowFixMe> | Array>, + simultaneousHandlers?: React$Ref<$FlowFixMe> | Array>, shouldCancelWhenOutside?: boolean, minPointers?: number, hitSlop?: HitSlop, @@ -541,7 +541,7 @@ declare module '@react-navigation/stack' { State: NavigationState, Action: GenericNavigationAction, > = {| - +[key: string]: (...args: any) => (Action | State => Action), + +[key: string]: (...args: $FlowFixMe) => (Action | State => Action), |}; declare export type DefaultRouterOptions = { @@ -569,7 +569,7 @@ declare module '@react-navigation/stack' { +type: $PropertyType, +getInitialState: (options: RouterConfigOptions) => State, +getRehydratedState: ( - partialState: PossibleStaleNavigationState, + partialState: PossiblyStaleNavigationState, options: RouterConfigOptions, ) => State, +getStateForRouteNamesChange: ( @@ -864,8 +864,8 @@ declare module '@react-navigation/stack' { |}; declare export type ScreenListeners< - EventMap: EventMapBase = EventMapCore, State: NavigationState = NavigationState, + EventMap: EventMapBase = EventMapCore, > = $ObjMapi< {| [name: $Keys]: empty |}, >(K, empty) => EventListenerCallback, @@ -887,11 +887,11 @@ declare module '@react-navigation/stack' { navigation: NavProp, |}) => ScreenOptions, +listeners?: - | ScreenListeners + | ScreenListeners | ({| route: RouteProp, navigation: NavProp, - |}) => ScreenListeners, + |}) => ScreenListeners, +initialParams?: $Shape<$ElementType>, |}; @@ -1556,7 +1556,7 @@ declare module '@react-navigation/stack' { declare export type PaperRoute = {| +key: string, +title?: string, - +icon?: any, + +icon?: $FlowFixMe, +badge?: string | number | boolean, +color?: string, +accessibilityLabel?: string, @@ -1682,7 +1682,7 @@ declare module '@react-navigation/stack' { +children: ({| +addListener: (type: 'enter', listener: number => void) => void, +removeListener: (type: 'enter', listener: number => void) => void, - +position: any, // Reanimated.Node + +position: $FlowFixMe, // Reanimated.Node +render: React$Node => React$Node, +jumpTo: string => void, |}) => React$Node, @@ -1734,13 +1734,13 @@ declare module '@react-navigation/stack' { ...MaterialTopTabBarOptions, ...MaterialTopTabNavigationBuilderResult, +layout: {| +width: number, +height: number |}, - +position: any, // Reanimated.Node + +position: $FlowFixMe, // Reanimated.Node +jumpTo: string => void, |}; declare export type MaterialTopTabNavigationConfig = {| ...$Partial, - +position?: any, // Reanimated.Value + +position?: $FlowFixMe, // Reanimated.Value +tabBarPosition?: 'top' | 'bottom', +initialLayout?: $Shape<{| +width: number, +height: number |}>, +lazy?: boolean, @@ -1863,7 +1863,7 @@ declare module '@react-navigation/stack' { declare export type DrawerContentProps = {| ...DrawerContentOptions, ...DrawerNavigationBuilderResult, - +progress: any, // Reanimated.Node + +progress: $FlowFixMe, // Reanimated.Node |}; declare export type DrawerNavigationConfig = {| diff --git a/types/@react-navigation/bottom-tabs.js.flow b/types/@react-navigation/bottom-tabs.js.flow new file mode 100644 index 00000000000..92e0cd3aec5 --- /dev/null +++ b/types/@react-navigation/bottom-tabs.js.flow @@ -0,0 +1,2049 @@ +/* +Types for the NPM package `@react-navigation/bottom-tabs`. + +Largely copied from @react-navigation/bottom-tabs_v5.x.x from flow-typed. + +@flow strict-local +*/ + +//--------------------------------------------------------------------------- +// SECTION 1: IDENTICAL TYPE DEFINITIONS +// This section is identical across all React Navigation libdefs and contains +// shared definitions. We wish we could make it DRY and import from a shared +// definition, but that isn't yet possible. +//--------------------------------------------------------------------------- + +/** + * We start with some definitions that we have copy-pasted from React Native + * source files. + */ + +// This is a bastardization of the true StyleObj type located in +// react-native/Libraries/StyleSheet/StyleSheetTypes. We unfortunately can't +// import that here, and it's too lengthy (and consequently too brittle) to +// copy-paste here either. +type StyleObj = + | null + | void + | number + | false + | '' + | $ReadOnlyArray + | {| [name: string]: $FlowFixMe |}; +type ViewStyleProp = StyleObj; +type TextStyleProp = StyleObj; +type AnimatedViewStyleProp = StyleObj; +type AnimatedTextStyleProp = StyleObj; + +// Vaguely copied from +// react-native/Libraries/Animated/src/animations/Animation.js +type EndResult = { finished: boolean, ... }; +type EndCallback = (result: EndResult) => void; +interface Animation { + start( + fromValue: number, + onUpdate: (value: number) => void, + onEnd: ?EndCallback, + previousAnimation: ?Animation, + animatedValue: AnimatedValue, + ): void; + stop(): void; +} +type AnimationConfig = { + isInteraction?: boolean, + useNativeDriver: boolean, + onComplete?: ?EndCallback, + iterations?: number, + ... +}; + +// Vaguely copied from +// react-native/Libraries/Animated/src/nodes/AnimatedTracking.js +interface AnimatedTracking { + constructor( + value: AnimatedValue, + parent: $FlowFixMe, + animationClass: $FlowFixMe, + animationConfig: $FlowFixMe, + callback?: ?EndCallback, + ): void; + update(): void; +} + +// Vaguely copied from +// react-native/Libraries/Animated/nodes/AnimatedValue.js +type ValueListenerCallback = (state: { value: number, ... }) => void; +interface AnimatedValue { + constructor(value: number): void; + setValue(value: number): void; + setOffset(offset: number): void; + flattenOffset(): void; + extractOffset(): void; + addListener(callback: ValueListenerCallback): string; + removeListener(id: string): void; + removeAllListeners(): void; + stopAnimation(callback?: ?(value: number) => void): void; + resetAnimation(callback?: ?(value: number) => void): void; + interpolate(config: InterpolationConfigType): AnimatedInterpolation; + animate(animation: Animation, callback: ?EndCallback): void; + stopTracking(): void; + track(tracking: AnimatedTracking): void; +} + +// Copied from +// react-native/Libraries/Animated/src/animations/TimingAnimation.js +type TimingAnimationConfigSingle = AnimationConfig & { + toValue: number | AnimatedValue, + easing?: (value: number) => number, + duration?: number, + delay?: number, + ... +}; + +// Copied from +// react-native/Libraries/Animated/src/animations/SpringAnimation.js +type SpringAnimationConfigSingle = AnimationConfig & { + toValue: number | AnimatedValue, + overshootClamping?: boolean, + restDisplacementThreshold?: number, + restSpeedThreshold?: number, + velocity?: number, + bounciness?: number, + speed?: number, + tension?: number, + friction?: number, + stiffness?: number, + damping?: number, + mass?: number, + delay?: number, + ... +}; + +// Copied from react-native/Libraries/Types/CoreEventTypes.js +type SyntheticEvent = $ReadOnly<{| + bubbles: ?boolean, + cancelable: ?boolean, + currentTarget: number, + defaultPrevented: ?boolean, + dispatchConfig: $ReadOnly<{| + registrationName: string, + |}>, + eventPhase: ?number, + preventDefault: () => void, + isDefaultPrevented: () => boolean, + stopPropagation: () => void, + isPropagationStopped: () => boolean, + isTrusted: ?boolean, + nativeEvent: T, + persist: () => void, + target: ?number, + timeStamp: number, + type: ?string, +|}>; +type Layout = $ReadOnly<{| + x: number, + y: number, + width: number, + height: number, +|}>; +type LayoutEvent = SyntheticEvent< + $ReadOnly<{| + layout: Layout, + |}>, +>; +type BlurEvent = SyntheticEvent< + $ReadOnly<{| + target: number, + |}>, +>; +type FocusEvent = SyntheticEvent< + $ReadOnly<{| + target: number, + |}>, +>; +type ResponderSyntheticEvent = $ReadOnly<{| + ...SyntheticEvent, + touchHistory: $ReadOnly<{| + indexOfSingleActiveTouch: number, + mostRecentTimeStamp: number, + numberActiveTouches: number, + touchBank: $ReadOnlyArray< + $ReadOnly<{| + touchActive: boolean, + startPageX: number, + startPageY: number, + startTimeStamp: number, + currentPageX: number, + currentPageY: number, + currentTimeStamp: number, + previousPageX: number, + previousPageY: number, + previousTimeStamp: number, + |}>, + >, + |}>, +|}>; +type PressEvent = ResponderSyntheticEvent< + $ReadOnly<{| + changedTouches: $ReadOnlyArray<$PropertyType>, + force: number, + identifier: number, + locationX: number, + locationY: number, + pageX: number, + pageY: number, + target: ?number, + timestamp: number, + touches: $ReadOnlyArray<$PropertyType>, + |}>, +>; + +// Vaguely copied from +// react-native/Libraries/Animated/src/nodes/AnimatedInterpolation.js +type ExtrapolateType = 'extend' | 'identity' | 'clamp'; +type InterpolationConfigType = { + inputRange: Array, + outputRange: Array | Array, + easing?: (input: number) => number, + extrapolate?: ExtrapolateType, + extrapolateLeft?: ExtrapolateType, + extrapolateRight?: ExtrapolateType, + ... +}; +interface AnimatedInterpolation { + interpolate(config: InterpolationConfigType): AnimatedInterpolation; +} + +// Copied from react-native/Libraries/Components/View/ViewAccessibility.js +type AccessibilityRole = + | 'none' + | 'button' + | 'link' + | 'search' + | 'image' + | 'keyboardkey' + | 'text' + | 'adjustable' + | 'imagebutton' + | 'header' + | 'summary' + | 'alert' + | 'checkbox' + | 'combobox' + | 'menu' + | 'menubar' + | 'menuitem' + | 'progressbar' + | 'radio' + | 'radiogroup' + | 'scrollbar' + | 'spinbutton' + | 'switch' + | 'tab' + | 'tablist' + | 'timer' + | 'toolbar'; +type AccessibilityActionInfo = $ReadOnly<{ + name: string, + label?: string, + ... +}>; +type AccessibilityActionEvent = SyntheticEvent< + $ReadOnly<{actionName: string, ...}>, +>; +type AccessibilityState = { + disabled?: boolean, + selected?: boolean, + checked?: ?boolean | 'mixed', + busy?: boolean, + expanded?: boolean, + ... +}; +type AccessibilityValue = $ReadOnly<{| + min?: number, + max?: number, + now?: number, + text?: string, +|}>; + +// Copied from +// react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js +type Stringish = string; +type EdgeInsetsProp = $ReadOnly<$Shape>; +type TouchableWithoutFeedbackProps = $ReadOnly<{| + accessibilityActions?: ?$ReadOnlyArray, + accessibilityElementsHidden?: ?boolean, + accessibilityHint?: ?Stringish, + accessibilityIgnoresInvertColors?: ?boolean, + accessibilityLabel?: ?Stringish, + accessibilityLiveRegion?: ?('none' | 'polite' | 'assertive'), + accessibilityRole?: ?AccessibilityRole, + accessibilityState?: ?AccessibilityState, + accessibilityValue?: ?AccessibilityValue, + accessibilityViewIsModal?: ?boolean, + accessible?: ?boolean, + children?: ?React$Node, + delayLongPress?: ?number, + delayPressIn?: ?number, + delayPressOut?: ?number, + disabled?: ?boolean, + focusable?: ?boolean, + hitSlop?: ?EdgeInsetsProp, + importantForAccessibility?: ?('auto' | 'yes' | 'no' | 'no-hide-descendants'), + nativeID?: ?string, + onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed, + onBlur?: ?(event: BlurEvent) => mixed, + onFocus?: ?(event: FocusEvent) => mixed, + onLayout?: ?(event: LayoutEvent) => mixed, + onLongPress?: ?(event: PressEvent) => mixed, + onPress?: ?(event: PressEvent) => mixed, + onPressIn?: ?(event: PressEvent) => mixed, + onPressOut?: ?(event: PressEvent) => mixed, + pressRetentionOffset?: ?EdgeInsetsProp, + rejectResponderTermination?: ?boolean, + testID?: ?string, + touchSoundDisabled?: ?boolean, +|}>; + +// Copied from react-native/Libraries/Image/ImageSource.js +type ImageURISource = $ReadOnly<{ + uri?: ?string, + bundle?: ?string, + method?: ?string, + headers?: ?$FlowFixMe, + body?: ?string, + cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'), + width?: ?number, + height?: ?number, + scale?: ?number, + ... +}>; + +/** + * The following is copied from react-native-gesture-handler's libdef + */ + +type $Event = $FlowFixMe; // TODO: fill this in (from r-n-gesture-handler?) + +type $EventHandlers = {| + onGestureEvent?: ($Event) => mixed, + onHandlerStateChange?: ($Event) => mixed, + onBegan?: ($Event) => mixed, + onFailed?: ($Event) => mixed, + onCancelled?: ($Event) => mixed, + onActivated?: ($Event) => mixed, + onEnded?: ($Event) => mixed, +|}; + +type HitSlop = + | number + | {| + left?: number, + top?: number, + right?: number, + bottom?: number, + vertical?: number, + horizontal?: number, + width?: number, + height?: number, + |} + | {| + width: number, + left: number, + |} + | {| + width: number, + right: number, + |} + | {| + height: number, + top: number, + |} + | {| + height: number, + bottom: number, + |}; + +type $GestureHandlerProps< + AdditionalProps: {...}, + ExtraEventsProps: {...} +> = $ReadOnly<{| + ...$Exact, + ...$EventHandlers, + id?: string, + enabled?: boolean, + waitFor?: React$Ref<$FlowFixMe> | Array>, + simultaneousHandlers?: React$Ref<$FlowFixMe> | Array>, + shouldCancelWhenOutside?: boolean, + minPointers?: number, + hitSlop?: HitSlop, + children?: React$Node, +|}>; + +type PanGestureHandlerProps = $GestureHandlerProps< + { + activeOffsetY?: number | [number, number], + activeOffsetX?: number | [number, number], + failOffsetY?: number | [number, number], + failOffsetX?: number | [number, number], + minDist?: number, + minVelocity?: number, + minVelocityX?: number, + minVelocityY?: number, + minPointers?: number, + maxPointers?: number, + avgTouches?: boolean, + ... + }, + { + x: number, + y: number, + absoluteX: number, + absoluteY: number, + translationX: number, + translationY: number, + velocityX: number, + velocityY: number, + ... + } +>; + +/** + * MAGIC + */ + +type $If = $Call< + ((true, Then, Else) => Then) & ((false, Then, Else) => Else), + Test, + Then, + Else, +>; +type $IsA = $Call< + (Y => true) & (mixed => false), + X, +>; +type $IsUndefined = $IsA; + +type $Partial = $Rest; + +/** + * Actions, state, etc. + */ + +export type ScreenParams = {| +[key: string]: mixed |}; + +export type BackAction = {| + +type: 'GO_BACK', + +source?: string, + +target?: string, +|}; +export type NavigateAction = {| + +type: 'NAVIGATE', + +payload: + | {| +key: string, +params?: ScreenParams |} + | {| +name: string, +key?: string, +params?: ScreenParams |}, + +source?: string, + +target?: string, +|}; +export type ResetAction = {| + +type: 'RESET', + +payload: StaleNavigationState, + +source?: string, + +target?: string, +|}; +export type SetParamsAction = {| + +type: 'SET_PARAMS', + +payload: {| +params?: ScreenParams |}, + +source?: string, + +target?: string, +|}; +export type CommonAction = + | BackAction + | NavigateAction + | ResetAction + | SetParamsAction; + +type NavigateActionCreator = {| + (routeName: string, params?: ScreenParams): NavigateAction, + ( + | {| +key: string, +params?: ScreenParams |} + | {| +name: string, +key?: string, +params?: ScreenParams |}, + ): NavigateAction, +|}; +export type CommonActionsType = {| + +navigate: NavigateActionCreator, + +goBack: () => BackAction, + +reset: (state: PossiblyStaleNavigationState) => ResetAction, + +setParams: (params: ScreenParams) => SetParamsAction, +|}; + +export type GenericNavigationAction = {| + +type: string, + +payload?: {| +[key: string]: mixed |}, + +source?: string, + +target?: string, +|}; + +export type LeafRoute = {| + +key: string, + +name: RouteName, + +params?: ScreenParams, +|}; +export type StateRoute = {| + ...LeafRoute, + +state: NavigationState | StaleNavigationState, +|}; +export type Route = + | LeafRoute + | StateRoute; + +export type NavigationState = {| + +key: string, + +index: number, + +routeNames: $ReadOnlyArray, + +history?: $ReadOnlyArray, + +routes: $ReadOnlyArray>, + +type: string, + +stale: false, +|}; + +export type StaleLeafRoute = {| + +key?: string, + +name: RouteName, + +params?: ScreenParams, +|}; +export type StaleStateRoute = {| + ...StaleLeafRoute, + +state: StaleNavigationState, +|}; +export type StaleRoute = + | StaleLeafRoute + | StaleStateRoute; +export type StaleNavigationState = {| + // It's possible to pass React Nav a StaleNavigationState with an undefined + // index, but React Nav will always return one with the index set. This is + // the same as for the type property below, but in the case of index we tend + // to rely on it being set more... + +index: number, + +history?: $ReadOnlyArray, + +routes: $ReadOnlyArray>, + +type?: string, + +stale?: true, +|}; + +export type PossiblyStaleNavigationState = + | NavigationState + | StaleNavigationState; +export type PossiblyStaleRoute = + | Route + | StaleRoute; + +/** + * Routers + */ + +type ActionCreators< + State: NavigationState, + Action: GenericNavigationAction, +> = {| + +[key: string]: (...args: $FlowFixMe) => (Action | State => Action), +|}; + +export type DefaultRouterOptions = { + +initialRouteName?: string, + ... +}; + +export type RouterFactory< + State: NavigationState, + Action: GenericNavigationAction, + RouterOptions: DefaultRouterOptions, +> = (options: RouterOptions) => Router; + +export type ParamListBase = {| +[key: string]: ?ScreenParams |}; + +export type RouterConfigOptions = {| + +routeNames: $ReadOnlyArray, + +routeParamList: ParamListBase, +|}; + +export type Router< + State: NavigationState, + Action: GenericNavigationAction, +> = {| + +type: $PropertyType, + +getInitialState: (options: RouterConfigOptions) => State, + +getRehydratedState: ( + partialState: PossiblyStaleNavigationState, + options: RouterConfigOptions, + ) => State, + +getStateForRouteNamesChange: ( + state: State, + options: RouterConfigOptions, + ) => State, + +getStateForRouteFocus: (state: State, key: string) => State, + +getStateForAction: ( + state: State, + action: Action, + options: RouterConfigOptions, + ) => ?PossiblyStaleNavigationState; + +shouldActionChangeFocus: (action: GenericNavigationAction) => boolean, + +actionCreators?: ActionCreators, +|}; + +/** + * Stack actions and router + */ + +export type StackNavigationState = {| + ...NavigationState, + +type: 'stack', +|}; + +export type ReplaceAction = {| + +type: 'REPLACE', + +payload: {| +name: string, +key?: ?string, +params?: ScreenParams |}, + +source?: string, + +target?: string, +|}; +export type PushAction = {| + +type: 'PUSH', + +payload: {| +name: string, +key?: ?string, +params?: ScreenParams |}, + +source?: string, + +target?: string, +|}; +export type PopAction = {| + +type: 'POP', + +payload: {| +count: number |}, + +source?: string, + +target?: string, +|}; +export type PopToTopAction = {| + +type: 'POP_TO_TOP', + +source?: string, + +target?: string, +|}; +export type StackAction = + | CommonAction + | ReplaceAction + | PushAction + | PopAction + | PopToTopAction; + +export type StackActionsType = {| + +replace: (routeName: string, params?: ScreenParams) => ReplaceAction, + +push: (routeName: string, params?: ScreenParams) => PushAction, + +pop: (count?: number) => PopAction, + +popToTop: () => PopToTopAction, +|}; + +export type StackRouterOptions = $Exact; + +/** + * Tab actions and router + */ + +export type TabNavigationState = {| + ...NavigationState, + +type: 'tab', + +history: $ReadOnlyArray<{| type: 'route', key: string |}>, +|}; + +export type JumpToAction = {| + +type: 'JUMP_TO', + +payload: {| +name: string, +params?: ScreenParams |}, + +source?: string, + +target?: string, +|}; +export type TabAction = + | CommonAction + | JumpToAction; + +export type TabActionsType = {| + +jumpTo: string => JumpToAction, +|}; + +export type TabRouterOptions = {| + ...$Exact, + +backBehavior?: 'initialRoute' | 'order' | 'history' | 'none', +|}; + +/** + * Drawer actions and router + */ + +type DrawerHistoryEntry = + | {| +type: 'route', +key: string |} + | {| +type: 'drawer' |}; +export type DrawerNavigationState = {| + ...NavigationState, + +type: 'drawer', + +history: $ReadOnlyArray, +|}; + +export type OpenDrawerAction = {| + +type: 'OPEN_DRAWER', + +source?: string, + +target?: string, +|}; +export type CloseDrawerAction = {| + +type: 'CLOSE_DRAWER', + +source?: string, + +target?: string, +|}; +export type ToggleDrawerAction = {| + +type: 'TOGGLE_DRAWER', + +source?: string, + +target?: string, +|}; +export type DrawerAction = + | TabAction + | OpenDrawerAction + | CloseDrawerAction + | ToggleDrawerAction; + +export type DrawerActionsType = {| + ...TabActionsType, + +openDrawer: () => OpenDrawerAction, + +closeDrawer: () => CloseDrawerAction, + +toggleDrawer: () => ToggleDrawerAction, +|}; + +export type DrawerRouterOptions = {| + ...TabRouterOptions, + +openByDefault?: boolean, +|}; + +/** + * Events + */ + +export type EventMapBase = {| + +[name: string]: {| + +data?: mixed, + +canPreventDefault?: boolean, + |}, +|}; +type EventPreventDefaultProperties = $If< + Test, + {| +defaultPrevented: boolean, +preventDefault: () => void |}, + {| |}, +>; +type EventDataProperties = $If< + $IsUndefined, + {| |}, + {| +data: Data |}, +>; +type EventArg< + EventName: string, + CanPreventDefault: ?boolean = false, + Data = void, +> = {| + ...EventPreventDefaultProperties, + ...EventDataProperties, + +type: EventName, + +target?: string, +|}; +type GlobalEventMap = {| + +state: {| +data: {| +state: State |}, +canPreventDefault: false |}, +|}; +type EventMapCore = {| + ...GlobalEventMap, + +focus: {| +data: void, +canPreventDefault: false |}, + +blur: {| +data: void, +canPreventDefault: false |}, +|}; +type EventListenerCallback< + EventName: string, + State: PossiblyStaleNavigationState = NavigationState, + EventMap: EventMapBase = EventMapCore, +> = (e: EventArg< + EventName, + $PropertyType< + $ElementType< + {| ...EventMap, ...EventMapCore |}, + EventName, + >, + 'canPreventDefault', + >, + $PropertyType< + $ElementType< + {| ...EventMap, ...EventMapCore |}, + EventName, + >, + 'data', + >, +>) => mixed; + +/** + * Navigation prop + */ + +export type SimpleNavigate = + >( + routeName: DestinationRouteName, + params: $ElementType, + ) => void; + +export type Navigate = + & SimpleNavigate + & >( + route: + | {| + key: string, + params?: $ElementType, + |} + | {| + name: DestinationRouteName, + key?: string, + params?: $ElementType, + |}, + ) => void; + +type NavigationHelpers< + ParamList: ParamListBase, + State: PossiblyStaleNavigationState = PossiblyStaleNavigationState, + EventMap: EventMapBase = EventMapCore, +> = { + +navigate: Navigate, + +dispatch: ( + action: + | GenericNavigationAction + | (State => GenericNavigationAction), + ) => void, + +reset: PossiblyStaleNavigationState => void, + +goBack: () => void, + +isFocused: () => boolean, + +canGoBack: () => boolean, + +dangerouslyGetParent: >() => ?Parent, + +dangerouslyGetState: () => NavigationState, + +addListener: |}, + >>( + name: EventName, + callback: EventListenerCallback, + ) => () => void, + +removeListener: |}, + >>( + name: EventName, + callback: EventListenerCallback, + ) => void, + ... +}; + +export type NavigationProp< + ParamList: ParamListBase, + +RouteName: $Keys = $Keys, + State: PossiblyStaleNavigationState = PossiblyStaleNavigationState, + ScreenOptions: {...} = {...}, + EventMap: EventMapBase = EventMapCore, +> = { + ...$Exact>, + +setOptions: (options: $Shape) => void, + +setParams: ( + // We've edited this to be less complicated, so Flow in types-first + // mode can handle it. + // + // The complicated version appears to have been a workaround for the + // brokenness of $Shape: `$Shape` is `{ ... }`. `$Partial` is + // basically the fixed `$Shape`, and makes the complexity unneeded. + params: $Partial<$NonMaybeType<$ElementType>>, + ) => void, + ... +}; + +/** + * CreateNavigator + */ + +export type RouteProp< + ParamList: ParamListBase, + RouteName: $Keys, +> = {| + ...LeafRoute, + +params: $ElementType, +|}; + +export type ScreenListeners< + State: NavigationState = NavigationState, + EventMap: EventMapBase = EventMapCore, +> = $ObjMapi< + {| [name: $Keys]: empty |}, + >(K, empty) => EventListenerCallback, +>; + +type BaseScreenProps< + ParamList: ParamListBase, + NavProp, + RouteName: $Keys = $Keys, + State: NavigationState = NavigationState, + ScreenOptions: {...} = {...}, + EventMap: EventMapBase = EventMapCore, +> = {| + +name: RouteName, + +options?: + | ScreenOptions + | ({| + route: RouteProp, + navigation: NavProp, + |}) => ScreenOptions, + +listeners?: + | ScreenListeners + | ({| + route: RouteProp, + navigation: NavProp, + |}) => ScreenListeners, + +initialParams?: $Shape<$ElementType>, +|}; + +export type ScreenProps< + ParamList: ParamListBase, + NavProp, + RouteName: $Keys = $Keys, + State: NavigationState = NavigationState, + ScreenOptions: {...} = {...}, + EventMap: EventMapBase = EventMapCore, +> = + | {| + ...BaseScreenProps< + ParamList, + NavProp, + RouteName, + State, + ScreenOptions, + EventMap, + >, + +component: React$ComponentType<{| + route: RouteProp, + navigation: NavProp, + |}>, + |} + | {| + ...BaseScreenProps< + ParamList, + NavProp, + RouteName, + State, + ScreenOptions, + EventMap, + >, + +children: ({| + route: RouteProp, + navigation: NavProp, + |}) => React$Node, + |}; + +export type ScreenComponent< + GlobalParamList: ParamListBase, + ParamList: ParamListBase, + State: NavigationState = NavigationState, + ScreenOptions: {...} = {...}, + EventMap: EventMapBase = EventMapCore, +> = < + RouteName: $Keys, + NavProp: NavigationProp< + GlobalParamList, + RouteName, + State, + ScreenOptions, + EventMap, + >, +>(props: ScreenProps< + ParamList, + NavProp, + RouteName, + State, + ScreenOptions, + EventMap, +>) => React$Node; + +type ScreenOptionsProp = {| + +screenOptions?: + | ScreenOptions + | ({| route: LeafRoute<>, navigation: NavProp |}) => ScreenOptions, +|}; +export type ExtraNavigatorPropsBase = { + ...$Exact, + +children?: React$Node, + ... +}; +export type NavigatorPropsBase = { + ...$Exact, + ...ScreenOptionsProp, + ... +}; + +export type CreateNavigator< + State: NavigationState, + ScreenOptions: {...}, + EventMap: EventMapBase, + ExtraNavigatorProps: ExtraNavigatorPropsBase, +> = < + GlobalParamList: ParamListBase, + ParamList: ParamListBase, + NavProp: NavigationHelpers< + GlobalParamList, + State, + EventMap, + >, +>() => {| + +Screen: ScreenComponent< + GlobalParamList, + ParamList, + State, + ScreenOptions, + EventMap, + >, + +Navigator: React$ComponentType<{| + ...$Exact, + ...ScreenOptionsProp, + |}>, +|}; + +export type CreateNavigatorFactory = < + State: NavigationState, + ScreenOptions: {...}, + EventMap: EventMapBase, + NavProp: NavigationHelpers< + ParamListBase, + State, + EventMap, + >, + ExtraNavigatorProps: ExtraNavigatorPropsBase, +>( + navigator: React$ComponentType<{| + ...$Exact, + ...ScreenOptionsProp, + |}>, +) => CreateNavigator; + +/** + * useNavigationBuilder + */ + +export type Descriptor< + NavProp, + ScreenOptions: {...} = {...}, +> = {| + +render: () => React$Node, + +options: $ReadOnly, + +navigation: NavProp, +|}; + +export type UseNavigationBuilder = < + State: NavigationState, + Action: GenericNavigationAction, + ScreenOptions: {...}, + RouterOptions: DefaultRouterOptions, + NavProp, +>( + routerFactory: RouterFactory, + options: {| + ...$Exact, + ...ScreenOptionsProp, + +children?: React$Node, + |}, +) => {| + +state: State, + +descriptors: {| +[key: string]: Descriptor |}, + +navigation: NavProp, +|}; + +/** + * EdgeInsets + */ + +type EdgeInsets = {| + +top: number, + +right: number, + +bottom: number, + +left: number, +|}; + +/** + * TransitionPreset + */ + +export type TransitionSpec = + | {| + animation: 'spring', + config: $Diff< + SpringAnimationConfigSingle, + { toValue: number | AnimatedValue, ... }, + >, + |} + | {| + animation: 'timing', + config: $Diff< + TimingAnimationConfigSingle, + { toValue: number | AnimatedValue, ... }, + >, + |}; + +export type StackCardInterpolationProps = {| + +current: {| + +progress: AnimatedInterpolation, + |}, + +next?: {| + +progress: AnimatedInterpolation, + |}, + +index: number, + +closing: AnimatedInterpolation, + +swiping: AnimatedInterpolation, + +inverted: AnimatedInterpolation, + +layouts: {| + +screen: {| +width: number, +height: number |}, + |}, + +insets: EdgeInsets, +|}; +export type StackCardInterpolatedStyle = {| + containerStyle?: AnimatedViewStyleProp, + cardStyle?: AnimatedViewStyleProp, + overlayStyle?: AnimatedViewStyleProp, + shadowStyle?: AnimatedViewStyleProp, +|}; +export type StackCardStyleInterpolator = ( + props: StackCardInterpolationProps, +) => StackCardInterpolatedStyle; + +export type StackHeaderInterpolationProps = {| + +current: {| + +progress: AnimatedInterpolation, + |}, + +next?: {| + +progress: AnimatedInterpolation, + |}, + +layouts: {| + +header: {| +width: number, +height: number |}, + +screen: {| +width: number, +height: number |}, + +title?: {| +width: number, +height: number |}, + +leftLabel?: {| +width: number, +height: number |}, + |}, +|}; +export type StackHeaderInterpolatedStyle = {| + leftLabelStyle?: AnimatedViewStyleProp, + leftButtonStyle?: AnimatedViewStyleProp, + rightButtonStyle?: AnimatedViewStyleProp, + titleStyle?: AnimatedViewStyleProp, + backgroundStyle?: AnimatedViewStyleProp, +|}; +export type StackHeaderStyleInterpolator = ( + props: StackHeaderInterpolationProps, +) => StackHeaderInterpolatedStyle; + +type GestureDirection = + | 'horizontal' + | 'horizontal-inverted' + | 'vertical' + | 'vertical-inverted'; + +export type TransitionPreset = {| + +gestureDirection: GestureDirection, + +transitionSpec: {| + +open: TransitionSpec, + +close: TransitionSpec, + |}, + +cardStyleInterpolator: StackCardStyleInterpolator, + +headerStyleInterpolator: StackHeaderStyleInterpolator, +|}; + +/** + * Stack options + */ + +export type StackDescriptor = Descriptor< + StackNavigationProp<>, + StackOptions, +>; + +type Scene = {| + +route: T, + +descriptor: StackDescriptor, + +progress: {| + +current: AnimatedInterpolation, + +next?: AnimatedInterpolation, + +previous?: AnimatedInterpolation, + |}, +|}; + +export type StackHeaderProps = {| + +mode: 'float' | 'screen', + +layout: {| +width: number, +height: number |}, + +insets: EdgeInsets, + +scene: Scene>, + +previous?: Scene>, + +navigation: StackNavigationProp, + +styleInterpolator: StackHeaderStyleInterpolator, +|}; + +export type StackHeaderLeftButtonProps = $Shape<{| + +onPress: (() => void), + +pressColorAndroid: string; + +backImage: (props: {| tintColor: string |}) => React$Node, + +tintColor: string, + +label: string, + +truncatedLabel: string, + +labelVisible: boolean, + +labelStyle: AnimatedTextStyleProp, + +allowFontScaling: boolean, + +onLabelLayout: LayoutEvent => void, + +screenLayout: {| +width: number, +height: number |}, + +titleLayout: {| +width: number, +height: number |}, + +canGoBack: boolean, +|}>; + +type StackHeaderTitleInputBase = { + +onLayout: LayoutEvent => void, + +children: string, + +allowFontScaling: ?boolean, + +tintColor: ?string, + +style: ?AnimatedTextStyleProp, + ... +}; + +export type StackHeaderTitleInputProps = + $Exact; + +export type StackOptions = $Shape<{| + +title: string, + +header: StackHeaderProps => React$Node, + +headerShown: boolean, + +cardShadowEnabled: boolean, + +cardOverlayEnabled: boolean, + +cardOverlay: {| style: ViewStyleProp |} => React$Node, + +cardStyle: ViewStyleProp, + +animationEnabled: boolean, + +animationTypeForReplace: 'push' | 'pop', + +gestureEnabled: boolean, + +gestureResponseDistance: {| vertical?: number, horizontal?: number |}, + +gestureVelocityImpact: number, + +safeAreaInsets: $Shape, + // Transition + ...TransitionPreset, + // Header + +headerTitle: string | (StackHeaderTitleInputProps => React$Node), + +headerTitleAlign: 'left' | 'center', + +headerTitleStyle: AnimatedTextStyleProp, + +headerTitleContainerStyle: ViewStyleProp, + +headerTintColor: string, + +headerTitleAllowFontScaling: boolean, + +headerBackAllowFontScaling: boolean, + +headerBackTitle: string | null, + +headerBackTitleStyle: TextStyleProp, + +headerBackTitleVisible: boolean, + +headerTruncatedBackTitle: string, + +headerLeft: StackHeaderLeftButtonProps => React$Node, + +headerLeftContainerStyle: ViewStyleProp, + +headerRight: {| tintColor?: string |} => React$Node, + +headerRightContainerStyle: ViewStyleProp, + +headerBackImage: $PropertyType, + +headerPressColorAndroid: string, + +headerBackground: ({| style: ViewStyleProp |}) => React$Node, + +headerStyle: ViewStyleProp, + +headerTransparent: boolean, + +headerStatusBarHeight: number, +|}>; + +/** + * Stack navigation prop + */ + +export type StackNavigationEventMap = {| + ...EventMapCore, + +transitionStart: {| + +data: {| +closing: boolean |}, + +canPreventDefault: false, + |}, + +transitionEnd: {| + +data: {| +closing: boolean |}, + +canPreventDefault: false, + |}, +|}; + +type InexactStackNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = StackOptions, + EventMap: EventMapBase = StackNavigationEventMap, +> = { + ...$Exact>, + +replace: SimpleNavigate, + +push: SimpleNavigate, + +pop: (count?: number) => void, + +popToTop: () => void, + ... +}; + +export type StackNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = StackOptions, + EventMap: EventMapBase = StackNavigationEventMap, +> = $Exact>; + +/** + * Miscellaneous stack exports + */ + +type StackNavigationConfig = {| + +mode?: 'card' | 'modal', + +headerMode?: 'float' | 'screen' | 'none', + +keyboardHandlingEnabled?: boolean, +|}; + +export type ExtraStackNavigatorProps = {| + ...$Exact, + ...StackRouterOptions, + ...StackNavigationConfig, +|}; + +export type StackNavigatorProps< + NavProp: InexactStackNavigationProp<> = StackNavigationProp<>, +> = {| + ...ExtraStackNavigatorProps, + ...ScreenOptionsProp, +|}; + +/** + * Bottom tab options + */ + +export type BottomTabBarButtonProps = {| + ...$Diff< + TouchableWithoutFeedbackProps, + {| onPress?: ?(event: PressEvent) => mixed |}, + >, + +to?: string, + +children: React$Node, + +onPress?: (MouseEvent | PressEvent) => void, +|}; + +export type BottomTabOptions = $Shape<{| + +title: string, + +tabBarLabel: + | string + | ({| focused: boolean, color: string |}) => React$Node, + +tabBarIcon: ({| + focused: boolean, + color: string, + size: number, + |}) => React$Node, + +tabBarBadge?: number | string; + +tabBarBadgeStyle?: TextStyleProp; + +tabBarAccessibilityLabel: string, + +tabBarTestID: string, + +tabBarVisible: boolean, + +tabBarButton: BottomTabBarButtonProps => React$Node, + +unmountOnBlur: boolean, +|}>; + +/** + * Bottom tab navigation prop + */ + +export type BottomTabNavigationEventMap = {| + ...EventMapCore, + +tabPress: {| +data: void, +canPreventDefault: true |}, + +tabLongPress: {| +data: void, +canPreventDefault: false |}, +|}; + +type InexactTabNavigationProp< + ParamList: ParamListBase, + +RouteName: $Keys, + Options: {...}, + EventMap: EventMapBase, +> = { + ...$Exact>, + +jumpTo: SimpleNavigate, + ... +}; + +export type InexactBottomTabNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = BottomTabOptions, + EventMap: EventMapBase = BottomTabNavigationEventMap, +> = InexactTabNavigationProp< + ParamList, + RouteName, + Options, + EventMap, +>; + +export type BottomTabNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = BottomTabOptions, + EventMap: EventMapBase = BottomTabNavigationEventMap, +> = $Exact>; + +/** + * Miscellaneous bottom tab exports + */ + +export type BottomTabDescriptor = Descriptor< + BottomTabNavigationProp<>, + BottomTabOptions, +>; + +export type BottomTabBarOptions = $Shape<{| + +keyboardHidesTabBar: boolean, + +activeTintColor: string, + +inactiveTintColor: string, + +activeBackgroundColor: string, + +inactiveBackgroundColor: string, + +allowFontScaling: boolean, + +showLabel: boolean, + +showIcon: boolean, + +labelStyle: TextStyleProp, + +iconStyle: TextStyleProp, + +tabStyle: ViewStyleProp, + +labelPosition: 'beside-icon' | 'below-icon', + +adaptive: boolean, + +safeAreaInsets: $Shape, + +style: ViewStyleProp, +|}>; + +type BottomTabNavigationBuilderResult = {| + +state: TabNavigationState, + +navigation: BottomTabNavigationProp<>, + +descriptors: {| +[key: string]: BottomTabDescriptor |}, +|}; + +export type BottomTabBarProps = {| + ...BottomTabBarOptions, + ...BottomTabNavigationBuilderResult, +|} + +type BottomTabNavigationConfig = {| + +lazy?: boolean, + +tabBar?: BottomTabBarProps => React$Node, + +tabBarOptions?: BottomTabBarOptions, +|}; + +export type ExtraBottomTabNavigatorProps = {| + ...$Exact, + ...TabRouterOptions, + ...BottomTabNavigationConfig, +|}; + +export type BottomTabNavigatorProps< + NavProp: InexactBottomTabNavigationProp<> = BottomTabNavigationProp<>, +> = {| + ...ExtraBottomTabNavigatorProps, + ...ScreenOptionsProp, +|}; + +/** + * Material bottom tab options + */ + +export type MaterialBottomTabOptions = $Shape<{| + +title: string, + +tabBarColor: string, + +tabBarLabel: string, + +tabBarIcon: + | string + | ({| +focused: boolean, +color: string |}) => React$Node, + +tabBarBadge: boolean | number | string, + +tabBarAccessibilityLabel: string, + +tabBarTestID: string, +|}>; + +/** + * Material bottom tab navigation prop + */ + +export type MaterialBottomTabNavigationEventMap = {| + ...EventMapCore, + +tabPress: {| +data: void, +canPreventDefault: true |}, +|}; + +export type InexactMaterialBottomTabNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = MaterialBottomTabOptions, + EventMap: EventMapBase = MaterialBottomTabNavigationEventMap, +> = InexactTabNavigationProp< + ParamList, + RouteName, + Options, + EventMap, +>; + +export type MaterialBottomTabNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = MaterialBottomTabOptions, + EventMap: EventMapBase = MaterialBottomTabNavigationEventMap, +> = $Exact>; + +/** + * Miscellaneous material bottom tab exports + */ + +export type PaperFont = {| + +fontFamily: string, + +fontWeight?: + | 'normal' + | 'bold' + | '100' + | '200' + | '300' + | '400' + | '500' + | '600' + | '700' + | '800' + | '900', +|}; + +type Font = $FlowFixMe; // TODO: Fill this in (from @react-navigation/material-bottom-tabs?) + +export type PaperFonts = {| + +regular: Font, + +medium: Font, + +light: Font, + +thin: Font, +|}; + +export type PaperTheme = {| + +dark: boolean, + +mode?: 'adaptive' | 'exact', + +roundness: number, + +colors: {| + +primary: string, + +background: string, + +surface: string, + +accent: string, + +error: string, + +text: string, + +onSurface: string, + +onBackground: string, + +disabled: string, + +placeholder: string, + +backdrop: string, + +notification: string, + |}, + +fonts: PaperFonts, + +animation: {| + +scale: number, + |}, +|}; + +export type PaperRoute = {| + +key: string, + +title?: string, + +icon?: $FlowFixMe, + +badge?: string | number | boolean, + +color?: string, + +accessibilityLabel?: string, + +testID?: string, +|}; + +export type PaperTouchableProps = {| + ...TouchableWithoutFeedbackProps, + +key: string, + +route: PaperRoute, + +children: React$Node, + +borderless?: boolean, + +centered?: boolean, + +rippleColor?: string, +|}; + +export type MaterialBottomTabNavigationConfig = {| + +shifting?: boolean, + +labeled?: boolean, + +renderTouchable?: PaperTouchableProps => React$Node, + +activeColor?: string, + +inactiveColor?: string, + +sceneAnimationEnabled?: boolean, + +keyboardHidesNavigationBar?: boolean, + +barStyle?: ViewStyleProp, + +style?: ViewStyleProp, + +theme?: PaperTheme, +|}; + +export type ExtraMaterialBottomTabNavigatorProps = {| + ...$Exact, + ...TabRouterOptions, + ...MaterialBottomTabNavigationConfig, +|}; + +export type MaterialBottomTabNavigatorProps< + NavProp: InexactMaterialBottomTabNavigationProp<> = + MaterialBottomTabNavigationProp<>, +> = {| + ...ExtraMaterialBottomTabNavigatorProps, + ...ScreenOptionsProp, +|}; + +/** + * Material top tab options + */ + +export type MaterialTopTabOptions = $Shape<{| + +title: string, + +tabBarLabel: + | string + | ({| +focused: boolean, +color: string |}) => React$Node, + +tabBarIcon: ({| +focused: boolean, +color: string |}) => React$Node, + +tabBarAccessibilityLabel: string, + +tabBarTestID: string, +|}>; + +/** + * Material top tab navigation prop + */ + +export type MaterialTopTabNavigationEventMap = {| + ...EventMapCore, + +tabPress: {| +data: void, +canPreventDefault: true |}, + +tabLongPress: {| +data: void, +canPreventDefault: false |}, + +swipeStart: {| +data: void, +canPreventDefault: false |}, + +swipeEnd: {| +data: void, +canPreventDefault: false |}, +|}; + +export type InexactMaterialTopTabNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = MaterialTopTabOptions, + EventMap: EventMapBase = MaterialTopTabNavigationEventMap, +> = InexactTabNavigationProp< + ParamList, + RouteName, + Options, + EventMap, +>; + +export type MaterialTopTabNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = MaterialTopTabOptions, + EventMap: EventMapBase = MaterialTopTabNavigationEventMap, +> = $Exact>; + +/** + * Miscellaneous material top tab exports + */ + +type MaterialTopTabPagerCommonProps = {| + +keyboardDismissMode: 'none' | 'on-drag' | 'auto', + +swipeEnabled: boolean, + +swipeVelocityImpact?: number, + +springVelocityScale?: number, + +springConfig: $Shape<{| + +damping: number, + +mass: number, + +stiffness: number, + +restSpeedThreshold: number, + +restDisplacementThreshold: number, + |}>, + +timingConfig: $Shape<{| + +duration: number, + |}>, +|}; + +export type MaterialTopTabPagerProps = {| + ...MaterialTopTabPagerCommonProps, + +onSwipeStart?: () => void, + +onSwipeEnd?: () => void, + +onIndexChange: (index: number) => void, + +navigationState: TabNavigationState, + +layout: {| +width: number, +height: number |}, + +removeClippedSubviews: boolean, + +children: ({| + +addListener: (type: 'enter', listener: number => void) => void, + +removeListener: (type: 'enter', listener: number => void) => void, + +position: $FlowFixMe, // Reanimated.Node + +render: React$Node => React$Node, + +jumpTo: string => void, + |}) => React$Node, + +gestureHandlerProps: PanGestureHandlerProps, +|}; + +export type MaterialTopTabBarIndicatorProps = {| + +navigationState: TabNavigationState, + +width: string, + +style?: ViewStyleProp, + +getTabWidth: number => number, +|}; + +export type MaterialTopTabBarOptions = $Shape<{| + +scrollEnabled: boolean, + +bounces: boolean, + +pressColor: string, + +pressOpacity: number, + +getAccessible: ({| +route: Route<> |}) => boolean, + +renderBadge: ({| +route: Route<> |}) => React$Node, + +renderIndicator: MaterialTopTabBarIndicatorProps => React$Node, + +tabStyle: ViewStyleProp, + +indicatorStyle: ViewStyleProp, + +indicatorContainerStyle: ViewStyleProp, + +labelStyle: TextStyleProp, + +contentContainerStyle: ViewStyleProp, + +style: ViewStyleProp, + +activeTintColor: string, + +inactiveTintColor: string, + +iconStyle: ViewStyleProp, + +labelStyle: TextStyleProp, + +showLabel: boolean, + +showIcon: boolean, + +allowFontScaling: boolean, +|}>; + +export type MaterialTopTabDescriptor = Descriptor< + MaterialBottomTabNavigationProp<>, + MaterialBottomTabOptions, +>; + +type MaterialTopTabNavigationBuilderResult = {| + +state: TabNavigationState, + +navigation: MaterialTopTabNavigationProp<>, + +descriptors: {| +[key: string]: MaterialTopTabDescriptor |}, +|}; + +export type MaterialTopTabBarProps = {| + ...MaterialTopTabBarOptions, + ...MaterialTopTabNavigationBuilderResult, + +layout: {| +width: number, +height: number |}, + +position: $FlowFixMe, // Reanimated.Node + +jumpTo: string => void, +|}; + +export type MaterialTopTabNavigationConfig = {| + ...$Partial, + +position?: $FlowFixMe, // Reanimated.Value + +tabBarPosition?: 'top' | 'bottom', + +initialLayout?: $Shape<{| +width: number, +height: number |}>, + +lazy?: boolean, + +lazyPreloadDistance?: number, + +removeClippedSubviews?: boolean, + +sceneContainerStyle?: ViewStyleProp, + +style?: ViewStyleProp, + +gestureHandlerProps?: PanGestureHandlerProps, + +pager?: MaterialTopTabPagerProps => React$Node, + +lazyPlaceholder?: ({| +route: Route<> |}) => React$Node, + +tabBar?: MaterialTopTabBarProps => React$Node, + +tabBarOptions?: MaterialTopTabBarOptions, +|}; + +export type ExtraMaterialTopTabNavigatorProps = {| + ...$Exact, + ...TabRouterOptions, + ...MaterialTopTabNavigationConfig, +|}; + +export type MaterialTopTabNavigatorProps< + NavProp: InexactMaterialTopTabNavigationProp<> = + MaterialTopTabNavigationProp<>, +> = {| + ...ExtraMaterialTopTabNavigatorProps, + ...ScreenOptionsProp, +|}; + +/** + * Drawer options + */ + +export type DrawerOptions = $Shape<{| + title: string, + drawerLabel: + | string + | ({| +color: string, +focused: boolean |}) => React$Node, + drawerIcon: ({| + +color: string, + +size: number, + +focused: boolean, + |}) => React$Node, + gestureEnabled: boolean, + swipeEnabled: boolean, + unmountOnBlur: boolean, +|}>; + +/** + * Drawer navigation prop + */ + +export type DrawerNavigationEventMap = {| + ...EventMapCore, + +drawerOpen: {| +data: void, +canPreventDefault: false |}, + +drawerClose: {| +data: void, +canPreventDefault: false |}, +|}; + +export type InexactDrawerNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = DrawerOptions, + EventMap: EventMapBase = DrawerNavigationEventMap, +> = { + ...$Exact>, + +jumpTo: SimpleNavigate, + +openDrawer: () => void, + +closeDrawer: () => void, + +toggleDrawer: () => void, + ... +}; + +export type DrawerNavigationProp< + ParamList: ParamListBase = ParamListBase, + +RouteName: $Keys = $Keys, + Options: {...} = DrawerOptions, + EventMap: EventMapBase = DrawerNavigationEventMap, +> = $Exact>; + +/** + * Miscellaneous drawer exports + */ + +export type DrawerDescriptor = Descriptor< + DrawerNavigationProp<>, + DrawerOptions, +>; + +export type DrawerItemListBaseOptions = $Shape<{| + +activeTintColor: string, + +activeBackgroundColor: string, + +inactiveTintColor: string, + +inactiveBackgroundColor: string, + +itemStyle: ViewStyleProp, + +labelStyle: TextStyleProp, +|}>; + +export type DrawerContentOptions = $Shape<{| + ...DrawerItemListBaseOptions, + +contentContainerStyle: ViewStyleProp, + +style: ViewStyleProp, +|}>; + +type DrawerNavigationBuilderResult = {| + +state: DrawerNavigationState, + +navigation: DrawerNavigationProp<>, + +descriptors: {| +[key: string]: DrawerDescriptor |}, +|}; + +export type DrawerContentProps = {| + ...DrawerContentOptions, + ...DrawerNavigationBuilderResult, + +progress: $FlowFixMe, // Reanimated.Node +|}; + +export type DrawerNavigationConfig = {| + +drawerPosition?: 'left' | 'right', + +drawerType?: 'front' | 'back' | 'slide' | 'permanent', + +edgeWidth?: number, + +hideStatusBar?: boolean, + +keyboardDismissMode?: 'on-drag' | 'none', + +minSwipeDistance?: number, + +overlayColor?: string, + +statusBarAnimation?: 'slide' | 'none' | 'fade', + +gestureHandlerProps?: PanGestureHandlerProps, + +lazy?: boolean, + +drawerContent?: DrawerContentProps => React$Node, + +drawerContentOptions?: DrawerContentOptions, + +sceneContainerStyle?: ViewStyleProp, + +drawerStyle?: ViewStyleProp, +|}; + +export type ExtraDrawerNavigatorProps = {| + ...$Exact, + ...DrawerRouterOptions, + ...DrawerNavigationConfig, +|}; + +export type DrawerNavigatorProps< + NavProp: InexactDrawerNavigationProp<> = DrawerNavigationProp<>, +> = {| + ...ExtraDrawerNavigatorProps, + ...ScreenOptionsProp, +|}; + +/** + * BaseNavigationContainer + */ + +export type BaseNavigationContainerProps = {| + +children: React$Node, + +initialState?: PossiblyStaleNavigationState, + +onStateChange?: (state: ?PossiblyStaleNavigationState) => void, + +independent?: boolean, +|}; + +export type ContainerEventMap = {| + ...GlobalEventMap, + +options: {| + +data: {| +options: {| +[key: string]: mixed |} |}, + +canPreventDefault: false, + |}, + +__unsafe_action__: {| + +data: {| + +action: GenericNavigationAction, + +noop: boolean, + |}, + +canPreventDefault: false, + |}, +|}; + +export type BaseNavigationContainerInterface = {| + ...$Exact>, + +setParams: (params: ScreenParams) => void, + +resetRoot: (state?: ?PossiblyStaleNavigationState) => void, + +getRootState: () => NavigationState, +|}; + +/** + * State utils + */ + +export type GetStateFromPath = ( + path: string, + options?: LinkingConfig, +) => PossiblyStaleNavigationState; + +export type GetPathFromState = ( + state?: ?PossiblyStaleNavigationState, + options?: LinkingConfig, +) => string; + +export type GetFocusedRouteNameFromRoute = + PossiblyStaleRoute => ?string; + +/** + * Linking + */ + +export type ScreenLinkingConfig = {| + +path?: string, + +exact?: boolean, + +parse?: {| +[param: string]: string => mixed |}, + +stringify?: {| +[param: string]: mixed => string |}, + +screens?: ScreenLinkingConfigMap, + +initialRouteName?: string, +|}; + +export type ScreenLinkingConfigMap = {| + +[routeName: string]: string | ScreenLinkingConfig, +|}; + +export type LinkingConfig = {| + +initialRouteName?: string, + +screens: ScreenLinkingConfigMap, +|}; + +export type LinkingOptions = {| + +enabled?: boolean, + +prefixes: $ReadOnlyArray, + +config?: LinkingConfig, + +getStateFromPath?: GetStateFromPath, + +getPathFromState?: GetPathFromState, +|}; + +/** + * NavigationContainer + */ + +export type Theme = {| + +dark: boolean, + +colors: {| + +primary: string, + +background: string, + +card: string, + +text: string, + +border: string, + |}, +|}; + +export type NavigationContainerType = React$AbstractComponent< + {| + ...BaseNavigationContainerProps, + +theme?: Theme, + +linking?: LinkingOptions, + +fallback?: React$Node, + +onReady?: () => mixed, + |}, + BaseNavigationContainerInterface, +>; + +//--------------------------------------------------------------------------- +// SECTION 2: EXPORTED MODULE +// This section defines the module exports and contains exported types that +// are not present in any other React Navigation libdef. +//--------------------------------------------------------------------------- + +/** + * createBottomTabNavigator + */ + +export var createBottomTabNavigator: CreateNavigator< + TabNavigationState, + BottomTabOptions, + BottomTabNavigationEventMap, + ExtraBottomTabNavigatorProps, +>; + +/** + * BottomTabBar + */ + +export var BottomTabBar: React$ComponentType; + +/** + * BottomTabView + */ + +export type BottomTabViewProps = {| + ...BottomTabNavigationConfig, + ...BottomTabNavigationBuilderResult, +|}; +export var BottomTabView: React$ComponentType; diff --git a/types/__flow-tests__/@react-navigation/bottom-tabs-test.js b/types/__flow-tests__/@react-navigation/bottom-tabs-test.js new file mode 100644 index 00000000000..c34b14cad05 --- /dev/null +++ b/types/__flow-tests__/@react-navigation/bottom-tabs-test.js @@ -0,0 +1,36 @@ +/* @flow strict-local */ +import { type NavigationProp } from '@react-navigation/bottom-tabs'; + +/* eslint-disable no-unused-vars */ + +function test_setParams() { + type NavProp

= NavigationProp<{| r: P |}, 'r'>; + + function test_happy(navigation: NavProp<{| a: number |}>) { + navigation.setParams({ a: 1 }); + } + + function test_accepts_missing(navigation: NavProp<{| a: number, b: number |}>) { + navigation.setParams({ a: 1 }); + } + + function test_rejects_extra(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[prop-missing] + navigation.setParams({ b: 1 }); + } + + function test_rejects_mismatch(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[incompatible-call] + navigation.setParams({ a: 'a' }); + } + + function test_rejects_object_to_void(navigation: NavProp) { + // $FlowExpectedError[incompatible-call] + navigation.setParams({ a: 1 }); + } + + function test_rejects_void_to_object(navigation: NavProp<{| a: number |}>) { + // $FlowExpectedError[incompatible-call] + navigation.setParams(); + } +}