Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzitelli committed Jan 11, 2022
1 parent eb1fec1 commit 7556617
Showing 1 changed file with 73 additions and 37 deletions.
110 changes: 73 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,119 @@
<p align="center">
<img src="https://xxx-files.ggc.team/oss/rnn-screens/rnn-screens-logo.png" width="80%" title="Logo">
<img src="https://xxx-files.ggc.team/oss/rnn-screens/cover.png" width="80%" title="Logo">
</p>

Purpose of [RNN Screens](https://github.com/kanzitelli/rnn-screens) is to simplify and accelerate the process of React Native App development with [React Native Navigation](https://github.com/wix/react-native-navigation). It is not a replacement for RNN but a good addition!
## Goal

The goal of [RNN Screens](https://github.com/kanzitelli/rnn-screens) is to provide React Native developers with more simplified and predictable way of Navigation. It's build on top of [React Native Navigation](https://github.com/wix/react-native-navigation).

☣️ `Experiment`. This library is an experiment and may have breaking changes in the future.

## Quick start

Make sure you have [react-native-navigation](https://github.com/wix/react-native-navigation) installed in your project.

#### 1. Install RNN Screens

```
> yarn add rnn-screens
```

#### 2. Install and link [React Native Navigation](https://github.com/wix/react-native-navigation)

```
yarn add rnn-screens
> yarn add react-native-navigation
> npx rnn-link
```

#### 3. Install pods

```
> npx pod-install
```

If you had problems installing RNN, please follow more [detailed tutorial](https://wix.github.io/react-native-navigation/docs/installing)

## Usage

### 1. Describe app's screens
#### 1. Update `index.js`

```tsx
import {registerRootComponent} from 'rnn-screens';
import App from './App';

registerRootComponent(App);
```

#### 2. Build components (ex., in `App.tsx`)

```tsx
import {generateRNNScreens, Root, Screen, ScreenComponent} from 'rnn-screens';

const Main: ScreenComponent = ({componentId}) => {
return <>...</>;
};

type SettingsProps = {
type: 'push' | 'show';
};
const Settings: ScreenComponent<SettingsProps> = ({componentId, type}) => {
return <>...</>;
};
```

#### 3. Describe screens

```tsx
import {generateRNNScreens, Root, Stack, Component, BottomTabs} from 'rnn-screens';

export const screens = generateRNNScreens({
const screens = generateRNNScreens({
Main: {
component: Main,
options: {
topBar: {
title: {
text: 'Home',
},
},
topBar: {title: {text: 'Home'}},
},
},
Settings: {
component: Settings,
options: {
topBar: {
title: {
text: 'Settings',
},
},
topBar: {title: {text: 'Settings'}},
},
},
});
```

### 2. Set app's navigation root
#### 4. Build `App` component

```tsx
// One screen app
screens.N.setRoot(Root(Stack(Component(screens.get('Main')))));

// Tab based app
screens.N.setRoot(
Root(
BottomTabs([
Stack(Component(screens.get('Main'))),
Stack(Component(screens.get('Settings'))),
]),
),
);
const App = () => Root(Screen(screens.get('Main')));
```

### 3. Navigate with predictability
#### 5. Navigate with predictability

```tsx
// push screen
screens.push(componentId, 'Example');
screens.push(componentId, 'Settings');

// show modal
screens.show('Example');
screens.show('Settings');

// push screen with passProps
screens.push<ExampleScreenProps>(
componentId,
'Example',
{ value: randomNum() },
)
screens.push<SettingsProps>(componentId, 'Settings', {type: 'push'});

// use RNN Navigation instance
screens.N.dismissAllModals();
```

An integration example could be found at [kanzitelli/rnn-starter](https://github.com/kanzitelli/rnn-starter).
A simple example of RNN Screens integration is located under `example/` folder.

If you'd like to see more advanced example with translation service and other stuff, check out [kanzitelli/rnn-starter](https://github.com/kanzitelli/rnn-starter).

## Enhancements

- [ ] Better documentation
- [ ] Build an OSS React Native app with RNN Screens.

Feel free to open an issue for suggestions.

## Credits

Expand Down

0 comments on commit 7556617

Please sign in to comment.