Skip to content

Commit f3e2589

Browse files
author
Alejandro Lara
committed
Add listeners bindings across navigators
1 parent 152a632 commit f3e2589

File tree

7 files changed

+73
-4
lines changed

7 files changed

+73
-4
lines changed

src/BottomTabs.res

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,19 @@ and headerParams = {
9696
layout: layout,
9797
}
9898

99+
type listeners = {
100+
...Core.eventListeners,
101+
tabPress?: navigationEvent<unit> => unit,
102+
tabLongPress?: navigationEvent<unit> => unit,
103+
transitionStart?: navigationEvent<unit> => unit,
104+
transitionEnd?: navigationEvent<unit> => unit,
105+
}
106+
99107
type navigatorProps = {
100108
id?: string,
101109
initialRouteName?: string,
102110
screenOptions?: screenOptionsParams => options,
111+
screenListeners?: screenOptionsParams => listeners,
103112
backBehavior?: backBehavior,
104113
detachInactiveScreens?: bool,
105114
tabBar?: unit => React.element,
@@ -111,6 +120,7 @@ type screenProps<'params> = {
111120
name: string,
112121
navigationKey?: string,
113122
options?: screenOptionsParams => options,
123+
listeners?: screenOptionsParams => listeners,
114124
initialParams?: 'params,
115125
getId?: getIdOptions => option<string>,
116126
component?: React.component<screenProps>,
@@ -167,6 +177,9 @@ module Navigation = {
167177
@string
168178
[
169179
| #tabPress(navigationEvent<unit> => unit)
180+
| #tabLongPress(navigationEvent<unit> => unit)
181+
| #transitionStart(navigationEvent<unit> => unit)
182+
| #transitionEnd(navigationEvent<unit> => unit)
170183
],
171184
) => unsubscribe = "addListener"
172185
}

src/Core.res

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ type stateEventData = {state: navigationState}
5454

5555
type action
5656

57+
type beforeRemoveEventData = {action: action}
58+
59+
type eventListeners = {
60+
focus?: navigationEvent<unit> => unit,
61+
blur?: navigationEvent<unit> => unit,
62+
state?: navigationEvent<stateEventData> => unit,
63+
beforeRemove?: navigationEvent<beforeRemoveEventData> => unit,
64+
}
65+
5766
type layoutNavigatorParams = {
5867
state: navigationState,
5968
navigation: navigation,
@@ -100,6 +109,7 @@ module Navigation = {
100109
| #focus(navigationEvent<unit> => unit)
101110
| #blur(navigationEvent<unit> => unit)
102111
| #state(navigationEvent<stateEventData> => unit)
112+
| #beforeRemove(navigationEvent<beforeRemoveEventData> => unit)
103113
],
104114
) => unsubscribe = "addListener"
105115
}

src/Drawer.res

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,18 @@ type contentComponentProps = {
9090
descriptors: descriptors,
9191
}
9292

