• Stars
    star
    280
  • Rank 147,492 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React renderer for NativeScript

npm version

React NativeScript is A React renderer for NativeScript, allowing you to write a NativeScript app using the familiar React style.

I'm always hanging out in the #react chat of the NativeScript Slack if you'd like to talk about this project.

Setup

# Make sure that you have `tns` (the NativeScript CLI) installed:
#   https://docs.nativescript.org/start/quick-setup

tns create myApp --react

cd myApp
npm install

# The Preview and Playground apps are awaiting an update from
# RNS v0 to v1, so the `tns preview` workflow isn't supported
# yet. We're working on it. โ€“ 18th July 2020
#
# tns preview
# or
tns run ios
# or
tns run android

Documentation

Example real-world app

See the Apps showcase in the docs to see various apps built with React NativeScript.

One example is my rpstrackerrns issue-tracking example app, which demonstrates how you can make fully native, professional-looking UIs with RNS:

Login Page

Backlog Page

Detail Page

Plugins

Although NativeScript lets you write native code inline as JavaScript, you can also write modules purely using native code (e.g. Objective-C and Java), and access the code directly in NativeScript via JavaScript. When a common, cross-platform JavaScript API is provided for such modules, it is called a "plugin", and can be thought of as equivalent to a React Native "native module". NativeScript has a rich ecosystem of these plugins โ€“ see the NativeScript Marketplace.

React NativeScript uses the same plugins API as NativeScript Vue and NativeScript Angular, so all those plugins should be compatible (although generally needing to be consumed with any type, as most plugins are only typed for NativeScript Core). Instructions on how to integrate plugins, and provide typings for React, can be found in the React NativeScript plugins documentation.

Why not just use React Native? ๐Ÿคทโ€โ™‚๏ธ

React NativeScript shares most of the good parts of React Native, but above all gives a first-class development experience for interacting with native code. Never write another native module again โ€“ you can write your native code inline using JavaScript!

React Native

React NativeScript

UI renderer

React

Programming language

JavaScript (with TypeScript typings available)

Platforms

iOS + Android + many more

iOS + Android

Bundler

Metro

Webpack

Codebase

Absolutely unfathomable

Very approachable to new contributors

Javascript VM threading

Separate 'JS' thread

Main (UI) thread

Native API access
Synchronicity

Mostly asynchronous. Typically involves sending JSON-serialisable messages back-and-forth over a native-to-JS bridge. Synchronous only in advanced cases such as JSI and C++ TurboModules, and static values from native modules.

Synchronous: The JS VM has direct bindings to the native context, and sits on the main (UI) thread.

Type marshalling

Only supports JSON-serialisable types[iOS][Android], and only passes by value rather than by reference.

Can marshal nearly any data type[iOS][Android] back and forth between the JS and native contexts, and even passes by reference from native to JS, allowing APIs to be called on native class instances from the JS context. Memory management of native references held by JS is very clever.

Bindings

Users must write their own bindings[iOS][Android] (except possibly for the advanced feature of C++ TurboModules) and try not to get anything wrong.

Bindings between the Objective-C/Java runtimes and JavaScript will be automatically generated[iOS][Android] for any source code included in your app.

Typings

Users must write the typings for their native modules manually[iOS][Android] (except possibly for the advanced feature of C++ TurboModules) and try not to get anything wrong!

Typings can be automatically generated for bindings[iOS][Android], and typings for the whole platform SDK are already provided.

Swift and Kotlin support

For Swift, can write implementation but must expose to React Native via an accompanying Obj-C file and manually-written bindings. Documentation also very limited. Not sure what's involved for Kotlin, but it is supported.

For Swift, just follow a few steps such as adding the @objc tag to the methods, and you're good to go! Not sure what's involved for Kotlin, but it is supported.

UI access

Very limited access to the underlying UI components (e.g. with a ref to a View component, you cannot do much โ€“ you can't traverse the UI tree, make synchronous measurements, or call the underlying APIs of the UI component). Exceptions may include the advanced case of Reanimated 2 worklets.

All NativeScript UI elements provide full, synchronous API access to the underlying UI component. e.g. on iOS, with a ref to a React NativeScript <frame> component, you can access the underlying UINavigationController along with all of its APIs and make synchronous UI measurements.

Hot reloading

All native code changes (except possibly JSI and worklets) require app recompilation.

Any native API accesses via JS can be hot reloaded. Native code written in Obj-C / Java does, however, still require an app recompile upon change.

FAQ

Is it production-ready?

It's based on React, NativeScript Core, and NativeScript Vue, which are each individually production-ready. Make of that what you will.

Can this consume React Native projects?

No, but it could with a lot of hard work. Allowing React NativeScript to run projects that were written for React Native is a huge project, but it's theoretically very possible โ€“ it would be a project on exactly the same scale as React Native Web. See react-nativescript-compat-react-native for work towards this, where I've ported part of RNTester as a proof-of-concept... ๐Ÿ‘ฉโ€๐Ÿ”ฌ๐Ÿ‘จโ€๐Ÿ”ฌ

Can this consume React Native native modules?

Certainly not UI-based native modules. But all flavours of NativeScript can consume native code, so it can probably consume React Native native modules, though may take a small bit of refactoring ๐Ÿค”

Stanisล‚aw Chmiela (@sjchmiela) produced a proof-of-concept for importing Expo Unimodules into NativeScript that could be used as a basis for this effort. Original discussion here.

Contributing ๐Ÿ™‹โ€โ™€๏ธ

Ideally get in contact via the Discord channel before starting any PRs!

More Repositories

1

react-native-native-runtime

The Objective-C runtime exposed directly to React Native via JSI (Java runtime may follow)!
Objective-C++
239
star
2

nside

A JavaScript IDE for accessing a phone/tablet's native runtime via NativeScript bindings!
TypeScript
101
star
3

react-native-web-browser-app

Not another wrapper around SFSafariViewController. A fully-featured, cross-platform web browser written in React Native.
TypeScript
58
star
4

react-native-typescript-2d-game

A simple 2D game (called The Box) implemented in React Native, as an Expo app, using TypeScript.
TypeScript
37
star
5

crank-native

A Crank renderer for iOS and Android apps, based on NativeScript.
TypeScript
25
star
6

dom-events-wintercg

A standalone implementation of the DOM Events APIs, extracted from the Node.js codebase, for usage in WinterCG runtimes.
JavaScript
17
star
7

react-native-nativescript-runtime

Use the NativeScript runtime from React Native
Java
14
star
8

subscripto

An app that handles subscriptions and local receipt validation โ€“ used in a real app, LinguaBrowse!
C
14
star
9

react-native-safe-popover

A faithful port of UIPopoverPresentationController, which respects the safe area, to React Native.
TypeScript
10
star
10

nativescript-grimoire

A grimoire of NativeScript incantations to invoke native APIs
9
star
11

mecab-ko

A fork of Mecab, with support for both Japanese and Korean, organised as a Cocoapod and npm package for usage with iOS/macOS.
C++
7
star
12

nativescript-html

HTML and some web platform features for NativeScript
TypeScript
7
star
13

cocoapojs

CocoaPods, ported to JavaScript
TypeScript
7
star
14

uikit-dom

Implementing DOM for UIKit; wish me luck
Swift
6
star
15

jp-pitch-accent

A demo of how to use Svelte components to take Japanese pitch accent notes.
Svelte
6
star
16

clang_metagen_deno

A Deno-based program for generating FFI metadata for languages like Obj-C using the Clang APIs.
TypeScript
6
star
17

nativescript-syntax-highlighter

Syntax Highlighter for NativeScript. Currently only supports iOS (being completely based on Highlightr).
CSS
6
star
18

react-nativescript-navigation

React Navigation integration for React NativeScript
TypeScript
4
star
19

react-nativescript-compat-react-native

Compatibility layer to allow React NativeScript projects to run React Native codebases
TypeScript
3
star
20

mecab-naist-jdic-utf-8

mecab-naist-jdic (a Japanese dictionary for use with Mecab), in UTF-8 format, organised as a Cocoapod and npm package for usage with iOS/macOS.
Ruby
3
star
21

pitch-accent

Predict pitch accent in Japanese
TypeScript
2
star
22

elementr

Convenience framework for assembling and styling a tree of HTML Elements.
TypeScript
2
star
23

seiyuu-ranker

Visualise which seiyuus were the most prolific in a given year or season.
Svelte
2
star
24

rnobjc

Repo for the code behind my React Native EU 2022 talk, "How to access all the Objectiveโ€‘C APIs using JSI". A cleaner version of shirakaba/react-native-native-runtime.
Objective-C++
2
star
25

rpstrackerrns

Alex Ziskind's RPS Tracker app, ported from NativeScript Core to React NativeScript
TypeScript
2
star
26

react-nativescript-site

Source code for the React NativeScript documentation website
JavaScript
2
star
27

tns-template-blank-crank

NativeScript CLI template for building a Crank Native app.
JavaScript
1
star
28

migrate-ts-loader-to-babel-loader

JavaScript
1
star
29

url-wintercg

A polyfill for WHATWG URL and related APIs, powered by Ada.
C++
1
star
30

GrafanaSimpleJsonValueMapper-docker

Docker container for setting up GrafanaSimpleJsonValueMapper.
Shell
1
star
31

anime-diverge

JavaScript
1
star
32

JBSearchBar

React Native searchbar implemented in Swift
Swift
1
star
33

easytimeline-docker

EasyTimeline, Dockerised
Perl
1
star
34

react-nativescript-pikatalk

A real-world app, based on HelloTalk, made with React NativeScript.
TypeScript
1
star
35

rns-browser

[Under construction] A browser written in React NativeScript, based on the Cliqz and Firefox iOS browser UIs.
TypeScript
1
star
36

executor

Wrap up any executable as a Cocoa app!
Swift
1
star
37

Kanji-etymology-browser

Tools to create a lightweight, browsable digital version using scans of the 1988 kanji etymology paperback dictionary by Kenneth G. Henshall. For personal educational use.
HTML
1
star
38

nativescript-flowlayout

TypeScript
1
star
39

jmdict-sqlite

A crude script to download a release of `jmdict-simplified` and build an SQLite database from it.
JavaScript
1
star