Skip to content

Feature for render callback of stack screen #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/Example.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,24 @@ var MainStackScreen_Header = include.Header;

var MainStackScreen_stack = include.stack;

var MainStackScreen_ScreenWithCallback = include.ScreenWithCallback;

var MainStackScreen = {
StakeParams: StakeParams,
Navigation: MainStackScreen_Navigation,
HeaderTitle: MainStackScreen_HeaderTitle,
Header: MainStackScreen_Header,
stack: MainStackScreen_stack,
ScreenWithCallback: MainStackScreen_ScreenWithCallback,
$$Screen: $$Screen,
$$Navigator: $$Navigator,
make: Example$MainStackScreen
};

var include$1 = Stack$ReactNavigation.Make({ });

var ScreenWithCallback = include$1.ScreenWithCallback;

var $$Screen$1 = include$1.$$Screen;

var $$Navigator$1 = include$1.$$Navigator;
Expand All @@ -98,9 +103,14 @@ function Example$RootStackScreen(Props) {
}, React.createElement($$Screen$1.make, {
name: "Main",
component: Example$MainStackScreen
}), React.createElement($$Screen$1.make, {
}), React.createElement(ScreenWithCallback.make, {
name: "MyModal",
component: Example$ModalScreen
children: (function (param) {
return React.createElement(Example$ModalScreen, {
navigation: param.navigation,
route: param.route
});
})
}))
});
}
Expand All @@ -118,6 +128,7 @@ var RootStackScreen = {
HeaderTitle: RootStackScreen_HeaderTitle,
Header: RootStackScreen_Header,
stack: RootStackScreen_stack,
ScreenWithCallback: ScreenWithCallback,
$$Screen: $$Screen$1,
$$Navigator: $$Navigator$1,
make: Example$RootStackScreen
Expand Down
4 changes: 3 additions & 1 deletion src/Example.re
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ module RootStackScreen = {
<Native.NavigationContainer>
<Navigator mode=`modal headerMode=`none>
<Screen name="Main" component=MainStackScreen.make />
<Screen name="MyModal" component=ModalScreen.make />
<ScreenWithCallback name="MyModal">
{({navigation, route}) => <ModalScreen navigation route />}
</ScreenWithCallback>
</Navigator>
</Native.NavigationContainer>;
};
11 changes: 8 additions & 3 deletions src/Stack.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,23 @@ function Make(M) {
};
var stack = Stack.createStackNavigator();
var make = stack.Screen;
var $$Screen = {
var ScreenWithCallback = {
make: make
};
var make$1 = stack.Navigator;
var $$Navigator = {
var make$1 = stack.Screen;
var $$Screen = {
make: make$1
};
var make$2 = stack.Navigator;
var $$Navigator = {
make: make$2
};
return {
Navigation: Navigation,
HeaderTitle: HeaderTitle,
Header: Header,
stack: stack,
ScreenWithCallback: ScreenWithCallback,
$$Screen: $$Screen,
$$Navigator: $$Navigator
};
Expand Down
51 changes: 32 additions & 19 deletions src/Stack.re
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ module TransitionSpec = {
};
[@bs.obj]
external spring:
(~animation: [@bs.string] [ | `spring], ~config: springConfig) => t =
"";
(~animation: [@bs.string] [ | `spring], ~config: springConfig) => t;

type timingConfig = {
duration: int,
Expand All @@ -99,8 +98,7 @@ module TransitionSpec = {

[@bs.obj]
external timing:
(~animation: [@bs.string] [ | `timing], ~config: timingConfig) => t =
"";
(~animation: [@bs.string] [ | `timing], ~config: timingConfig) => t;
};

type transitionSpec = {
Expand Down Expand Up @@ -136,8 +134,7 @@ module Make = (M: {type params;}) => {
type gestureResponseDistance;
[@bs.obj]
external gestureResponseDistance:
(~vertical: float=?, ~horizontal: float=?, unit) => gestureResponseDistance =
"";
(~vertical: float=?, ~horizontal: float=?, unit) => gestureResponseDistance;

module HeaderTitle = {
type t;
Expand Down Expand Up @@ -251,8 +248,7 @@ module Make = (M: {type params;}) => {
~headerStyleInterpolator: stackHeaderStyleInterpolator=?,
unit
) =>
options =
"";
options;
type optionsProps = {
navigation,
route,
Expand All @@ -266,17 +262,23 @@ module Make = (M: {type params;}) => {
headerMode: option(string),
keyboardHandlingEnabled: option(bool),
};

type renderCallbackProp = {
navigation,
route,
};
type screenProps('params) = {
name: string,
options: option(optionCallback),
initialParams: option('params),
component:
React.component({
.
"navigation": navigation,
"route": route,
}),
option(
React.component({
.
"navigation": navigation,
"route": route,
}),
),
children: option(renderCallbackProp => React.element),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead we should have screenProps & screenPropsWithCallback?

Copy link
Contributor Author

@a-c-sreedhar-reddy a-c-sreedhar-reddy Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/reason-react-native/reason-react-navigation/blob/master/src/Stack.re#L288

But argument of Screen function here can be only of one type right?

};

[@bs.module "@react-navigation/stack"]
Expand All @@ -290,7 +292,19 @@ module Make = (M: {type params;}) => {
"createStackNavigator";

let stack = make();

module ScreenWithCallback = {
[@bs.obj]
external makeProps:
(
~name: string,
~options: optionCallback=?,
~initialParams: M.params=?,
~children: renderCallbackProp => React.element,
unit
) =>
screenProps(M.params);
let make = stack##"Screen";
};
module Screen = {
type componentProps = {navigation};
[@bs.obj]
Expand All @@ -306,8 +320,8 @@ module Make = (M: {type params;}) => {
}),
unit
) =>
screenProps(M.params) =
"";
screenProps(M.params);

let make = stack##"Screen";
};

Expand All @@ -323,8 +337,7 @@ module Make = (M: {type params;}) => {
~children: React.element,
unit
) =>
navigatorProps =
"";
navigatorProps;

let make = stack##"Navigator";
};
Expand Down