Giter VIP home page Giter VIP logo

react-native-electron's Introduction

React Native Electron Build Status npm version

Electron extensions to React Native for Web

Introduction

This project aims to provide extensions to React Native for Web targeted to the Electron environment to support additional modules exposed by React Native (ex Clipboard, WebView) using Electron APIs.

This is very early stage, not fully tested, and APIs will likely change between releases, so don't use this library if you need something stable.

Installation

npm install react-native-electron

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

npm install electron react react-native-web

react-art is also needed if you use ART.

Example

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

To run the demo app, fork this repository and run:

  • npm install
  • npm run example:server
  • In another terminal instance, npm run example:electron

Usage with Expo application

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

  • Follow this guide's setup
  • Run yarn expo-electron customize in order to eject expo-electron's webpack configuration
  • Edit ./electron/webpack.config.js as follows:
const { withExpoWebpack } = require('@expo/electron-adapter');

module.exports = config => {
	let 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 implementation using Electron's dialog

Alert.alert(
  title: string,
  message: ?string,
  buttons: ?Array<{text: string, onPress?: () => void}> = [],
  type: ?('none' | 'info' | 'error' | 'question' | 'warning') = 'none'
): void

Appearance

React Native's Appearance implementation using Electron's nativeTheme

Appearance.getColorScheme(): 'light' | 'dark' | null

Clipboard

React Native's Clipboard implementation using Electron's clipboard.

Clipboard.getString(type: ?string): Promise<?string>

Clipboard.setString(text: string, type: ?string): void

Linking

React Native's Linking implementation using Electron's app and 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

Hooks

useColorScheme(): 'light' | 'dark' | null

License

MIT
See LICENSE file.

react-native-electron's People

Contributors

paullecam avatar ronamihai avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.