5.4.0 • Published 1 month ago

@gasbuddy/react-navigation-codegen v5.4.0

Weekly downloads
88
License
MIT
Repository
github
Last release
1 month ago

react-navigation-codegen

Node CI

A simple code generator to turn somewhat abstract specifications into TypeScript code with information about your full navigation stack in a React Navigation based app. This avoids lots of magic strings in your code, gives you a sense of the actual navigation structure, and avoids repeating yourself in code as much as usual.

Input can be YAML, JS, JSON, or Typescript. Consider a typical navigation setup:

type RootStackParamList = {
  Home: undefined;
  Profile: { userId: string };
  Feed: { sort: 'latest' | 'top' } | undefined;
};

const RootStack = createStackNavigator<RootStackParamList>();

<RootStack.Navigator initialRouteName="Home">
  <RootStack.Screen name="Home" component={Home} />
  <RootStack.Screen
    name="Profile"
    component={Profile}
    initialParams={{ userId: user.id }}
  />
  <RootStack.Screen name="Feed" component={Feed} />
</RootStack.Navigator>

With this module, you would specify as follows:

export default {
  screens: {
    Root: {
      parameterListType: 'RootStackParamList',
      screens: {
        Home: {},
        Profile: {
          parameterType: '{ userId: string }',
        },
        Feed: {
          parameterType: '{ sort: 'latest' | 'top' } | undefined',
        }
      }
    }
  }
}

And now your code becomes:

const RootStack = createStackNavigator<RootStackParamList>();

<RootStack.Navigator initialRouteName="Home">
  <RootStack.Screen name={Nav.Root.Home} component={Home} />
  <RootStack.Screen
    name={Nav.Root.Profile}
    component={Profile}
    initialParams={{ userId: user.id }}
  />
  <RootStack.Screen name={Nav.Root.Feed} component={Feed} />
</RootStack.Navigator>

Perhaps not a massive improvement in the simple example, but as you scale, it gets harder to manage all the types, related types and constants for every navigator, AND you lose a notion of the structure of the navigation tree.

5.4.0

1 month ago

5.3.0

3 months ago

5.2.0

3 months ago

5.1.4

12 months ago

5.1.3

12 months ago

5.1.2

12 months ago

5.1.1

1 year ago

5.1.0

1 year ago

5.0.0

1 year ago

4.1.0

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

4.2.0

1 year ago

4.1.1

1 year ago

3.3.0

3 years ago

3.2.0

3 years ago

3.1.1

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago