Skip to content

Commit

Permalink
v0.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulLeCam committed Aug 6, 2022
1 parent c3f55e1 commit 1922ae7
Show file tree
Hide file tree
Showing 28 changed files with 8,011 additions and 4,229 deletions.
22 changes: 14 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ name: CI
on: [push, pull_request]
jobs:
build:
name: Build and lint on Node ${{ matrix.node }} and ${{ matrix.os }}
name: Node ${{ matrix.node }} on ${{ matrix.os }}

runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['16.x', '17.x']
node: ['16.x', '18.x']
os: [ubuntu-latest, macOS-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 7

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Lint
run: yarn lint
run: cd library && pnpm run lint
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
node_modules
lib
es
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.18.0 (2022-08-06)

- Updated React dependency to v18.
- Updated React Native for Web dependency to v0.18.
- Updated Electron dependency to v20.0.

## v0.17.0 (2022-02-26)

- Updated Electron dependency to v17.0.
Expand Down
122 changes: 1 addition & 121 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,4 @@

[Electron](https://www.electronjs.org) extensions to [React Native for Web](https://github.com/necolas/react-native-web)

## Introduction

This project aims to provide extensions to [React Native for Web](https://github.com/necolas/react-native-web) targeted to the [Electron](https://www.electronjs.org) environment to support additional modules exposed by React Native (`Alert`) or alternative implementations (`Linking`) using Electron APIs.

## Installation

```sh
npm install react-native-electron
```

`electron`, `react` and `react-native-web` are required peer dependencies, make sure to install them as well:

```sh
npm install electron react react-native-web
```

`react-art` is also needed if you use `ART`.

## Electron setup

In order for the APIs exposed by `react-native-electron` to be accessible in Electron's render process, the following setup must be applied:

- The `react-native-electron/main` module must be imported in the main process
- `BrowserWindow` instances must be created with the `preload` script from `react-native-electron/preload`, for example:

```js
webPreferences: {
preload: require('path').resolve(
require.resolve('react-native-electron/preload'),
),
},
```

## Example

See the `example` directory for the source code and Webpack config.

To run the demo app, fork this repository and run the following commands in the root folder:

- `yarn install`
- `yarn build`

Then in the `example` folder:

- `yarn install`
- `yarn start`

## Usage with Expo application

This module can be used with Expo application (created by `expo-cli`) using the following steps:

- Follow [this guide's](https://docs.expo.io/guides/using-electron/) setup
- Run `yarn expo-electron customize` in order to eject expo-electron's webpack configuration
- Edit `./electron/webpack.config.js` as follows:

```js
const { withExpoWebpack } = require('@expo/electron-adapter')

module.exports = (config) => {
const expoConfig = withExpoWebpack(config)
expoConfig.resolve.alias['react-native$'] = 'react-native-electron'
return expoConfig
}
```

Note this is a partial solution, as Expo's default webpack configuration includes more aliases to `react-native`, but it should cover all of `react-native-electron`'s APIs.

## APIs

### Alert

[React Native's Alert](https://reactnative.dev/docs/alert.html) implementation using [Electron's dialog](https://www.electronjs.org/docs/api/dialog/)

```js
Alert.alert(
title: string,
message: ?string,
buttons: ?Array<{text: string, onPress?: () => void}> = [],
type: ?('none' | 'info' | 'error' | 'question' | 'warning') = 'none'
): void
```
### Linking
[React Native's Linking](https://reactnative.dev/docs/linking.html) implementation using Electron's [app](https://www.electronjs.org/docs/api/app/) and [shell](https://www.electronjs.org/docs/api/shell/) APIs.
`Linking.openURL(url: string): Promise<void>`
`Linking.addEventListener(type: string, handler: Function): void`
`Linking.removeEventListener(type: string, handler: Function): void`
`Linking.canOpenURL(): Promise<true>`: always resolves to `true`
`Linking.getInitialURL(): Promise<?string>`: resolves with the `process.argv[1]` value, expecting the app to be opened by a command such as `myapp myapp://test`

### Platform

[React Native's Platform](https://reactnative.dev/docs/platform.html)
`Platform.isElectron: boolean`
`Platform.OS: string`
`Platform.nativeOS: string`
```ts
Platform.select(
win32?: any,
linux?: any,
darwin?: any,
electron?: any,
web?: any,
default?: any
): any
```
## License
MIT
See [LICENSE](LICENSE) file.
## [Documentation](library/README.md)
17 changes: 10 additions & 7 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
},
"license": "MIT",
"dependencies": {
"react-native-electron": "link:.."
"react": "18.2.0",
"react-dom": "^18.2.0",
"react-native-electron": "workspace:*"
},
"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/preset-react": "^7.16.7",
"@babel/core": "^7.18.5",
"@babel/preset-react": "^7.17.12",
"@electron-forge/cli": "^6.0.0-beta.63",
"@electron-forge/maker-zip": "^6.0.0-beta.63",
"@electron-forge/plugin-webpack": "6.0.0-beta.63",
"babel-loader": "^8.2.3",
"electron": "17.1.0",
"node-loader": "^2.0.0"
"@electron-forge/plugin-webpack": "6.0.0-beta.65",
"babel-loader": "^8.2.5",
"electron": "^20.0.0",
"node-loader": "^2.0.0",
"webpack": "^5.74.0"
},
"config": {
"forge": {
Expand Down
4 changes: 2 additions & 2 deletions example/src/renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { render } from 'react-dom'
import { createRoot } from 'react-dom/client'

import App from './App'

render(<App />, document.getElementById('app'))
createRoot(document.getElementById('app')).render(<App />)
2 changes: 1 addition & 1 deletion example/webpack.renderer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
},
resolve: {
alias: {
'react-native': require('path').resolve(__dirname, '..'),
'react-native': require('path').resolve(__dirname, '../library'),
},
},
}
Loading

0 comments on commit 1922ae7

Please sign in to comment.