All Projects → horiuchie → react-native-dva-starter-with-builtin-router

horiuchie / react-native-dva-starter-with-builtin-router

Licence: other
Integrate dva into react-native app with builtin router of dva.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-native-dva-starter-with-builtin-router

umi-react-native
umi preset plugins for react-native
Stars: ✭ 54 (+217.65%)
Mutual labels:  dva, expo
react-native-collapsible-segmented-view
A cross-platform Collapsible Segmented View component for React Native
Stars: ✭ 37 (+117.65%)
Mutual labels:  expo
app-intro-lottie-expo
App Intro component with Expo, styled-components and Lottie
Stars: ✭ 46 (+170.59%)
Mutual labels:  expo
react-native-news-app
Get breaking news headlines with short description filtered by your interests and country preferences
Stars: ✭ 75 (+341.18%)
Mutual labels:  expo
maker
Maker is a advanced mobile ToDo app for Android and iOS
Stars: ✭ 35 (+105.88%)
Mutual labels:  expo
status-bar-height
Listen to status bar changes during incoming calls and other multi-tasking events
Stars: ✭ 73 (+329.41%)
Mutual labels:  expo
react-native-expo-web
All-in-one React Native project (Expo + react-native-web)
Stars: ✭ 16 (-5.88%)
Mutual labels:  expo
nodejs-starter-kit
A Universal Javascript Starter Kit to satisify all you Web / App needs!
Stars: ✭ 23 (+35.29%)
Mutual labels:  expo
react-native-msal
MSAL for React Native
Stars: ✭ 62 (+264.71%)
Mutual labels:  expo
taro-template
可用于生产环境的taro项目模版,技术栈:taro + taro-ui + typescript + dva / mobx + sass,无需过多关注项目配置,预置功能包括但不限于页面/组件/store/service模版一键生成/编译自动生成路由列表和组件入口/代码规范强制检查/请求拦截封装/小程序CI等,实现多端项目的高效快速开发。目前已有1.x / 2.x / 3.x 版本。
Stars: ✭ 59 (+247.06%)
Mutual labels:  dva
expo-ui-kit
expo-ui-kit - a components based React-Native UI Kit
Stars: ✭ 88 (+417.65%)
Mutual labels:  expo
smovie-expo
[New] New version with more examples: https://github.com/theo-mesnil/WhatToWatch [Old version] Smovie is the simplest and fastest way to discover movies, series and actors. With React Native, Expo and themoviedb 🎥
Stars: ✭ 19 (+11.76%)
Mutual labels:  expo
RN-Book-Search
A Book search app using Expo (React Native) and Google Books API
Stars: ✭ 29 (+70.59%)
Mutual labels:  expo
react-mobile
从0构建 react 移动端框架,包含 分模块打包,自动转为rem,强大的路由功能,并配置dva,and-mobile等优质组件(项目会逐渐迭代~)
Stars: ✭ 30 (+76.47%)
Mutual labels:  dva
Expo-Nitro-Roll
A cross-platform video game built with Expo and three.js!
Stars: ✭ 16 (-5.88%)
Mutual labels:  expo
rn-mirror-lists
🪞 Mirror scroll lists for React Native
Stars: ✭ 38 (+123.53%)
Mutual labels:  expo
expo-doodle-jump
No description or website provided.
Stars: ✭ 44 (+158.82%)
Mutual labels:  expo
DRIP
Fixed Income Analytics, Portfolio Construction Analytics, Transaction Cost Analytics, Counter Party Analytics, Asset Backed Analytics
Stars: ✭ 44 (+158.82%)
Mutual labels:  dva
blog
✍️无他术,唯勤读书而多为之,自工。
Stars: ✭ 62 (+264.71%)
Mutual labels:  dva
config-plugins
Out-of-tree Expo config plugins for packages that haven't adopted the config plugin system yet.
Stars: ✭ 180 (+958.82%)
Mutual labels:  expo

react-native-dva-starter-with-builtin-router

This example shows a way to integrate dva into react-native app with builtin router of dva.
Since you don't need a router designed for react-native, this approach allows you to code any native app with dva just like web app.

Try it at https://expo.io/@horiuchie/react-native-dva-starter-with-builtin-router.

How to integrate

  1. yarn global add expo-cli if you have not installed yet.
  2. expo init {project-name} then choose blank.
  3. cd {project-name}.
  4. yarn add dva dva-loading react-dom.
  5. replace App.js with the following:
import React from 'react';
import dva, { connect } from 'dva';
import createLoading from 'dva-loading';
import { Router, Route, Switch, routerRedux } from 'dva/router';
import { View, Text, TouchableOpacity, ActivityIndicator } from 'react-native';
import { createMemoryHistory } from 'history';

const delay = time => new Promise(resolve => setTimeout(resolve, time));

const app = dva({
  ...createLoading(),
  history: createMemoryHistory(),  // Trick !!
  initialState: {}
});

app.model({
  namespace: 'user',
  state: {},
  reducers: {},
  effects: {
    *login ( action, { put, call } ) {
      yield call(delay, 1000);
      yield put(routerRedux.push({ pathname: '/home' }));
    }
  },
  subscriptions: {
    // You can use history object in subscriptions.
    setup({ history, dispatch }) {
      history.listen(({ pathname }) => {
        if (pathname === '/home') { alert('logged in'); }
      });
    }
  }
});

const LoginPage = connect(({ loading }) => ({ loading }))(({ dispatch, loading: { effects } }) => {
  return (
    <View style={{ flex: 1, flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
      {
        effects['user/login']
        ? <ActivityIndicator />
        : <TouchableOpacity onPress={() => dispatch({ type: 'user/login' })}>
            <Text style={{ fontSize: 24 }}>Login</Text>
          </TouchableOpacity>
      }
    </View>
  );
});

const HomePage = () => {
  return (
    <View style={{ flex: 1, flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
      <Text style={{ fontSize: 24 }}>Welcome</Text>
    </View>
  );
};

app.router(({ history }) => (
  <Router history={history}>
    <Switch>
      <Route path="/" exact component={LoginPage} />
      <Route path="/home" exact component={HomePage} />
    </Switch>
  </Router>
));

const App = app.start();

export default App;
  1. expo start. If your project on other networks, run expo start --tunnnel.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].