Last active
June 12, 2019 23:33
-
-
Save dangdennis/3ed0d759e2f04a4c1a6a2ef18d831971 to your computer and use it in GitHub Desktop.
Interop'ing a TS component into Reason
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[@bs.module "./routes.js"] [@react.component] | |
external make: (~name: string) => React.element = "default"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { View, Text } from 'react-native'; | |
import { | |
createStackNavigator, | |
createAppContainer, | |
NavigationContainer as ReactNavigationContainer, | |
HeaderProps, | |
createBottomTabNavigator | |
} from 'react-navigation'; | |
import { getCurrentRouteState } from './routeUtil'; | |
export type TopNavigationElement = React.ReactElement<any>; | |
export type BottomNavigationElement = React.ReactElement<any>; | |
const HeadingNavigationOptions = ({ navigation }) => { | |
const header = (headerProps: HeaderProps): TopNavigationElement | null => { | |
const { params } = getCurrentRouteState(navigation); | |
return params && params.topNavigation && params.topNavigation(headerProps); | |
}; | |
return { ...navigation, header }; | |
}; | |
function SearchScreen1() { | |
return ( | |
<View> | |
<Text h1>Search Screen 1</Text> | |
</View> | |
); | |
} | |
function SearchScreen2() { | |
return ( | |
<View> | |
<Text h1>Screen 2</Text> | |
</View> | |
); | |
} | |
function SearchScreen3() { | |
return ( | |
<View> | |
<Text h1>Screen 3</Text> | |
</View> | |
); | |
} | |
function DummyScreen1() { | |
return ( | |
<View> | |
<Text h1>Dummy Screen 1</Text> | |
</View> | |
); | |
} | |
function DummyScreen2() { | |
return ( | |
<View> | |
<Text h1>Screen 2</Text> | |
</View> | |
); | |
} | |
function DummyScreen3() { | |
return ( | |
<View> | |
<Text h1>Screen 3</Text> | |
</View> | |
); | |
} | |
const SearchNavigator: ReactNavigationContainer = createStackNavigator({ | |
Search1: { | |
screen: SearchScreen1 | |
}, | |
Search2: { | |
screen: SearchScreen2 | |
}, | |
Search3: { | |
screen: SearchScreen3 | |
} | |
}); | |
const DummyNavigator: ReactNavigationContainer = createStackNavigator({ | |
Dummy1: { | |
screen: DummyScreen1 | |
}, | |
Dummy2: { | |
screen: DummyScreen2 | |
}, | |
Dummy3: { | |
screen: DummyScreen3 | |
} | |
}); | |
const MenuNavigator: ReactNavigationContainer = createBottomTabNavigator({ | |
Search: SearchNavigator, | |
Dummy: DummyNavigator | |
}); | |
const AppNavigator: ReactNavigationContainer = createStackNavigator({ | |
Home: { | |
screen: MenuNavigator, | |
navigationOptions: HeadingNavigationOptions | |
} | |
}); | |
export default createAppContainer(AppNavigator); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment