├── .babelrc ├── .flowconfig ├── .gitignore ├── .travis.yml ├── .watchmanconfig ├── App.js ├── App.test.js ├── LICENSE ├── README.md ├── app.json ├── package.json ├── src ├── assets │ └── app-icon.png ├── components │ ├── CustomHeader.js │ ├── MenuHeader.js │ ├── TodoItem.js │ └── Touch.js ├── index.js ├── models │ ├── count.js │ ├── index.js │ ├── todos.js │ └── zhihu.js ├── pages │ ├── AxiosPage.js │ ├── CounterPage.js │ ├── HomePage.js │ └── TodosPage.js ├── router.js ├── services │ └── zhihu-api.js └── utils │ └── Uploader.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["babel-preset-expo"], 3 | "env": { 4 | "development": { 5 | "plugins": ["transform-react-jsx-source"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | .*/Libraries/react-native/ReactNative.js 16 | 17 | ; Additional create-react-native-app ignores 18 | 19 | ; Ignore duplicate module providers 20 | .*/node_modules/fbemitter/lib/* 21 | 22 | ; Ignore misbehaving dev-dependencies 23 | .*/node_modules/xdl/build/* 24 | .*/node_modules/reqwest/tests/* 25 | 26 | ; Ignore missing expo-sdk dependencies (temporarily) 27 | ; https://github.com/expo/expo/issues/162 28 | .*/node_modules/expo/src/* 29 | 30 | ; Ignore react-native-fbads dependency of the expo sdk 31 | .*/node_modules/react-native-fbads/* 32 | 33 | [include] 34 | 35 | [libs] 36 | node_modules/react-native/Libraries/react-native/react-native-interface.js 37 | node_modules/react-native/flow 38 | flow/ 39 | 40 | [options] 41 | module.system=haste 42 | 43 | emoji=true 44 | 45 | experimental.strict_type_args=true 46 | 47 | munge_underscores=true 48 | 49 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 50 | 51 | suppress_type=$FlowIssue 52 | suppress_type=$FlowFixMe 53 | suppress_type=$FixMe 54 | 55 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-5]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\) 56 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-5]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)?:? #[0-9]+ 57 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 58 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 59 | 60 | unsafe.enable_getters_and_setters=true 61 | 62 | [version] 63 | ^0.45.0 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .expo/ 3 | npm-debug.* 4 | .idea/ 5 | yarn-error.log -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "stable" -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import App from './src'; 3 | import dva from 'dva/mobile'; 4 | import models from './src/models'; 5 | 6 | const app = dva(); 7 | models.map(m=>app.model(m)); 8 | app.router(() => ); 9 | 10 | export default app.start(); -------------------------------------------------------------------------------- /App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import App from './App'; 3 | 4 | import renderer from 'react-test-renderer'; 5 | 6 | it('renders without crashing', () => { 7 | const rendered = renderer.create().toJSON(); 8 | expect(rendered).toBeTruthy(); 9 | }); 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Zeven 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-starterkit 2 | 使用 [dva](https://github.com/dvajs/dva) + [nativebase](https://github.com/GeekyAnts/NativeBase) + [expo](https://github.com/expo/expo) 快速开发 ReactNative 脚手架 3 | 4 | ![build](https://travis-ci.org/ZevenFang/react-native-starterkit.svg?branch=master) 5 | 6 | ## Android preview 7 | 8 | 9 | ## iOS preview 10 | 11 | 12 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app). 13 | 14 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md). 15 | 16 | ## Table of Contents 17 | 18 | * [Updating to New Releases](#updating-to-new-releases) 19 | * [Available Scripts](#available-scripts) 20 | * [npm start](#npm-start) 21 | * [npm test](#npm-test) 22 | * [npm run ios](#npm-run-ios) 23 | * [npm run android](#npm-run-android) 24 | * [npm run eject](#npm-run-eject) 25 | * [Writing and Running Tests](#writing-and-running-tests) 26 | * [Environment Variables](#environment-variables) 27 | * [Configuring Packager IP Address](#configuring-packager-ip-address) 28 | * [Adding Flow](#adding-flow) 29 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon) 30 | * [Sharing and Deployment](#sharing-and-deployment) 31 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community) 32 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app) 33 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app) 34 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio) 35 | * [Should I Use ExpoKit?](#should-i-use-expokit) 36 | * [Troubleshooting](#troubleshooting) 37 | * [Networking](#networking) 38 | * [iOS Simulator won't open](#ios-simulator-wont-open) 39 | * [QR Code does not scan](#qr-code-does-not-scan) 40 | 41 | ## Updating to New Releases 42 | 43 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never. 44 | 45 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies. 46 | 47 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility. 48 | 49 | ## Available Scripts 50 | 51 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing. 52 | 53 | ### `npm start` 54 | 55 | Runs your app in development mode. 56 | 57 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal. 58 | 59 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script: 60 | 61 | ``` 62 | npm start -- --reset-cache 63 | # or 64 | yarn start -- --reset-cache 65 | ``` 66 | 67 | #### `npm test` 68 | 69 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests. 70 | 71 | #### `npm run ios` 72 | 73 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed. 74 | 75 | #### `npm run android` 76 | 77 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App: 78 | 79 | ##### Using Android Studio's `adb` 80 | 81 | 1. Make sure that you can run adb from your terminal. 82 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location). 83 | 84 | ##### Using Genymotion's `adb` 85 | 86 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`. 87 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)). 88 | 3. Make sure that you can run adb from your terminal. 89 | 90 | #### `npm run eject` 91 | 92 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project. 93 | 94 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up. 95 | 96 | ## Customizing App Display Name and Icon 97 | 98 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key. 99 | 100 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string. 101 | 102 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency. 103 | 104 | ## Writing and Running Tests 105 | 106 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/tree/master/react-native-scripts/template/__tests__) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/tutorial-react-native.html). 107 | 108 | ## Environment Variables 109 | 110 | You can configure some of Create React Native App's behavior using environment variables. 111 | 112 | ### Configuring Packager IP Address 113 | 114 | When starting your project, you'll see something like this for your project URL: 115 | 116 | ``` 117 | exp://192.168.0.2:19000 118 | ``` 119 | 120 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides. 121 | 122 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable: 123 | 124 | Mac and Linux: 125 | 126 | ``` 127 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start 128 | ``` 129 | 130 | Windows: 131 | ``` 132 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' 133 | npm start 134 | ``` 135 | 136 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`. 137 | 138 | ## Adding Flow 139 | 140 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept. 141 | 142 | React Native works with [Flow](http://flowtype.org/) out of the box, as long as your Flow version matches the one used in the version of React Native. 143 | 144 | To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps: 145 | 146 | 1. Find the Flow `[version]` at the bottom of the included [.flowconfig](.flowconfig) 147 | 2. Run `npm install --save-dev flow-bin@x.y.z` (or `yarn add --dev flow-bin@x.y.z`), where `x.y.z` is the .flowconfig version number. 148 | 3. Add `"flow": "flow"` to the `scripts` section of your `package.json`. 149 | 4. Add `// @flow` to any files you want to type check (for example, to `App.js`). 150 | 151 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors. 152 | You can optionally use a [plugin for your IDE or editor](https://flow.org/en/docs/editors/) for a better integrated experience. 153 | 154 | To learn more about Flow, check out [its documentation](https://flow.org/). 155 | 156 | ## Sharing and Deployment 157 | 158 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service. 159 | 160 | ### Publishing to Expo's React Native Community 161 | 162 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account. 163 | 164 | Install the `exp` command-line tool, and run the publish command: 165 | 166 | ``` 167 | $ npm i -g exp 168 | $ exp publish 169 | ``` 170 | 171 | ### Building an Expo "standalone" app 172 | 173 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself. 174 | 175 | ### Ejecting from Create React Native App 176 | 177 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio. 178 | 179 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html). 180 | 181 | #### Should I Use ExpoKit? 182 | 183 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option. 184 | 185 | ## Troubleshooting 186 | 187 | ### Networking 188 | 189 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports. 190 | 191 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see: 192 | 193 | ``` 194 | exp://192.168.0.1:19000 195 | ``` 196 | 197 | Try opening Safari or Chrome on your phone and loading 198 | 199 | ``` 200 | http://192.168.0.1:19000 201 | ``` 202 | 203 | and 204 | 205 | ``` 206 | http://192.168.0.1:19001 207 | ``` 208 | 209 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received. 210 | 211 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager. 212 | 213 | ### iOS Simulator won't open 214 | 215 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`: 216 | 217 | * "non-zero exit code: 107" 218 | * "You may need to install Xcode" but it is already installed 219 | * and others 220 | 221 | There are a few steps you may want to take to troubleshoot these kinds of errors: 222 | 223 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store. 224 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so. 225 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`. 226 | 227 | ### QR Code does not scan 228 | 229 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses. 230 | 231 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually. 232 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "expo": { 3 | "name": "React Native Starterkit", 4 | "icon": "https://s3.amazonaws.com/exp-us-standard/rnplay/app-icon.png", 5 | "description": "react-native-starterkit", 6 | "sdkVersion": "18.0.0", 7 | "ios": { 8 | "bundleIdentifier": "com.zeven.rnstarterkit" 9 | }, 10 | "android": { 11 | "package": "com.zeven.rnstarterkit" 12 | }, 13 | "androidStatusBar": { 14 | "barStyle": "light-content", 15 | "backgroundColor": "#3F51B5" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-starterkit", 3 | "version": "1.0.0", 4 | "private": true, 5 | "devDependencies": { 6 | "jest-expo": "~18.0.0", 7 | "react-native-scripts": "0.0.40", 8 | "react-test-renderer": "16.0.0-alpha.12" 9 | }, 10 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", 11 | "scripts": { 12 | "start": "react-native-scripts start", 13 | "eject": "react-native-scripts eject", 14 | "android": "react-native-scripts android", 15 | "ios": "react-native-scripts ios", 16 | "test": "node node_modules/jest/bin/jest.js" 17 | }, 18 | "jest": { 19 | "preset": "jest-expo", 20 | "transformIgnorePatterns": [ 21 | "/node_modules/(?!native-base)/" 22 | ] 23 | }, 24 | "dependencies": { 25 | "@expo/react-native-touchable-native-feedback-safe": "^1.1.2", 26 | "@expo/vector-icons": "^5.0.0", 27 | "axios": "^0.16.2", 28 | "dva": "^1.3.0-beta.3", 29 | "expo": "^18.0.3", 30 | "native-base": "^2.1.5", 31 | "react": "16.0.0-alpha.12", 32 | "react-native": "^0.45.1", 33 | "react-navigation": "^1.0.0-beta.11" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/assets/app-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZevenFang/react-native-expo-starterkit/d9091e49e5045e359ccbc2b1b9b3a403b6bc41d7/src/assets/app-icon.png -------------------------------------------------------------------------------- /src/components/CustomHeader.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {Header, Left, Body, Title, Right} from 'native-base'; 3 | 4 | class CustomHeader extends React.Component { 5 | 6 | render() { 7 | let {left, right, title, backgroundColor, color} = this.props; 8 | return ( 9 |
10 | 11 | {left} 12 | 13 | 14 | {title} 15 | 16 | 17 | {right} 18 | 19 |
20 | ) 21 | } 22 | 23 | } 24 | 25 | export default CustomHeader; -------------------------------------------------------------------------------- /src/components/MenuHeader.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {Button, Icon} from 'native-base'; 3 | import CustomHeader from './CustomHeader'; 4 | 5 | class MenuHeader extends React.Component { 6 | 7 | render() { 8 | let {title, right, navigation} = this.props; 9 | return ( 10 | navigation.navigate('DrawerOpen')}> 14 | 15 | 16 | } 17 | right={right} 18 | /> 19 | ) 20 | } 21 | 22 | } 23 | 24 | export default MenuHeader; -------------------------------------------------------------------------------- /src/components/TodoItem.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import {Alert} from 'react-native'; 3 | import {ListItem, CheckBox, Text, Icon, Right} from 'native-base'; 4 | 5 | class TodoItem extends Component { 6 | 7 | render() { 8 | let {index, completed, text, onPress, onDelete} = this.props; 9 | return ( 10 | onPress(index)} onLongPress={()=>{}}> 11 | onPress(index)} style={{backgroundColor: completed?'gray':'white', borderColor: 'gray'}} checked={completed} /> 12 | {text} 13 | 14 | Alert.alert( 15 | 'Delete', 16 | 'Are you sure?', 17 | [ 18 | {text: 'Cancel', style: 'cancel'}, 19 | {text: 'OK', onPress: () => onDelete(index)} 20 | ] 21 | )}/> 22 | 23 | 24 | ); 25 | } 26 | 27 | } 28 | 29 | export default TodoItem; -------------------------------------------------------------------------------- /src/components/Touch.js: -------------------------------------------------------------------------------- 1 | import TouchableNativeFeedbackSafe from '@expo/react-native-touchable-native-feedback-safe'; 2 | export default TouchableNativeFeedbackSafe; -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Expo, {AppLoading} from 'expo'; 3 | import { DrawerNavigator } from 'react-navigation'; 4 | import './pages/HomePage'; 5 | import router from './router'; 6 | 7 | const Drawer = DrawerNavigator( 8 | router, 9 | { 10 | initialRouteName: 'Home', 11 | contentOptions: { 12 | activeTintColor: 'cadetblue', 13 | }, 14 | } 15 | ); 16 | 17 | class App extends React.Component { 18 | 19 | state = { 20 | isReady: false 21 | }; 22 | 23 | async componentWillMount() { 24 | await Expo.Font.loadAsync({ 25 | 'Roboto': require('native-base/Fonts/Roboto.ttf'), 26 | 'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'), 27 | }); 28 | this.setState({isReady: true}); 29 | } 30 | 31 | render(){ 32 | if (!this.state.isReady) { 33 | return ; 34 | } 35 | return( 36 | 37 | ) 38 | } 39 | 40 | } 41 | 42 | export default App; 43 | -------------------------------------------------------------------------------- /src/models/count.js: -------------------------------------------------------------------------------- 1 | function delay(timeout) { 2 | return new Promise(resolve => { 3 | setTimeout(resolve, timeout); 4 | }); 5 | } 6 | 7 | export default { 8 | namespace: 'count', 9 | state: 0, 10 | reducers: { 11 | add(state) { return state + 1 }, 12 | }, 13 | effects: { 14 | *addDelay(action, { call, put }) { 15 | yield call(delay, 1000); 16 | yield put({ type: 'add' }); 17 | }, 18 | }, 19 | subscriptions: { 20 | setup({ dispatch }) { 21 | dispatch({type: 'add'}); 22 | }, 23 | }, 24 | } -------------------------------------------------------------------------------- /src/models/index.js: -------------------------------------------------------------------------------- 1 | import count from './count'; 2 | import todos from './todos'; 3 | import zhihu from './zhihu'; 4 | 5 | export default [count, todos, zhihu]; -------------------------------------------------------------------------------- /src/models/todos.js: -------------------------------------------------------------------------------- 1 | export default { 2 | namespace: 'todos', 3 | state: { 4 | list: [ 5 | {text: 'hello', completed: false}, 6 | {text: 'world', completed: true}, 7 | {text: 'react', completed: false}, 8 | {text: 'native', completed: true} 9 | ] 10 | }, 11 | reducers: { 12 | add(state, {text}){ 13 | state.list.push({text, completed: false}); 14 | return {...state}; 15 | }, 16 | del(state, {index}){ 17 | state.list.splice(index,1); 18 | return {...state}; 19 | }, 20 | upd(state, {index, text}){ 21 | state.list[index].text = text; 22 | return {...state}; 23 | }, 24 | check(state, {index}){ 25 | state.list[index].completed = !state.list[index].completed; 26 | return {...state}; 27 | }, 28 | clearCompleted(state){ 29 | state.list = state.list.filter(v=>!v.completed); 30 | return {...state} 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/models/zhihu.js: -------------------------------------------------------------------------------- 1 | import {getLatest} from '../services/zhihu-api'; 2 | import {Toast} from 'native-base'; 3 | 4 | export default { 5 | namespace: 'zhihu', 6 | state: { 7 | data: [] 8 | }, 9 | reducers: { 10 | setLatest(state, {data}){ 11 | state.data = data.stories; 12 | return {...state}; 13 | } 14 | }, 15 | effects: { 16 | *getLatest(action, {put, call}){ 17 | try { 18 | let {data} = yield call(getLatest); 19 | yield put({ 20 | type: 'setLatest', data 21 | }); 22 | } catch (err) { 23 | Toast.show({ 24 | text: 'Network error', 25 | position: 'bottom', 26 | buttonText: 'Okay' 27 | }) 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/pages/AxiosPage.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {Container, Content, List, ListItem, Thumbnail, Body, Text, Spinner} from 'native-base'; 3 | import MenuHeader from '../components/MenuHeader'; 4 | import {connect} from 'dva/mobile'; 5 | 6 | class AxiosPage extends React.Component { 7 | 8 | constructor(props) { 9 | super(props); 10 | props.dispatch({ 11 | type: 'zhihu/getLatest' 12 | }) 13 | } 14 | 15 | render() { 16 | let {zhihu} = this.props; 17 | return ( 18 | 19 | 20 | 21 | {zhihu.data.length===0?: 22 | 23 | {zhihu.data.map((v,k)=>( 24 | 25 | 26 | 27 | {v.title} 28 | 29 | 30 | ))} 31 | 32 | } 33 | 34 | 35 | ) 36 | } 37 | 38 | } 39 | 40 | const styles = { 41 | container: { 42 | flex: 1, 43 | justifyContent: 'center' 44 | }, 45 | }; 46 | 47 | export default connect(({zhihu})=>({zhihu}))(AxiosPage); -------------------------------------------------------------------------------- /src/pages/CounterPage.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { Container, Content, Text, View } from 'native-base'; 3 | import Touch from '../components/Touch'; 4 | import MenuHeader from '../components/MenuHeader'; 5 | import {connect} from 'dva/mobile'; 6 | 7 | class CounterPage extends Component { 8 | 9 | render() { 10 | let {count, dispatch} = this.props; 11 | return ( 12 | 13 | 14 | 15 | 16 | 17 | Count: { count } 18 | 19 | { dispatch({ type: 'count/add' }) }}> 20 | Add 21 | 22 | { dispatch({ type: 'count/addDelay' }) }}> 23 | Delay Add 24 | 25 | 26 | 27 | 28 | ); 29 | } 30 | } 31 | 32 | const styles = { 33 | container: { 34 | flex: 1, 35 | justifyContent: 'center' 36 | }, 37 | }; 38 | 39 | export default connect(({ count }) => ({ count }))(CounterPage); -------------------------------------------------------------------------------- /src/pages/HomePage.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {View, Text, Thumbnail, Container, Content, Button, Icon} from 'native-base'; 3 | import MenuHeader from '../components/MenuHeader'; 4 | 5 | class HomePage extends React.Component { 6 | 7 | render() { 8 | return ( 9 | 10 | 11 | 12 | 13 | 14 | Click on the upper left corner to navigate. 15 | 16 | 17 | 18 | ); 19 | } 20 | } 21 | 22 | const styles = { 23 | container: { 24 | flex: 1, 25 | justifyContent: 'center', 26 | alignItems: 'center' 27 | } 28 | }; 29 | 30 | export default HomePage; -------------------------------------------------------------------------------- /src/pages/TodosPage.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {Platform} from 'react-native'; 3 | import {Container, Content, Text, Icon, Header, Input, Item, View} from 'native-base'; 4 | import {TabNavigator} from 'react-navigation'; 5 | import {connect} from 'dva/mobile'; 6 | import TodoItem from '../components/TodoItem'; 7 | import Touch from '../components/Touch'; 8 | import MenuHeader from '../components/MenuHeader'; 9 | 10 | const TodosNav = TabNavigator({ 11 | All: { 12 | screen: ()=> 13 | }, 14 | Active: { 15 | screen: ()=> 16 | }, 17 | Completed: { 18 | screen: ()=> 19 | } 20 | }, { 21 | tabBarOptions: { 22 | labelStyle: Platform.OS==='ios'? {fontSize: 15, top: -15}:{}, 23 | style: Platform.OS==='android'?{backgroundColor: '#3F51B5'}:{} 24 | }, 25 | tabBarPosition: 'bottom', 26 | animationEnabled: true, 27 | swipeEnabled: true, 28 | }); 29 | 30 | class TodosPage extends React.Component { 31 | 32 | state = { 33 | text: '' 34 | }; 35 | 36 | addTask = () => { 37 | let {dispatch} = this.props; 38 | let {text} = this.state; 39 | if (text.trim().length===0) return; 40 | dispatch({ 41 | type: 'todos/add', 42 | text 43 | }); 44 | this.setState({text: ''}); 45 | }; 46 | 47 | render() { 48 | return ( 49 | 50 | }/> 51 |
52 | 53 | 54 | this.setState({text})} 57 | value={this.state.text}/> 58 | 59 | 60 |
61 | 62 |
63 | ) 64 | } 65 | 66 | } 67 | 68 | @connect(({todos})=>({todos})) 69 | class TodosList extends React.Component { 70 | 71 | delTask = (index) => { 72 | let {dispatch} = this.props; 73 | dispatch({ 74 | type: 'todos/del', 75 | index 76 | }); 77 | }; 78 | 79 | check = (index) => { 80 | let {dispatch} = this.props; 81 | dispatch({ 82 | type: 'todos/check', 83 | index 84 | }) 85 | }; 86 | 87 | render() { 88 | let {todos, type} = this.props; 89 | let list = todos.list.map((v,k) => ({...v, index: k})); 90 | if (type=='active') list = list.filter(v => !v.completed); 91 | else if (type=='completed') list = list.filter(v => v.completed); 92 | return ( 93 | 94 | {list.length>0?list.map((v,k)=>( 95 | 96 | )):There is no task here.} 97 | 98 | ) 99 | } 100 | 101 | } 102 | 103 | @connect() 104 | class ClearButton extends React.Component { 105 | render() { 106 | return ( 107 | {this.props.dispatch({type: 'todos/clearCompleted'})}}> 108 | Clear 109 | 110 | ) 111 | } 112 | } 113 | 114 | export default connect(({todos})=>({todos}))(TodosPage); -------------------------------------------------------------------------------- /src/router.js: -------------------------------------------------------------------------------- 1 | import HomePage from './pages/HomePage' 2 | import CounterPage from './pages/CounterPage' 3 | import TodosPage from './pages/TodosPage' 4 | import AxiosPage from './pages/AxiosPage' 5 | 6 | export default { 7 | Home: { 8 | path: '/', 9 | screen: HomePage, 10 | }, 11 | Counter: { 12 | path: '/counter', 13 | screen: CounterPage, 14 | }, 15 | Todos: { 16 | path: '/todos', 17 | screen: TodosPage, 18 | }, 19 | Axios: { 20 | path: '/axios', 21 | screen: AxiosPage, 22 | }, 23 | }; -------------------------------------------------------------------------------- /src/services/zhihu-api.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | let host = 'https://news-at.zhihu.com/api/4'; 3 | 4 | export function getLatest() { 5 | return axios.get(host+'/news/latest') 6 | } -------------------------------------------------------------------------------- /src/utils/Uploader.js: -------------------------------------------------------------------------------- 1 | class Qiniu { 2 | 3 | static crop(img, crop){ 4 | if (!crop.x) crop.x=0; 5 | if (!crop.y) crop.y=0; 6 | return img+`?imageMogr2/crop/!${crop.width}x${crop.height}${crop.x<0?crop.x:'a'+crop.x}${crop.y<0?crop.y:'a'+crop.y}`; 7 | } 8 | 9 | static center(img, w, h){ 10 | return h?img+`?imageMogr2/1/w/${w}/h/${h}`:img+`?imageMogr2/1/w/${w}/`; 11 | } 12 | 13 | } 14 | 15 | export default Uploader; 16 | --------------------------------------------------------------------------------