93+
type listeners = {
94+
...Core.eventListeners,
95+
drawerItemPress?: navigationEvent<unit> => unit,
96+
}
97+
9398
type drawerStatus = [#"open" | #closed]
9499

95100
type navigatorProps = {
96101
id?: string,
97102
initialRouteName?: string,
98103
screenOptions?: screenOptionsParams => options,
104+
screenListeners?: screenOptionsParams => listeners,
99105
backBehavior?: backBehavior,
100106
defaultStatus?: drawerStatus,
101107
detachInactiveScreens?: bool,
@@ -109,6 +115,7 @@ type screenProps<'params> = {
109115
name: string,
110116
navigationKey?: string,
111117
options?: screenOptionsParams => options,
118+
listeners?: screenOptionsParams => listeners,
112119
initialParams?: 'params,
113120
getId?: getIdOptions => option<string>,
114121
component?: React.component<screenProps>,

src/MaterialBottomTabs.res

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ type options = {
3535
tabBarTestID?: string,
3636
}
3737

38+
type listeners = {
39+
...Core.eventListeners,
40+
tabPress?: navigationEvent<unit> => unit,
41+
tabLongPress?: navigationEvent<unit> => unit,
42+
}
43+
3844
type navigatorProps = {
3945
id?: string,
4046
initialRouteName?: string,
4147
screenOptions?: screenOptionsParams => options,
48+
screenListeners?: screenOptionsParams => listeners,
4249
backBehavior?: backBehavior,
4350
shifting?: bool,
4451
labeled?: bool,
@@ -53,6 +60,7 @@ type screenProps<'params> = {
5360
name: string,
5461
navigationKey?: string,
5562
options?: screenOptionsParams => options,
63+
listeners?: screenOptionsParams => listeners,
5664
initialParams?: 'params,
5765
getId?: getIdOptions => option<string>,
5866
component?: React.component<screenProps>,
@@ -112,6 +120,7 @@ module Navigation = {
112120
@string
113121
[
114122
| #tabPress(navigationEvent<unit> => unit)
123+
| #tabLongPress(navigationEvent<unit> => unit)
115124
],
116125
) => unsubscribe = "addListener"
117126
}

src/MaterialTopTabs.res

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,17 @@ type tabBarProps = {
7676
jumpTo: string => unit,
7777
}
7878

79+
type listeners = {
80+
...Core.eventListeners,
81+
tabPress?: navigationEvent<unit> => unit,
82+
tabLongPress?: navigationEvent<unit> => unit,
83+
}
84+
7985
type navigatorProps = {
8086
id?: string,
8187
initialRouteName?: string,
8288
screenOptions?: screenOptionsParams => options,
89+
screenListeners?: screenOptionsParams => listeners,
8390
backBehavior?: backBehavior,
8491
tabBarPosition?: tabBarPosition,
8592
keyboardDismissMode?: keyboardDismissMode,
@@ -95,6 +102,7 @@ type screenProps<'params> = {
95102
name: string,
96103
navigationKey?: string,
97104
options?: screenOptionsParams => options,
105+
listeners?: screenOptionsParams => listeners,
98106
initialParams?: 'params,
99107
getId?: getIdOptions => option<string>,
100108
component?: React.component<screenProps>,
@@ -154,6 +162,7 @@ module Navigation = {
154162
@string
155163
[
156164
| #tabPress(navigationEvent<unit> => unit)
165+
| #tabLongPress(navigationEvent<unit> => unit)
157166
],
158167
) => unsubscribe = "addListener"
159168
}

src/NativeStack.res

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,20 @@ and headerParams = {
171171
back: backOptions,
172172
}
173173

174+
type screenEventData = {closing: bool}
175+
176+
type listeners = {
177+
...Core.eventListeners,
178+
transitionStart?: navigationEvent<screenEventData> => unit,
179+
transitionEnd?: navigationEvent<screenEventData> => unit,
180+
gestureCancel?: navigationEvent<unit> => unit,
181+
}
182+
174183
type navigatorProps = {
175184
id?: string,
176185
initialRouteName?: string,
177186
screenOptions?: screenOptionsParams => options,
187+
screenListeners?: screenOptionsParams => listeners,
178188
layout?: layoutNavigatorParams => React.element,
179189
children?: React.element,
180190
}
@@ -183,6 +193,7 @@ type screenProps<'params> = {
183193
name: string,
184194
navigationKey?: string,
185195
options?: screenOptionsParams => options,
196+
listeners?: screenOptionsParams => listeners,
186197
initialParams?: 'params,
187198
getId?: getIdOptions => option<string>,
188199
component?: React.component<screenProps>,
@@ -228,8 +239,6 @@ module Make = (): NavigatorModule => {
228239
}
229240
}
230241

231-
type screenEventData = {closing: int}
232-
233242
module Navigation = {
234243
@send
235244
external setOptions: (navigation, options) => unit = "setOptions"
@@ -255,6 +264,7 @@ module Navigation = {
255264
[
256265
| #transitionStart(navigationEvent<screenEventData> => unit)
257266
| #transitionEnd(navigationEvent<screenEventData> => unit)
267+
| #gestureCancel(navigationEvent<unit> => unit)
258268
],
259269
) => unsubscribe = "addListener"
260270
}

src/Stack.res

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,22 @@ and headerParams = {
154154
styleInterpolator: headerStyleInterpolator,
155155
}
156156

157+
type screenEventData = {closing: bool}
158+
159+
type listeners = {
160+
...Core.eventListeners,
161+
transitionStart?: navigationEvent<screenEventData> => unit,
162+
transitionEnd?: navigationEvent<screenEventData> => unit,
163+
gestureStart?: navigationEvent<unit> => unit,
164+
gestureEnd?: navigationEvent<unit> => unit,
165+
gestureCancel?: navigationEvent<unit> => unit,
166+
}
167+
157168
type navigatorProps = {
158169
id?: string,
159170
initialRouteName?: string,
160171
screenOptions?: screenOptionsParams => options,
172+
screenListeners?: screenOptionsParams => listeners,
161173
detachInactiveScreens?: bool,
162174
layout?: layoutNavigatorParams => React.element,
163175
children?: React.element,
@@ -167,6 +179,7 @@ type screenProps<'params> = {
167179
name: string,
168180
navigationKey?: string,
169181
options?: screenOptionsParams => options,
182+
listeners?: screenOptionsParams => listeners,
170183
initialParams?: 'params,
171184
getId?: getIdOptions => option<string>,
172185
component?: React.component<screenProps>,
@@ -212,8 +225,6 @@ module Make = (): NavigatorModule => {
212225
}
213226
}
214227

215-
type screenEventData = {closing: int}
216-
217228
module Navigation = {
218229
@send
219230
external setOptions: (navigation, options) => unit = "setOptions"

0 commit comments

Comments
 (0)