Skip to content

Instantly share code, notes, and snippets.

View emeraldsanto's full-sized avatar

Yanick Bélanger emeraldsanto

View GitHub Profile
@emeraldsanto
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
// 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
emeraldsanto / make-navigator-implementation-complete.tsx
Created September 4, 2021 03:53
Achieving type safe deep linking in React Native with react-navigation #9
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
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
/**
* 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
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 simply aggregates navigator constructors
* and allows us to support more than one type of navigator.
*/
const navigators = {
stack: createStackNavigator,
tab: createBottomTabNavigator,
} as const;
/**
@emeraldsanto
emeraldsanto / make-navigator-implementation-types.ts
Created September 4, 2021 03:49
Achieving type safe deep linking in React Native with react-navigation #6
export enum Navigator {
One = 'NavigatorOne',
Two = 'NavigatorTwo',
Three = 'NavigatorThree',
}
export enum Screen {
One = 'ScreenOne',
Two = 'ScreenTwo',
Three = 'ScreenThree',
@emeraldsanto
emeraldsanto / make-navigator-custom.tsx
Last active September 4, 2021 03:48
Achieving type safe deep linking in React Native with react-navigation #5
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
emeraldsanto / make-navigator-basic.tsx
Created September 4, 2021 03:45
Achieving type safe deep linking in React Native with react-navigation #4
export const SomeStackConfiguration = makeNavigator({
name: 'SomeStack',
type: 'stack',
screens: {
[Screen.One]: { screen: ScreenOne },
[Screen.Two]: { screen: ScreenTwo },
[Screen.Three]: { screen: ScreenThree, options: { /* ... */ } },
// ...
},
linking: {
@emeraldsanto
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
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
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
import { NavigationContainer } from '@react-navigation/native';
const config = {
screens: {
Home: {
initialRouteName: 'Feed',
screens: {
Profile: 'users/:id',
Feed: 'feed',
},
@emeraldsanto
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
import { NavigationContainer } from '@react-navigation/native';
const linking = {
prefixes: ['https://mychat.com', 'mychat://'],
config: {
screens: {
Chat: 'feed/:sort',
Profile: 'user',
}
},