|
| 1 | +open Core |
| 2 | + |
| 3 | +@module("react-native-screens") |
| 4 | +external enableScreens: unit => unit = "enableScreens" |
| 5 | + |
| 6 | +type options |
| 7 | + |
| 8 | +module NativeStackNavigationScreenProp = ( |
| 9 | + M: { |
| 10 | + type params |
| 11 | + type options |
| 12 | + }, |
| 13 | +) => { |
| 14 | + include NavigationScreenProp(M) |
| 15 | + |
| 16 | + type t = navigation |
| 17 | + |
| 18 | + @send external push: (t, string) => unit = "push" |
| 19 | + @send external pushWithParams: (t, string, M.params) => unit = "push" |
| 20 | + |
| 21 | + @send external pop: (t, ~count: int=?, unit) => unit = "pop" |
| 22 | + |
| 23 | + @send external popToTop: (t, unit) => unit = "popToTop" |
| 24 | +} |
| 25 | + |
| 26 | +module Make = ( |
| 27 | + M: { |
| 28 | + type params |
| 29 | + }, |
| 30 | +) => { |
| 31 | + type route = route<M.params> |
| 32 | + module Navigation = NativeStackNavigationScreenProp({ |
| 33 | + include M |
| 34 | + type options = options |
| 35 | + }) |
| 36 | + |
| 37 | + type headerBackTitleStyle = {fontFamily: option<string>, fontSize: option<float>} |
| 38 | + type headerLargeStyle = {backgroundColor: option<ReactNative.Color.t>} |
| 39 | + type headerLargeTitleStyle = { |
| 40 | + fontFamily: option<string>, |
| 41 | + fontSize: option<float>, |
| 42 | + color: option<ReactNative.Color.t>, |
| 43 | + } |
| 44 | + type blurEffect = [ |
| 45 | + | #extraLight |
| 46 | + | #light |
| 47 | + | #dark |
| 48 | + | #regular |
| 49 | + | #prominent |
| 50 | + | #systemUltraThinMaterial |
| 51 | + | #systemThinMaterial |
| 52 | + | #systemMaterial |
| 53 | + | #systemThickMaterial |
| 54 | + | #systemChromeMaterial |
| 55 | + | #systemUltraThinMaterialLight |
| 56 | + | #systemThinMaterialLight |
| 57 | + | #systemMaterialLight |
| 58 | + | #systemThickMaterialLight |
| 59 | + | #systemChromeMaterialLight |
| 60 | + | #systemUltraThinMaterialDark |
| 61 | + | #systemThinMaterialDark |
| 62 | + | #systemMaterialDark |
| 63 | + | #systemThickMaterialDark |
| 64 | + | #systemChromeMaterialDark |
| 65 | + ] |
| 66 | + type headerStyle = { |
| 67 | + backgroundColor: option<ReactNative.Color.t>, |
| 68 | + blurEffect: option<blurEffect>, |
| 69 | + } |
| 70 | + type headerTitleStyle = { |
| 71 | + fontFamily: option<string>, |
| 72 | + fontSize: option<float>, |
| 73 | + fontWeight: string, //ReactNative.Style.fontWeight, |
| 74 | + color: option<ReactNative.Color.t>, |
| 75 | + } |
| 76 | + |
| 77 | + @obj |
| 78 | + external options: ( |
| 79 | + ~backButtonInCustomView: bool=?, |
| 80 | + ~contentStyle: ReactNative.Style.t=?, |
| 81 | + ~direction: [#rtl | #ltr]=?, |
| 82 | + ~gestureEnabled: bool=?, |
| 83 | + ~headerBackTitle: string=?, |
| 84 | + ~headerBackTitleStyle: headerBackTitleStyle=?, |
| 85 | + ~headerBackTitleVisible: bool=?, |
| 86 | + ~headerCenter: unit => React.element=?, |
| 87 | + ~headerHideBackButton: bool=?, |
| 88 | + ~headerHideShadow: bool=?, |
| 89 | + ~headerLargeStyle: headerLargeStyle=?, |
| 90 | + ~headerLargeTitle: bool=?, |
| 91 | + ~headerLargeTitleHideShadow: bool=?, |
| 92 | + ~headerLargeTitleStyle: headerLargeTitleStyle=?, |
| 93 | + ~headerLeft: unit => React.element=?, |
| 94 | + ~headerRight: unit => React.element=?, |
| 95 | + ~headerShown: bool=?, |
| 96 | + ~headerStyle: headerStyle=?, |
| 97 | + ~headerTintColor: ReactNative.Color.t=?, |
| 98 | + ~headerTitle: string=?, |
| 99 | + ~headerTitleStyle: headerTitleStyle=?, |
| 100 | + ~headerTopInsetEnabled: bool=?, |
| 101 | + ~headerTranslucent: bool=?, |
| 102 | + ~replaceAnimation: [#push | #pop]=?, |
| 103 | + ~stackAnimation: [#default | #fade | #flip | #slide_from_right | #slide_from_left | #none]=?, |
| 104 | + ~stackPresentation: [ |
| 105 | + | #push |
| 106 | + | #modal |
| 107 | + | #transparentModal |
| 108 | + | #containedModal |
| 109 | + | #containedTransparentModal |
| 110 | + | #fullScreenModal |
| 111 | + | #formSheet |
| 112 | + ]=?, |
| 113 | + ~statusBarStyle: [#auto | #inverted | #light | #dark]=?, |
| 114 | + ~statusBarAnimation: [#fade | #none | #slide]=?, |
| 115 | + ~statusBarHidden: bool=?, |
| 116 | + ~screenOrientation: [ |
| 117 | + | #default |
| 118 | + | #all |
| 119 | + | #portrait |
| 120 | + | #portrait_up |
| 121 | + | #portrait_down |
| 122 | + | #landscape |
| 123 | + | #landscape_left |
| 124 | + | #landscape_right |
| 125 | + ]=?, |
| 126 | + ~title: string=?, |
| 127 | + unit, |
| 128 | + ) => options = "" |
| 129 | + |
| 130 | + type optionsProps = { |
| 131 | + navigation: navigation, |
| 132 | + route: route, |
| 133 | + } |
| 134 | + type optionsCallback = optionsProps => options |
| 135 | + |
| 136 | + type navigatorProps = { |
| 137 | + initialRouteName: option<string>, |
| 138 | + screenOptions: option<optionsCallback>, |
| 139 | + } |
| 140 | + type renderCallbackProp = { |
| 141 | + navigation: navigation, |
| 142 | + route: route, |
| 143 | + } |
| 144 | + type screenProps<'params> = { |
| 145 | + name: string, |
| 146 | + options: option<optionsCallback>, |
| 147 | + initialParams: option<'params>, |
| 148 | + component: option<React.component<{"navigation": navigation, "route": route}>>, |
| 149 | + children: option<renderCallbackProp => React.element>, |
| 150 | + } |
| 151 | + |
| 152 | + @module("react-native-screens/native-stack") |
| 153 | + external make: unit => { |
| 154 | + "Navigator": navigatorProps => React.element, |
| 155 | + "Screen": screenProps<M.params> => React.element, |
| 156 | + } = "createNativeStackNavigator" |
| 157 | + |
| 158 | + let stack = make() |
| 159 | + module ScreenWithCallback = { |
| 160 | + @obj |
| 161 | + external makeProps: ( |
| 162 | + ~name: string, |
| 163 | + ~options: optionsCallback=?, |
| 164 | + ~initialParams: M.params=?, |
| 165 | + ~children: renderCallbackProp => React.element, |
| 166 | + ~key: string=?, |
| 167 | + unit, |
| 168 | + ) => screenProps<M.params> = "" |
| 169 | + let make = stack["Screen"] |
| 170 | + } |
| 171 | + module Screen = { |
| 172 | + type componentProps = {navigation: navigation} |
| 173 | + @obj |
| 174 | + external makeProps: ( |
| 175 | + ~name: string, |
| 176 | + ~options: optionsCallback=?, |
| 177 | + ~initialParams: M.params=?, |
| 178 | + ~component: React.component<{"navigation": navigation, "route": route}>, |
| 179 | + ~key: string=?, |
| 180 | + unit, |
| 181 | + ) => screenProps<M.params> = "" |
| 182 | + |
| 183 | + let make = stack["Screen"] |
| 184 | + } |
| 185 | + |
| 186 | + module Navigator = { |
| 187 | + @obj |
| 188 | + external makeProps: ( |
| 189 | + ~initialRouteName: string=?, |
| 190 | + ~screenOptions: optionsCallback=?, |
| 191 | + ~children: React.element, |
| 192 | + ~key: string=?, |
| 193 | + unit, |
| 194 | + ) => navigatorProps = "" |
| 195 | + |
| 196 | + let make = stack["Navigator"] |
| 197 | + } |
| 198 | +} |
| 199 | + |
| 200 | +@val |
| 201 | +external mergeOptions: (options, options) => options = "Object.assign" |
0 commit comments