项目作者: dooboolab

项目描述 :
react-native javascript boilerplate with flow
高级语言: JavaScript
项目地址: git://github.com/dooboolab/dooboo-native-js.git
创建时间: 2018-07-01T15:06:42Z
项目社区:https://github.com/dooboolab/dooboo-native-js

开源协议:MIT License

下载


Deprecated

This boilperlate is currently deprecated since dooboo-cli started to focus on typescript projects from 2.0.0. This can live again when game changes but currently deprecated.

React Native JS Boilerplate

codecov
CircleCI Greenkeeper badge

Specification

Gain points

  1. 1. Sample of context-api with `react-hook` (`useContext`).
  2. 2. Know how to structure react native app with flow.
  3. 3. Know how to navigate between screens with `react-navigation`.
  4. 4. Know how to write test code with `react-native-testing-library`.
  5. 5. Know how to `lint` your project with `eslint`.
  6. 6. Know how to localize your project.

INSTALL

  1. npm install && npm start
  2. // or
  3. yarn && yarn start

Structures

  1. app/
  2. ├─ .doobooo // necessary if using dooboo-cli
  3. ├─ assets
  4. └─ icons // app icons
  5. └─ images // app images like background images
  6. ├─ node_modules/
  7. ├─ src/
  8. └─ apis
  9. └─ components
  10. └─ navigations
  11. └─ screen
  12. └─ shared
  13. └─ contexts
  14. └─ utils
  15. └─ App.js
  16. ├─ test/
  17. ├─ .buckconfig
  18. ├─ .eslintignore
  19. ├─ .eslintrc.js
  20. ├─ .flowconfig
  21. ├─ .gitattributes
  22. ├─ .gitignore
  23. ├─ .watchmanconfig
  24. ├─ app.json
  25. ├─ babel.config.js
  26. ├─ index.js
  27. ├─ jest.config.js
  28. ├─ package.json
  29. ├─ README.md
  30. └─ STRINGS.js

Running the project

Running the project is as simple as running

  1. npm run start

This runs the start script specified in our package.json, and will spawn off a server which reloads the page as we save our files.
Typically the server runs at http://localhost:8080, but should be automatically opened for you.

Testing the project

Testing is also just a command away:

  1. npm test
  2. > jest -u
  3. PASS src/components/screen/__tests__/NotFound.test.js
  4. Console
  5. console.log src/utils/Styles.js:6
  6. calRatio: 8.995502248875562
  7. console.log src/utils/Styles.js:20
  8. calRatio: 83.33333333333333
  9. console.log src/utils/Styles.js:25
  10. ratio: 2.083333333333333
  11. PASS lib/components/screen/__tests__/NotFound.test.js
  12. Console
  13. console.log lib/utils/Styles.js:1
  14. calRatio: 8.995502248875562
  15. console.log lib/utils/Styles.js:1
  16. calRatio: 83.33333333333333
  17. console.log lib/utils/Styles.js:1
  18. ratio: 2.083333333333333
  19. 2 snapshots written.
  20. PASS lib/components/screen/__tests__/Home.test.js
  21. 2 snapshots written.
  22. PASS src/components/shared/__tests__/Button.test.js
  23. Console
  24. console.log src/utils/Styles.js:6
  25. calRatio: 8.995502248875562
  26. console.log src/utils/Styles.js:20
  27. calRatio: 83.33333333333333
  28. console.log src/utils/Styles.js:25
  29. ratio: 2.083333333333333
  30. 4 snapshots updated.
  31. PASS lib/components/shared/__tests__/Button.test.js
  32. Console
  33. console.log lib/utils/Styles.js:1
  34. calRatio: 8.995502248875562
  35. console.log lib/utils/Styles.js:1
  36. calRatio: 83.33333333333333
  37. console.log lib/utils/Styles.js:1
  38. ratio: 2.083333333333333
  39. 4 snapshots written.
  40. PASS src/components/screen/__tests__/Intro.test.js
  41. Console
  42. console.log src/utils/Styles.js:6
  43. calRatio: 8.995502248875562
  44. console.log src/utils/Styles.js:20
  45. calRatio: 83.33333333333333
  46. console.log src/utils/Styles.js:25
  47. ratio: 2.083333333333333
  48. 1 snapshot updated.
  49. Snapshot Summary
  50. 8 snapshots written from 3 test suites.
  51. 5 snapshots updated from 2 test suites.
  52. Test Suites: 6 passed, 6 total
  53. Tests: 14 passed, 14 total
  54. Snapshots: 5 updated, 8 written, 3 passed, 16 total
  55. Time: 5.251s
  56. Ran all test suites.

Writing tests with Jest

We’ve created test examples with jest-ts in src/components/screen/__tests__ and src/components/shared/__tests__. Since react is component oriented, we’ve designed to focus on writing test in same level of directory with component. You can simply run npm test to test if it succeeds and look more closer opening the source.

Localization

We’ve defined Localization strings in STRINGS.js which is in root dir.
We used react-native-localization pacakage for this one.

  1. import LocalizedStrings from 'react-native-localization';
  2. const strings = new LocalizedStrings({
  3. en: {
  4. LOGIN: 'Login',
  5. },
  6. kr: {
  7. LOGIN: '로그인',
  8. },
  9. });
  10. export {
  11. strings,
  12. };

Fixed jest setup by adding following in jestSetup.

  1. import { NativeModules } from 'react-native';
  2. /**
  3. * monkey patching the locale to avoid the error:
  4. * Something went wrong initializing the native ReactLocalization module
  5. * https://gist.github.com/MoOx/08b465c3eac9e36e683929532472d1e0
  6. */
  7. NativeModules.ReactLocalization = {
  8. language: 'en_US',
  9. };

React version

16.6.3

React Native version

0.58

React navigation

3