Files
notesnook/apps/mobile/README.md

166 lines
5.6 KiB
Markdown
Raw Permalink Normal View History

2022-08-31 19:04:38 +05:00
<p align="center">
<img style="align:center; border-radius: 20px;" src="/resources/screenshots/mobile.jpg" alt="Notesnook mobile screenshot" width="250" />
</p>
2022-08-16 16:48:10 +05:00
2022-08-31 19:04:38 +05:00
<h1 align="center">Notesnook Mobile</h1>
<h3 align="center">The mobile app is built using React Native, Typescript & Javascript for both iOS & Android.</h3>
<p align="center">
<a href="#developer-guide">Developer guide</a> | <a href="#build-instructions">How to build?</a>
</p>
2022-08-16 16:48:10 +05:00
2022-08-31 19:04:38 +05:00
<p align="center">
<a href="https://play.google.com/store/apps/details?id=com.streetwriters.notesnook">
<img alt="Download on Google Play" src="https://play.google.com/intl/en_us/badges/images/badge_new.png" height=43>
</a>
<a href="https://apps.apple.com/us/app/notesnook-take-private-notes/id1544027013">
<img alt="Download on App Store" src="https://user-images.githubusercontent.com/7317008/43209852-4ca39622-904b-11e8-8ce1-cdc3aee76ae9.png" height=43>
</a>
</p>
2022-08-16 16:48:10 +05:00
2022-08-31 19:04:38 +05:00
## Build instructions
2022-08-16 16:48:10 +05:00
> **Before you start, it is recommended that you read [the contributing guidelines](/CONTRIBUTING.md).**
2022-08-16 16:48:10 +05:00
### Setting up the development environment
2022-08-16 16:48:10 +05:00
2022-08-31 19:04:38 +05:00
Requirements:
2022-08-16 16:48:10 +05:00
2022-08-31 19:04:38 +05:00
1. [Node.js](https://nodejs.org/en/download/)
2. [git](https://git-scm.com/downloads)
3. NPM (not yarn or pnpm)
4. [React Native](https://reactnative.dev/docs/environment-setup)
2022-08-16 16:48:10 +05:00
2022-08-31 19:04:38 +05:00
To run the app locally, you will need to setup React Native on your system:
2022-08-16 16:48:10 +05:00
2022-08-31 19:04:38 +05:00
1. Open the official [environment setup guide here](https://reactnative.dev/docs/environment-setup)
2. Select `React Native CLI Quickstart`
3. Select your OS & the platform to run the app on (iOS or Android)
4. Follow the steps listed.
2022-08-16 16:48:10 +05:00
2022-08-31 19:04:38 +05:00
> Please keep in mind that **Expo is not supported**.
2022-08-16 16:48:10 +05:00
2022-08-31 19:04:38 +05:00
Once you have completed the setup, the first step is to `clone` the monorepo:
2022-08-17 13:16:59 +05:00
2022-08-31 19:04:38 +05:00
```bash
git clone https://github.com/streetwriters/notesnook.git
2022-08-17 13:16:59 +05:00
2022-08-31 19:04:38 +05:00
# change directory
cd notesnook
```
2022-08-17 13:16:59 +05:00
2022-08-31 19:04:38 +05:00
Once you are inside the `./notesnook` directory, run the preparation step:
2022-08-17 13:16:59 +05:00
```bash
2022-08-31 19:04:38 +05:00
# this might take a while to complete
npm install
2022-08-17 13:16:59 +05:00
```
2022-08-31 19:04:38 +05:00
### Running the app on Android
[Setup an Android emulator from Android Studio](https://developer.android.com/studio/run/managing-avds) if you haven't already, and then run the following command to start the app in the Emulator:
2022-08-17 13:16:59 +05:00
```bash
2022-08-31 19:04:38 +05:00
npm run start:android
2022-08-17 13:16:59 +05:00
```
2022-08-31 19:04:38 +05:00
If you want to run the app on your phone, make sure to [enable USB debugging](https://developer.android.com/studio/debug/dev-options).
2022-08-17 13:16:59 +05:00
2022-08-31 19:04:38 +05:00
### Running the app on iOS
2022-08-17 13:16:59 +05:00
2022-08-31 19:04:38 +05:00
To run the app on iOS:
2022-08-17 13:16:59 +05:00
```bash
2022-08-31 19:04:38 +05:00
# this might take a while to complete
npm run prepare:ios
npm run start:ios
2022-08-17 13:16:59 +05:00
```
2022-08-31 19:04:38 +05:00
## Developer guide
2022-08-17 13:16:59 +05:00
> This project is in a transition state between Javascript & Typescript. We are gradually porting everything over to Typescript, so if you can help with that, it'd be great!
2022-08-17 15:59:59 +05:00
2022-08-31 19:04:38 +05:00
### The tech stack
2022-08-17 15:59:59 +05:00
We try to keep the stack as lean as possible:
2022-08-17 13:16:59 +05:00
2022-08-31 19:04:38 +05:00
1. React Native
2. Typescript/Javascript
3. Zustand: State management
4. Detox: Runs all our e2e tests
5. React Native MMKV: Database & persistence
6. libsodium: Encryption
2022-08-17 13:16:59 +05:00
2022-08-31 19:04:38 +05:00
### Project structure
2022-08-17 13:16:59 +05:00
2022-08-31 19:04:38 +05:00
The app codebase is distributed over two primary directories. `native/` and `app/`.
2022-08-17 13:16:59 +05:00
- `native/`: Includes `android/` and `ios/` folders and everything related to react native core functionality like bundling, development, and packaging. Any react-native dependency with native code, i.e., android & ios folders, is installed here.
2022-08-17 15:59:59 +05:00
- `app/`: Includes all the app code other than the native part. All JS-only dependencies are installed here.
- `components/`: Each component serves a specific purpose in the app UI. For example, the `Paragraph` component is used to render paragraphs in the app, and a `Header` component is used to render a `header` on all screens.
- `common/`: Features that are integral to the app's functionality. For example, the notesnook core is initialized here.
2022-08-31 19:04:38 +05:00
- `hooks/`: Hooks for different app logic
- `navigation/`: Includes app navigation-specific code. Here the app navigation, editor & side menu are rendered side by side in fluid tabs.
2022-08-31 19:04:38 +05:00
- `screens`: Navigator screens.
- `services`: Parts of code that do a specific function. For example, the `sync` service runs Sync from anywhere in the app.
- `stores`: We use `zustand` for global state management in the app. Multiple stores provide the state for different parts of the app.
- `utils`: General purpose stuff such as constant values, utility functions, etc.
2022-08-17 15:59:59 +05:00
2022-08-31 19:04:38 +05:00
There are several other folders at the root:
2022-08-17 13:16:59 +05:00
2022-08-31 19:04:38 +05:00
- `share/`: Code for the iOS Share Extension and Android widget.
- `e2e/`: Detox End to end tests
- `patches/`: Patches for various react native dependencies.
### Running the tests
When you are done making the required changes, you must run the tests to ensure you didn't break anything. We use Detox as the testing framework & the tests can be started as follows:
2022-09-01 15:43:24 +05:00
### Android
To run the tests on Android, you will need to create an emulator device on your system:
2022-09-01 15:43:24 +05:00
```
$ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_5_API_31 -d pixel --package "system-images;android-31;default;x86_64"
```
If you face problems, follow the detailed guide in [Detox documentation](https://wix.github.io/Detox/docs/introduction/android-dev-env). Keep the emulator name set to `Pixel_5_API_31`.
Once you have created an emulator device, build the Android apks:
2022-09-01 15:43:24 +05:00
```
npm run build:android
```
Finally, run the tests:
2022-09-01 15:43:24 +05:00
```
npm run test:android
```
### iOS
To run e2e tests on the iOS simulator, you must be on a Mac with XCode installed.
2022-09-01 15:43:24 +05:00
First, install [AppleSimulatorUtils](https://github.com/wix/AppleSimulatorUtils):
2022-09-01 15:43:24 +05:00
```
brew tap wix/brew
brew install applesimutils
```
Now build the iOS app for testing:
```
npm run build:ios
```
Finally, run the tests:
2022-09-01 15:43:24 +05:00
```
npm run test:ios
```
All tests on iOS are configured to run on `iPhone 8` simulator.