Instantly share code, notes, and snippets.
Mobile developer working with cross-platform tech.
- Montréal, Québec, Canada
-
00:24
(UTC -05:00) - https://yanickbelanger.dev?utm_source=github
- @yanthedev
- yan.blgr
emeraldsanto
/ make-navigator-usage-example.tsx
Last active
September 4, 2021 03:55
Achieving type safe deep linking in React Native with react-navigation #10
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
| // SomeStack.tsx | |
| export const SomeStackConfiguration = makeNavigator({ | |
| name: 'SomeStack', | |
| type: 'stack', | |
| screens: { | |
| [Screen.One]: { screen: ScreenOne }, | |
| [Screen.Two]: { screen: ScreenTwo }, | |
| [Screen.Three]: { screen: ScreenThree, options: { /* ... */ } }, | |
| // ... | |
| }, |
emeraldsanto
/ make-navigator-implementation-complete.tsx
Created
September 4, 2021 03:53
Achieving type safe deep linking in React Native with react-navigation #9
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
| const navigators = { | |
| stack: createStackNavigator, | |
| tab: createBottomTabNavigator, | |
| } as const; | |
| type NavigatorType = keyof typeof navigators; | |
| type NavigatorProps<T extends NavigatorType> = ComponentProps< | |
| ReturnType<typeof navigators[T]>['Navigator'] | |
| >; |
emeraldsanto
/ make-navigator-functions-explainer.tsx
Last active
September 4, 2021 03:52
Achieving type safe deep linking in React Native with react-navigation #8
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
| /** | |
| * Surprisingly, there is very little code here as all we really need to do | |
| * is provide a short hand for the default render function of the provided screens. | |
| * | |
| * If a custom `render` is provided, we execute it by passing the whole configuration | |
| * as props. | |
| * | |
| * Otherwise use the default behaviour defined in `renderScreens`. | |
| */ | |
| export function makeNavigator< |
emeraldsanto
/ make-navigator-implementation-types-explainer.ts
Created
September 4, 2021 03:50
Achieving type safe deep linking in React Native with react-navigation #7
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
| /** | |
| * This simply aggregates navigator constructors | |
| * and allows us to support more than one type of navigator. | |
| */ | |
| const navigators = { | |
| stack: createStackNavigator, | |
| tab: createBottomTabNavigator, | |
| } as const; | |
| /** |
emeraldsanto
/ make-navigator-implementation-types.ts
Created
September 4, 2021 03:49
Achieving type safe deep linking in React Native with react-navigation #6
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
| export enum Navigator { | |
| One = 'NavigatorOne', | |
| Two = 'NavigatorTwo', | |
| Three = 'NavigatorThree', | |
| } | |
| export enum Screen { | |
| One = 'ScreenOne', | |
| Two = 'ScreenTwo', | |
| Three = 'ScreenThree', |
emeraldsanto
/ make-navigator-custom.tsx
Last active
September 4, 2021 03:48
Achieving type safe deep linking in React Native with react-navigation #5
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
| const Tab = createBottomTabNavigator(); | |
| export const SomeTabConfiguration = makeNavigator({ | |
| name: 'SomeTab', | |
| type: 'tab', | |
| screens: { | |
| [Screen.One]: { screen: ScreenOne }, | |
| [Screen.Two]: { screen: ScreenTwo }, | |
| [Screen.Three]: { screen: ScreenThree, options: { /* ... */ } }, | |
| // ... |
emeraldsanto
/ make-navigator-basic.tsx
Created
September 4, 2021 03:45
Achieving type safe deep linking in React Native with react-navigation #4
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
| export const SomeStackConfiguration = makeNavigator({ | |
| name: 'SomeStack', | |
| type: 'stack', | |
| screens: { | |
| [Screen.One]: { screen: ScreenOne }, | |
| [Screen.Two]: { screen: ScreenTwo }, | |
| [Screen.Three]: { screen: ScreenThree, options: { /* ... */ } }, | |
| // ... | |
| }, | |
| linking: { |
emeraldsanto
/ react-navigation-old-navigator-example.tsx
Last active
September 4, 2021 03:44
Achieving type safe deep linking in React Native with react-navigation #3
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 { createStackNavigator } from '@react-navigation/stack'; | |
| import { Screen } from 'some-path/Screen'; | |
| import { ScreenOne } from 'some-path/ScreenOne'; | |
| import { ScreenTwo } from 'some-path/ScreenTwo'; | |
| import { ScreenThree } from 'some-path/ScreenThree'; | |
| const routeConfigMap = { | |
| [Screen.One]: { screen: ScreenOne }, | |
| [Screen.Two]: { screen: ScreenTwo }, | |
| [Screen.Three]: { screen: ScreenThree, options: { /* ... */ } }, |
emeraldsanto
/ react-navigation-linking-nested-example.tsx
Last active
September 4, 2021 03:42
Achieving type safe deep linking in React Native with react-navigation #2
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 { NavigationContainer } from '@react-navigation/native'; | |
| const config = { | |
| screens: { | |
| Home: { | |
| initialRouteName: 'Feed', | |
| screens: { | |
| Profile: 'users/:id', | |
| Feed: 'feed', | |
| }, |
emeraldsanto
/ react-navigation-linking-basic-example.tsx
Last active
September 4, 2021 03:39
Achieving type safe deep linking in React Native with react-navigation #1
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 { NavigationContainer } from '@react-navigation/native'; | |
| const linking = { | |
| prefixes: ['https://mychat.com', 'mychat://'], | |
| config: { | |
| screens: { | |
| Chat: 'feed/:sort', | |
| Profile: 'user', | |
| } | |
| }, |