├── .circleci
└── config.yml
├── .editorconfig
├── .gitattributes
├── .gitignore
├── .husky
├── .npmignore
├── commit-msg
└── pre-commit
├── .yarnrc
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── android
├── CMakeLists.txt
├── build.gradle
├── cpp-adapter.cpp
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── reactnativeobjcruntime
│ ├── ObjcRuntimeModule.java
│ └── ObjcRuntimePackage.java
├── babel.config.js
├── example
├── .eslintrc.json
├── android
│ ├── app
│ │ ├── build.gradle
│ │ ├── debug.keystore
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ ├── debug
│ │ │ ├── AndroidManifest.xml
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── reactnativeobjcruntime
│ │ │ │ └── ReactNativeFlipper.java
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── reactnativeobjcruntime
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── MainApplication.java
│ │ │ └── res
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
├── app.json
├── babel.config.js
├── index.tsx
├── ios
│ ├── File.swift
│ ├── ObjcRuntimeExample-Bridging-Header.h
│ ├── ObjcRuntimeExample.xcodeproj
│ │ ├── project.pbxproj
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── ObjcRuntimeExample.xcscheme
│ ├── ObjcRuntimeExample.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ ├── ObjcRuntimeExample
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Images.xcassets
│ │ │ ├── AppIcon.appiconset
│ │ │ │ └── Contents.json
│ │ │ └── Contents.json
│ │ ├── Info.plist
│ │ ├── LaunchScreen.storyboard
│ │ ├── main.m
│ │ └── objc-constants
│ │ │ └── Foundation.json
│ ├── Podfile
│ └── Podfile.lock
├── metro.config.js
├── package.json
├── src
│ ├── App.tsx
│ └── objc-types.d.ts
└── yarn.lock
├── ios
├── HostObjectClass.h
├── HostObjectClass.mm
├── HostObjectClassInstance.h
├── HostObjectClassInstance.mm
├── HostObjectObjc.h
├── HostObjectObjc.mm
├── HostObjectProtocol.h
├── HostObjectProtocol.mm
├── HostObjectSelector.h
├── HostObjectSelector.mm
├── HostObjectUtils.h
├── HostObjectUtils.mm
├── JSIUtils.h
├── JSIUtils.mm
├── ObjcRuntime.h
├── ObjcRuntime.mm
├── ObjcRuntime.xcodeproj
│ └── project.pbxproj
├── react-native-objc-runtime.h
└── react-native-objc-runtime.mm
├── package.json
├── react-native-objc-runtime.podspec
├── scripts
└── bootstrap.js
├── src
├── __tests__
│ └── index.test.tsx
└── index.tsx
├── tsconfig.build.json
├── tsconfig.json
└── yarn.lock
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 |
3 | executors:
4 | default:
5 | docker:
6 | - image: circleci/node:10
7 | working_directory: ~/project
8 |
9 | commands:
10 | attach_project:
11 | steps:
12 | - attach_workspace:
13 | at: ~/project
14 |
15 | jobs:
16 | install-dependencies:
17 | executor: default
18 | steps:
19 | - checkout
20 | - attach_project
21 | - restore_cache:
22 | keys:
23 | - dependencies-{{ checksum "package.json" }}
24 | - dependencies-
25 | - restore_cache:
26 | keys:
27 | - dependencies-example-{{ checksum "example/package.json" }}
28 | - dependencies-example-
29 | - run:
30 | name: Install dependencies
31 | command: |
32 | yarn install --cwd example --frozen-lockfile
33 | yarn install --frozen-lockfile
34 | - save_cache:
35 | key: dependencies-{{ checksum "package.json" }}
36 | paths: node_modules
37 | - save_cache:
38 | key: dependencies-example-{{ checksum "example/package.json" }}
39 | paths: example/node_modules
40 | - persist_to_workspace:
41 | root: .
42 | paths: .
43 |
44 | lint:
45 | executor: default
46 | steps:
47 | - attach_project
48 | - run:
49 | name: Lint files
50 | command: |
51 | yarn lint
52 |
53 | typescript:
54 | executor: default
55 | steps:
56 | - attach_project
57 | - run:
58 | name: Typecheck files
59 | command: |
60 | yarn typescript
61 |
62 | unit-tests:
63 | executor: default
64 | steps:
65 | - attach_project
66 | - run:
67 | name: Run unit tests
68 | command: |
69 | yarn test --coverage
70 | - store_artifacts:
71 | path: coverage
72 | destination: coverage
73 |
74 | build-package:
75 | executor: default
76 | steps:
77 | - attach_project
78 | - run:
79 | name: Build package
80 | command: |
81 | yarn prepare
82 |
83 | workflows:
84 | build-and-test:
85 | jobs:
86 | - install-dependencies
87 | - lint:
88 | requires:
89 | - install-dependencies
90 | - typescript:
91 | requires:
92 | - install-dependencies
93 | - unit-tests:
94 | requires:
95 | - install-dependencies
96 | - build-package:
97 | requires:
98 | - install-dependencies
99 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 |
9 | indent_style = space
10 | indent_size = 2
11 |
12 | end_of_line = lf
13 | charset = utf-8
14 | trim_trailing_whitespace = true
15 | insert_final_newline = true
16 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 | # specific for windows script files
3 | *.bat text eol=crlf
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # XDE
6 | .expo/
7 |
8 | # VSCode
9 | .vscode/
10 | jsconfig.json
11 |
12 | # Xcode
13 | #
14 | build/
15 | *.pbxuser
16 | !default.pbxuser
17 | *.mode1v3
18 | !default.mode1v3
19 | *.mode2v3
20 | !default.mode2v3
21 | *.perspectivev3
22 | !default.perspectivev3
23 | xcuserdata
24 | *.xccheckout
25 | *.moved-aside
26 | DerivedData
27 | *.hmap
28 | *.ipa
29 | *.xcuserstate
30 | project.xcworkspace
31 |
32 | # Android/IJ
33 | #
34 | .classpath
35 | .cxx
36 | .gradle
37 | .idea
38 | .project
39 | .settings
40 | local.properties
41 | android.iml
42 |
43 | # Cocoapods
44 | #
45 | example/ios/Pods
46 |
47 | # node.js
48 | #
49 | node_modules/
50 | npm-debug.log
51 | yarn-debug.log
52 | yarn-error.log
53 |
54 | # BUCK
55 | buck-out/
56 | \.buckd/
57 | android/app/libs
58 | android/keystores/debug.keystore
59 |
60 | # Expo
61 | .expo/*
62 |
63 | # generated by bob
64 | lib/
65 |
--------------------------------------------------------------------------------
/.husky/.npmignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn commitlint -E HUSKY_GIT_PARAMS
5 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn lint && yarn typescript
5 |
--------------------------------------------------------------------------------
/.yarnrc:
--------------------------------------------------------------------------------
1 | # Override Yarn command so we can automatically setup the repo on running `yarn`
2 |
3 | yarn-path "scripts/bootstrap.js"
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project.
4 |
5 | ## Development workflow
6 |
7 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
8 |
9 | ```sh
10 | yarn
11 | ```
12 |
13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development.
14 |
15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app.
16 |
17 | To start the packager:
18 |
19 | ```sh
20 | yarn example start
21 | ```
22 |
23 | To run the example app on Android:
24 |
25 | ```sh
26 | yarn example android
27 | ```
28 |
29 | To run the example app on iOS:
30 |
31 | ```sh
32 | yarn example ios
33 | ```
34 |
35 | Make sure your code passes TypeScript and ESLint. Run the following to verify:
36 |
37 | ```sh
38 | yarn typescript
39 | yarn lint
40 | ```
41 |
42 | To fix formatting errors, run the following:
43 |
44 | ```sh
45 | yarn lint --fix
46 | ```
47 |
48 | Remember to add tests for your change if possible. Run the unit tests by:
49 |
50 | ```sh
51 | yarn test
52 | ```
53 |
54 | To edit the Objective-C files, open `example/ios/ObjcRuntimeExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-objc-runtime`.
55 |
56 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativeobjcruntime` under `Android`.
57 |
58 | ### Commit message convention
59 |
60 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
61 |
62 | - `fix`: bug fixes, e.g. fix crash due to deprecated method.
63 | - `feat`: new features, e.g. add new method to the module.
64 | - `refactor`: code refactor, e.g. migrate from class components to hooks.
65 | - `docs`: changes into documentation, e.g. add usage example for the module..
66 | - `test`: adding or updating tests, e.g. add integration tests using detox.
67 | - `chore`: tooling changes, e.g. change CI config.
68 |
69 | Our pre-commit hooks verify that your commit message matches this format when committing.
70 |
71 | ### Linting and tests
72 |
73 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
74 |
75 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
76 |
77 | Our pre-commit hooks verify that the linter and tests pass when committing.
78 |
79 | ### Publishing to npm
80 |
81 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
82 |
83 | To publish new versions, run the following:
84 |
85 | ```sh
86 | yarn release
87 | ```
88 |
89 | ### Scripts
90 |
91 | The `package.json` file contains various scripts for common tasks:
92 |
93 | - `yarn bootstrap`: setup project by installing all dependencies and pods.
94 | - `yarn typescript`: type-check files with TypeScript.
95 | - `yarn lint`: lint files with ESLint.
96 | - `yarn test`: run unit tests with Jest.
97 | - `yarn example start`: start the Metro server for the example app.
98 | - `yarn example android`: run the example app on Android.
99 | - `yarn example ios`: run the example app on iOS.
100 |
101 | ### Sending a pull request
102 |
103 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
104 |
105 | When you're sending a pull request:
106 |
107 | - Prefer small pull requests focused on one change.
108 | - Verify that linters and tests are passing.
109 | - Review the documentation to make sure it looks good.
110 | - Follow the pull request template when opening a pull request.
111 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
112 |
113 | ## Code of Conduct
114 |
115 | ### Our Pledge
116 |
117 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
118 |
119 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
120 |
121 | ### Our Standards
122 |
123 | Examples of behavior that contributes to a positive environment for our community include:
124 |
125 | - Demonstrating empathy and kindness toward other people
126 | - Being respectful of differing opinions, viewpoints, and experiences
127 | - Giving and gracefully accepting constructive feedback
128 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
129 | - Focusing on what is best not just for us as individuals, but for the overall community
130 |
131 | Examples of unacceptable behavior include:
132 |
133 | - The use of sexualized language or imagery, and sexual attention or
134 | advances of any kind
135 | - Trolling, insulting or derogatory comments, and personal or political attacks
136 | - Public or private harassment
137 | - Publishing others' private information, such as a physical or email
138 | address, without their explicit permission
139 | - Other conduct which could reasonably be considered inappropriate in a
140 | professional setting
141 |
142 | ### Enforcement Responsibilities
143 |
144 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
145 |
146 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
147 |
148 | ### Scope
149 |
150 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
151 |
152 | ### Enforcement
153 |
154 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly.
155 |
156 | All community leaders are obligated to respect the privacy and security of the reporter of any incident.
157 |
158 | ### Enforcement Guidelines
159 |
160 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
161 |
162 | #### 1. Correction
163 |
164 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
165 |
166 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
167 |
168 | #### 2. Warning
169 |
170 | **Community Impact**: A violation through a single incident or series of actions.
171 |
172 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
173 |
174 | #### 3. Temporary Ban
175 |
176 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
177 |
178 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
179 |
180 | #### 4. Permanent Ban
181 |
182 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
183 |
184 | **Consequence**: A permanent ban from any sort of public interaction within the community.
185 |
186 | ### Attribution
187 |
188 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
189 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
190 |
191 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
192 |
193 | [homepage]: https://www.contributor-covenant.org
194 |
195 | For answers to common questions about this code of conduct, see the FAQ at
196 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
197 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | ===== react-nativescript-native-runtime =====
2 |
3 | MIT License
4 |
5 | Copyright (c) 2021 Jamie Birch
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in all
15 | copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | SOFTWARE.
24 |
25 | ===== react-native-vision-camera (used in cpp/JSIUtils.mm and cpp/JSIUtils.h; forked from react-native) =====
26 |
27 | Copyright 2021 Marc Rousavy
28 |
29 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
30 |
31 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32 |
33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 |
35 | ===== react-native =====
36 |
37 | MIT License
38 |
39 | Copyright (c) Facebook, Inc. and its affiliates.
40 |
41 | Permission is hereby granted, free of charge, to any person obtaining a copy
42 | of this software and associated documentation files (the "Software"), to deal
43 | in the Software without restriction, including without limitation the rights
44 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45 | copies of the Software, and to permit persons to whom the Software is
46 | furnished to do so, subject to the following conditions:
47 |
48 | The above copyright notice and this permission notice shall be included in all
49 | copies or substantial portions of the Software.
50 |
51 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
57 | SOFTWARE.
58 |
59 |
60 | ====== @nativescript/ios/types =====
61 |
62 | Apache License
63 | Version 2.0, January 2004
64 | http://www.apache.org/licenses/
65 |
66 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
67 |
68 | 1. Definitions.
69 |
70 | "License" shall mean the terms and conditions for use, reproduction,
71 | and distribution as defined by Sections 1 through 9 of this document.
72 |
73 | "Licensor" shall mean the copyright owner or entity authorized by
74 | the copyright owner that is granting the License.
75 |
76 | "Legal Entity" shall mean the union of the acting entity and all
77 | other entities that control, are controlled by, or are under common
78 | control with that entity. For the purposes of this definition,
79 | "control" means (i) the power, direct or indirect, to cause the
80 | direction or management of such entity, whether by contract or
81 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
82 | outstanding shares, or (iii) beneficial ownership of such entity.
83 |
84 | "You" (or "Your") shall mean an individual or Legal Entity
85 | exercising permissions granted by this License.
86 |
87 | "Source" form shall mean the preferred form for making modifications,
88 | including but not limited to software source code, documentation
89 | source, and configuration files.
90 |
91 | "Object" form shall mean any form resulting from mechanical
92 | transformation or translation of a Source form, including but
93 | not limited to compiled object code, generated documentation,
94 | and conversions to other media types.
95 |
96 | "Work" shall mean the work of authorship, whether in Source or
97 | Object form, made available under the License, as indicated by a
98 | copyright notice that is included in or attached to the work
99 | (an example is provided in the Appendix below).
100 |
101 | "Derivative Works" shall mean any work, whether in Source or Object
102 | form, that is based on (or derived from) the Work and for which the
103 | editorial revisions, annotations, elaborations, or other modifications
104 | represent, as a whole, an original work of authorship. For the purposes
105 | of this License, Derivative Works shall not include works that remain
106 | separable from, or merely link (or bind by name) to the interfaces of,
107 | the Work and Derivative Works thereof.
108 |
109 | "Contribution" shall mean any work of authorship, including
110 | the original version of the Work and any modifications or additions
111 | to that Work or Derivative Works thereof, that is intentionally
112 | submitted to Licensor for inclusion in the Work by the copyright owner
113 | or by an individual or Legal Entity authorized to submit on behalf of
114 | the copyright owner. For the purposes of this definition, "submitted"
115 | means any form of electronic, verbal, or written communication sent
116 | to the Licensor or its representatives, including but not limited to
117 | communication on electronic mailing lists, source code control systems,
118 | and issue tracking systems that are managed by, or on behalf of, the
119 | Licensor for the purpose of discussing and improving the Work, but
120 | excluding communication that is conspicuously marked or otherwise
121 | designated in writing by the copyright owner as "Not a Contribution."
122 |
123 | "Contributor" shall mean Licensor and any individual or Legal Entity
124 | on behalf of whom a Contribution has been received by Licensor and
125 | subsequently incorporated within the Work.
126 |
127 | 2. Grant of Copyright License. Subject to the terms and conditions of
128 | this License, each Contributor hereby grants to You a perpetual,
129 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
130 | copyright license to reproduce, prepare Derivative Works of,
131 | publicly display, publicly perform, sublicense, and distribute the
132 | Work and such Derivative Works in Source or Object form.
133 |
134 | 3. Grant of Patent License. Subject to the terms and conditions of
135 | this License, each Contributor hereby grants to You a perpetual,
136 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
137 | (except as stated in this section) patent license to make, have made,
138 | use, offer to sell, sell, import, and otherwise transfer the Work,
139 | where such license applies only to those patent claims licensable
140 | by such Contributor that are necessarily infringed by their
141 | Contribution(s) alone or by combination of their Contribution(s)
142 | with the Work to which such Contribution(s) was submitted. If You
143 | institute patent litigation against any entity (including a
144 | cross-claim or counterclaim in a lawsuit) alleging that the Work
145 | or a Contribution incorporated within the Work constitutes direct
146 | or contributory patent infringement, then any patent licenses
147 | granted to You under this License for that Work shall terminate
148 | as of the date such litigation is filed.
149 |
150 | 4. Redistribution. You may reproduce and distribute copies of the
151 | Work or Derivative Works thereof in any medium, with or without
152 | modifications, and in Source or Object form, provided that You
153 | meet the following conditions:
154 |
155 | (a) You must give any other recipients of the Work or
156 | Derivative Works a copy of this License; and
157 |
158 | (b) You must cause any modified files to carry prominent notices
159 | stating that You changed the files; and
160 |
161 | (c) You must retain, in the Source form of any Derivative Works
162 | that You distribute, all copyright, patent, trademark, and
163 | attribution notices from the Source form of the Work,
164 | excluding those notices that do not pertain to any part of
165 | the Derivative Works; and
166 |
167 | (d) If the Work includes a "NOTICE" text file as part of its
168 | distribution, then any Derivative Works that You distribute must
169 | include a readable copy of the attribution notices contained
170 | within such NOTICE file, excluding those notices that do not
171 | pertain to any part of the Derivative Works, in at least one
172 | of the following places: within a NOTICE text file distributed
173 | as part of the Derivative Works; within the Source form or
174 | documentation, if provided along with the Derivative Works; or,
175 | within a display generated by the Derivative Works, if and
176 | wherever such third-party notices normally appear. The contents
177 | of the NOTICE file are for informational purposes only and
178 | do not modify the License. You may add Your own attribution
179 | notices within Derivative Works that You distribute, alongside
180 | or as an addendum to the NOTICE text from the Work, provided
181 | that such additional attribution notices cannot be construed
182 | as modifying the License.
183 |
184 | You may add Your own copyright statement to Your modifications and
185 | may provide additional or different license terms and conditions
186 | for use, reproduction, or distribution of Your modifications, or
187 | for any such Derivative Works as a whole, provided Your use,
188 | reproduction, and distribution of the Work otherwise complies with
189 | the conditions stated in this License.
190 |
191 | 5. Submission of Contributions. Unless You explicitly state otherwise,
192 | any Contribution intentionally submitted for inclusion in the Work
193 | by You to the Licensor shall be under the terms and conditions of
194 | this License, without any additional terms or conditions.
195 | Notwithstanding the above, nothing herein shall supersede or modify
196 | the terms of any separate license agreement you may have executed
197 | with Licensor regarding such Contributions.
198 |
199 | 6. Trademarks. This License does not grant permission to use the trade
200 | names, trademarks, service marks, or product names of the Licensor,
201 | except as required for reasonable and customary use in describing the
202 | origin of the Work and reproducing the content of the NOTICE file.
203 |
204 | 7. Disclaimer of Warranty. Unless required by applicable law or
205 | agreed to in writing, Licensor provides the Work (and each
206 | Contributor provides its Contributions) on an "AS IS" BASIS,
207 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
208 | implied, including, without limitation, any warranties or conditions
209 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
210 | PARTICULAR PURPOSE. You are solely responsible for determining the
211 | appropriateness of using or redistributing the Work and assume any
212 | risks associated with Your exercise of permissions under this License.
213 |
214 | 8. Limitation of Liability. In no event and under no legal theory,
215 | whether in tort (including negligence), contract, or otherwise,
216 | unless required by applicable law (such as deliberate and grossly
217 | negligent acts) or agreed to in writing, shall any Contributor be
218 | liable to You for damages, including any direct, indirect, special,
219 | incidental, or consequential damages of any character arising as a
220 | result of this License or out of the use or inability to use the
221 | Work (including but not limited to damages for loss of goodwill,
222 | work stoppage, computer failure or malfunction, or any and all
223 | other commercial damages or losses), even if such Contributor
224 | has been advised of the possibility of such damages.
225 |
226 | 9. Accepting Warranty or Additional Liability. While redistributing
227 | the Work or Derivative Works thereof, You may choose to offer,
228 | and charge a fee for, acceptance of support, warranty, indemnity,
229 | or other liability obligations and/or rights consistent with this
230 | License. However, in accepting such obligations, You may act only
231 | on Your own behalf and on Your sole responsibility, not on behalf
232 | of any other Contributor, and only if You agree to indemnify,
233 | defend, and hold each Contributor harmless for any liability
234 | incurred by, or claims asserted against, such Contributor by reason
235 | of your accepting any such warranty or additional liability.
236 |
237 | END OF TERMS AND CONDITIONS
238 |
239 | APPENDIX: How to apply the Apache License to your work.
240 |
241 | To apply the Apache License to your work, attach the following
242 | boilerplate notice, with the fields enclosed by brackets "{}"
243 | replaced with your own identifying information. (Don't include
244 | the brackets!) The text should be enclosed in the appropriate
245 | comment syntax for the file format. We also recommend that a
246 | file or class name and description of purpose be included on the
247 | same "printed page" as the copyright notice for easier
248 | identification within third-party archives.
249 |
250 | Copyright (c) 2020, nStudio LLC
251 |
252 | Licensed under the Apache License, Version 2.0 (the "License");
253 | you may not use this file except in compliance with the License.
254 | You may obtain a copy of the License at
255 |
256 | http://www.apache.org/licenses/LICENSE-2.0
257 |
258 | Unless required by applicable law or agreed to in writing, software
259 | distributed under the License is distributed on an "AS IS" BASIS,
260 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
261 | See the License for the specific language governing permissions and
262 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-native-runtime
2 |
3 |
18 |
19 | Access the native APIs directly from the React Native JS context!
20 |
21 | For now, we support just Objective-C (for iOS/macOS/tvOS devices, but I'll refer to iOS for brevity). Adding support for Java (for Android devices) is on my wishlist for the future.
22 |
23 | ## Installation
24 |
25 | Please get in contact if these instructions don't work for you!
26 |
27 | ```sh
28 | # WARNING: only tested with react-native@^0.64.2.
29 | # Will not work on lower versions; *may* work on newer versions.
30 |
31 | # Install the npm package
32 | npm install --save react-native-native-runtime
33 |
34 | # Install the Cocoapod
35 | cd ios && pod install && cd ..
36 | ```
37 |
38 | ## Usage
39 |
40 | For now, as I haven't installed the package yet, just clone the repo and play around with [example/src/App.tsx](example/src/App.tsx).
41 |
42 | ### The Java runtime
43 |
44 | 🚧 I haven't yet started building this, and it's further away from my expertise (I'm more of an iOS developer). Get in contact if you'd like to get involved!
45 |
46 | ### The Obj-C runtime
47 |
48 | All Obj-C APIs are exposed through a proxy object called `objc`, which is injected into the JS context's global scope early at run time (provided you have remembered to install the Cocoapod and rebuilt your iOS app since then). Technically it occurs when React Native finds the `setBridge` method in `ios/ObjcRuntime.mm` just like for any other iOS native module and then calls the `ObjcRuntimeJsi::install()` method within.
49 |
50 | #### TypeScript typings?
51 |
52 | ⚠️ First, a warning: We only have very minimal hand-written TypeScript typings at the moment. Get used to `any` type until we make a more lasting solution, most likely based on the NativeScript metadata/typings generator. For now, copy [example/src/objc-types.d.ts](example/src/objc-types.d.ts) to get started.
53 |
54 | #### The `objc` proxy object
55 |
56 | As mentioned, this is available in the global scope on any Apple app.
57 |
58 | Generally, you'll use the `objc` proxy object to look up some native data type. If a match is found for the native data type, we wrap it in a C++ HostObject class instance that is shared across to the JS context.
59 |
60 | ```typescript
61 | // Class lookup:
62 | // Returns a JS HostObject wrapping a native class.
63 | // This works via the Obj-C runtime helper NSClassFromString,
64 | // so it has O(1) complexity.
65 | objc.NSString;
66 |
67 | // Protocol lookup:
68 | // Returns a JS HostObject wrapping a native Protocol (if a class
69 | // with the same name wasn't found first).
70 | // This works via the Obj-C runtime helper NSProtocolFromString,
71 | // so it has O(1) complexity.
72 | objc.NSSecureCoding;
73 |
74 | // Constant/variable lookup:
75 | // Returns a JS HostObject wrapping any native global symbol (the
76 | // most common ones being constants and variables).
77 | // This works by looking up the symbol from the executable (a
78 | // fallback undertaken when neither NSClassFromString nor
79 | // NSProtocolFromString return a match for the given string).
80 | // This works via dlsym, so I believe it has O(N) complexity, but
81 | // probably isn't too slow anyway.
82 | objc.NSStringTransformLatinToHiragana;
83 |
84 | // Selector lookup:
85 | // Returns a JS HostObject wrapping a native Selector.
86 | // This works via the Obj-C runtime helper NSSelectorFromString, so
87 | // it has O(1) complexity.
88 | // I can't think of a good example for this, but it's possible.
89 | objc.getSelector("NoGoodExample:soWhoKnows:");
90 |
91 | // Will return an array of all Obj-C classes and all convenience
92 | // methods, but that's all.
93 | // Does not, for example, list out all constants/variables/protocols
94 | // available. Those have to be looked up individually.
95 | Object.keys(objc);
96 |
97 | // Will return the string:
98 | // [object HostObjectObjc]
99 | objc.toString();
100 |
101 | // Will cause an infinite loop and crash! Need some advice from JSI
102 | // experts on this.
103 | // It involves the following getters being called in sequence:
104 | // $$typeof -> Symbol.toStringTag -> toJSON -> Symbol.toStringTag ->
105 | // Symbol.toStringTag -> Symbol.toStringTag -> toString
106 | console.log(objc);
107 | ```
108 |
109 | #### Host Objects
110 |
111 | Again, this is a C++ HostObject class instance that is shared across to the JS context. Don't ask me how the memory-management works! That's one for a JSI expert (and I'd love some code review on my approach).
112 |
113 | The `objc` proxy object is one such HostObject. I've made some others:
114 |
115 | * HostObjectClass (wraps a class)
116 | * HostObjectClassInstance (wraps a class instance)
117 | * HostObjectProtocol (wraps a protocol)
118 | * HostObjectSelector (wraps a selector)
119 |
120 | *TODO: I'll likely make these expand a common abstract class. For now, they all directly extend `facebook::jsi::HostObject`.*
121 |
122 | These may expand in future, but the former two cover a huge API surface on their own. I'll focus on documenting those, as the latter two are largely empty skeletons.
123 |
124 |
125 | ##### HostObjectClass
126 |
127 | You can obtain a HostObjectClass by looking up a class on the `objc` proxy object:
128 |
129 | ```typescript
130 | const nSStringClass: objc.NSString = objc.NSString;
131 | ```
132 |
133 | You can also call class methods (AKA static methods, in other languages) on it:
134 |
135 | ```typescript
136 | const voice: objc.AVSpeechSynthesisVoice =
137 | objc.AVSpeechSynthesisVoice['voiceWithLanguage:']('en-GB');
138 | ```
139 |
140 | We'll cover what you can do with a class instance in the next section.
141 |
142 | ##### HostObjectClassInstance
143 |
144 | Once you have a class instance, you can call instance methods. The method names mirror the Obj-C selector, hence you'll be seeing a lot of colons. The JS invocation takes as many arguments as the Obj-C selector suggests (each colon indicates one param).
145 |
146 | ```typescript
147 | // Initialise an NSString
148 | const hello: objc.NSString =
149 | objc.NSString.alloc()['initWithString:']('Hello');
150 |
151 | // Return a new NSString by concatenating it
152 | const helloWorld: objc.NSString =
153 | hello['stringByAppendingString:'](', world!');
154 | ```
155 |
156 | You will have noticed that we're passing JS primitive types in as parameters. All JS primitive types are marshalled into equivalent Obj-C types:
157 |
158 | * string -> NSString
159 | * number -> NSNumber
160 | * boolean -> NSBoolean
161 | * Array -> NSArray
162 | * object -> NSDictionary
163 | * undefined -> nil
164 | * null -> nil
165 |
166 | Conversely, you can also marshal the following types from Obj-C to JS:
167 |
168 | * NSString -> string
169 | * NSNumber -> number
170 | * NSBoolean -> boolean
171 | * NSArray -> Array (provided each of the constituent values are marshal-friendly)
172 | * NSDictionary -> object (provided each of the constituent values are marshal-friendly)
173 | * kCFNull -> null
174 | * nil -> undefined
175 |
176 | Do so using the `toJS()` method on a HostObjectClassInstance:
177 |
178 | ```typescript
179 | // Marshal the NSString to a JS primitive string
180 | console.log(helloWorld.toJS());
181 | ```
182 |
183 | Beyond that, you can get the keys on the class instance:
184 |
185 | ```typescript
186 | // Will return a list of all instance variables, properties, and
187 | // native methods, and some added methods like toString().
188 | // TODO: list out all the *inherited* instance variables,
189 | // properties, and methods as well.
190 | Object.keys(helloWorld);
191 | ```
192 |
193 | You can also use getters:
194 |
195 | ```typescript
196 | // Allocate a native class instance
197 | const utterance: objc.AVSpeechUtterance =
198 | objc.AVSpeechUtterance.alloc()['initWithString:']('Hello, world!');
199 |
200 | // Get the property
201 | utterance.voice;
202 | ```
203 |
204 | ... and call setters:
205 |
206 | ```typescript
207 | // Allocate a native class instance
208 | const utterance: objc.AVSpeechUtterance =
209 | objc.AVSpeechUtterance.alloc()['initWithString:']('Hello, world!');
210 |
211 | // Set properties on it
212 | utterance.voice =
213 | objc.AVSpeechSynthesisVoice['voiceWithLanguage:']('ja-JP');
214 | ```
215 |
216 | ... but both getters and setters are currently *very* experimental and I need some help from an Obj-C expert to get them right.
217 |
218 | ## Is it complete?
219 |
220 | The Java runtime isn't even started yet, for one thing.
221 |
222 | The Obj-C runtime lets you do a lot of things already, but it is far from complete. There are some glaring things like lack of `console.log()` support and incomplete getter/setter support that are high priorities to solve, and peer review from JSI experts is also needed.
223 |
224 | ## Is it production-ready?
225 |
226 | No, but you can help that by contributing!
227 |
228 | Seriously, expect errors to be thrown if you don't know what you're doing (particularly as there are no TypeScript typings yet).
229 |
230 | ## Contributing
231 |
232 | Get in touch on the `#objc-runtime` channel of the [React Native JSI Discord](https://discord.com/invite/QDMxYqXw), or [send me a message](https://twitter.com/LinguaBrowse) on Twitter!
233 |
234 | I'll start putting some issues together to indicate tasks that need help.
235 |
236 | ## Acknowledgements
237 |
238 | JSI is an API that is not yet publicly documented, so I've stood on the shoulders of a few giants to get here.
239 |
240 | I couldn't have done this without [Marc Rousavy](https://github.com/mrousavy)'s [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera) project to refer to (I even make direct use of his JSIUtils helper methods in this codebase). He has done an exceptional amount of work digging into JSI by asking around in GitHub issues and other channels, paving the way for the rest of us.
241 |
242 | Thanks also to [Oscar Franco](https://github.com/ospfranco) for his JSI guides (e.g. [this one](https://ospfranco.com/post/2021/02/24/how-to-create-a-javascript-jsi-module/)) and [starter template](https://github.com/ospfranco/react-native-jsi-template).
243 |
244 | I also got a lot of mileage out of Ammar Ahmed's [JSI guide](https://blog.notesnook.com/getting-started-react-native-jsi/), too – well worth a read.
245 |
246 | Thank you to [Takuya Matsuyama](https://github.com/craftzdog) too, for his very minimal [react-native-quick-base64](https://github.com/craftzdog/react-native-quick-base64) JSI module, and for being one of the first community members to jump into the ring to wrestle with JSI.
247 |
248 | ## License
249 |
250 | MIT
251 |
--------------------------------------------------------------------------------
/android/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | set (CMAKE_VERBOSE_MAKEFILE ON)
4 | set (CMAKE_CXX_STANDARD 11)
5 |
6 | add_library(cpp
7 | SHARED
8 | ../cpp/example.cpp
9 | cpp-adapter.cpp
10 | )
11 |
12 | # Specifies a path to native header files.
13 | include_directories(
14 | ../cpp
15 | )
16 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | if (project == rootProject) {
3 | repositories {
4 | google()
5 | mavenCentral()
6 | jcenter()
7 | }
8 |
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.5.3'
11 | }
12 | }
13 | }
14 |
15 | apply plugin: 'com.android.library'
16 |
17 | def safeExtGet(prop, fallback) {
18 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
19 | }
20 |
21 | android {
22 | compileSdkVersion safeExtGet('ObjcRuntime_compileSdkVersion', 29)
23 | defaultConfig {
24 | minSdkVersion safeExtGet('ObjcRuntime_minSdkVersion', 16)
25 | targetSdkVersion safeExtGet('ObjcRuntime_targetSdkVersion', 29)
26 | versionCode 1
27 | versionName "1.0"
28 |
29 | externalNativeBuild {
30 | cmake {
31 | cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
32 | abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
33 | }
34 | }
35 |
36 | }
37 |
38 | externalNativeBuild {
39 | cmake {
40 | path "CMakeLists.txt"
41 | }
42 | }
43 |
44 | buildTypes {
45 | release {
46 | minifyEnabled false
47 | }
48 | }
49 | lintOptions {
50 | disable 'GradleCompatible'
51 | }
52 | compileOptions {
53 | sourceCompatibility JavaVersion.VERSION_1_8
54 | targetCompatibility JavaVersion.VERSION_1_8
55 | }
56 | }
57 |
58 | repositories {
59 | mavenLocal()
60 | maven {
61 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
62 | url("$rootDir/../node_modules/react-native/android")
63 | }
64 | google()
65 | mavenCentral()
66 | jcenter()
67 | }
68 |
69 | dependencies {
70 | //noinspection GradleDynamicVersion
71 | implementation "com.facebook.react:react-native:+" // From node_modules
72 | }
73 |
--------------------------------------------------------------------------------
/android/cpp-adapter.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "example.h"
3 |
4 | extern "C"
5 | JNIEXPORT jint JNICALL
6 | Java_com_reactnativeobjcruntime_ObjcRuntimeModule_nativeMultiply(JNIEnv *env, jclass type, jint a, jint b) {
7 | return example::multiply(a, b);
8 | }
9 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/android/src/main/java/com/reactnativeobjcruntime/ObjcRuntimeModule.java:
--------------------------------------------------------------------------------
1 | package com.reactnativeobjcruntime;
2 |
3 | import androidx.annotation.NonNull;
4 |
5 | import com.facebook.react.bridge.Promise;
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
8 | import com.facebook.react.bridge.ReactMethod;
9 | import com.facebook.react.module.annotations.ReactModule;
10 |
11 | @ReactModule(name = ObjcRuntimeModule.NAME)
12 | public class ObjcRuntimeModule extends ReactContextBaseJavaModule {
13 | public static final String NAME = "ObjcRuntime";
14 |
15 | public ObjcRuntimeModule(ReactApplicationContext reactContext) {
16 | super(reactContext);
17 | }
18 |
19 | @Override
20 | @NonNull
21 | public String getName() {
22 | return NAME;
23 | }
24 |
25 | static {
26 | try {
27 | // Used to load the 'native-lib' library on application startup.
28 | System.loadLibrary("cpp");
29 | } catch (Exception ignored) {
30 | }
31 | }
32 |
33 | // Example method
34 | // See https://reactnative.dev/docs/native-modules-android
35 | @ReactMethod
36 | public void multiply(int a, int b, Promise promise) {
37 | promise.resolve(nativeMultiply(a, b));
38 | }
39 |
40 | public static native int nativeMultiply(int a, int b);
41 | }
42 |
--------------------------------------------------------------------------------
/android/src/main/java/com/reactnativeobjcruntime/ObjcRuntimePackage.java:
--------------------------------------------------------------------------------
1 | package com.reactnativeobjcruntime;
2 |
3 | import androidx.annotation.NonNull;
4 |
5 | import com.facebook.react.ReactPackage;
6 | import com.facebook.react.bridge.NativeModule;
7 | import com.facebook.react.bridge.ReactApplicationContext;
8 | import com.facebook.react.uimanager.ViewManager;
9 |
10 | import java.util.ArrayList;
11 | import java.util.Collections;
12 | import java.util.List;
13 |
14 | public class ObjcRuntimePackage implements ReactPackage {
15 | @NonNull
16 | @Override
17 | public List createNativeModules(@NonNull ReactApplicationContext reactContext) {
18 | List modules = new ArrayList<>();
19 | modules.add(new ObjcRuntimeModule(reactContext));
20 | return modules;
21 | }
22 |
23 | @NonNull
24 | @Override
25 | public List createViewManagers(@NonNull ReactApplicationContext reactContext) {
26 | return Collections.emptyList();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ['module:metro-react-native-babel-preset'],
3 | };
4 |
--------------------------------------------------------------------------------
/example/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "overrides": [
3 | {
4 | "files": ["*.ts", "*.tsx"],
5 | "rules": {
6 | "no-undef": "off"
7 | }
8 | }
9 | ]
10 | }
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 |
3 | import com.android.build.OutputFile
4 |
5 | /**
6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7 | * and bundleReleaseJsAndAssets).
8 | * These basically call `react-native bundle` with the correct arguments during the Android build
9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10 | * bundle directly from the development server. Below you can see all the possible configurations
11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the
12 | * `apply from: "../../node_modules/react-native/react.gradle"` line.
13 | *
14 | * project.ext.react = [
15 | * // the name of the generated asset file containing your JS bundle
16 | * bundleAssetName: "index.android.bundle",
17 | *
18 | * // the entry file for bundle generation
19 | * entryFile: "index.android.js",
20 | *
21 | * // https://reactnative.dev/docs/performance#enable-the-ram-format
22 | * bundleCommand: "ram-bundle",
23 | *
24 | * // whether to bundle JS and assets in debug mode
25 | * bundleInDebug: false,
26 | *
27 | * // whether to bundle JS and assets in release mode
28 | * bundleInRelease: true,
29 | *
30 | * // whether to bundle JS and assets in another build variant (if configured).
31 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
32 | * // The configuration property can be in the following formats
33 | * // 'bundleIn${productFlavor}${buildType}'
34 | * // 'bundleIn${buildType}'
35 | * // bundleInFreeDebug: true,
36 | * // bundleInPaidRelease: true,
37 | * // bundleInBeta: true,
38 | *
39 | * // whether to disable dev mode in custom build variants (by default only disabled in release)
40 | * // for ObjcRuntimeExample: to disable dev mode in the staging build type (if configured)
41 | * devDisabledInStaging: true,
42 | * // The configuration property can be in the following formats
43 | * // 'devDisabledIn${productFlavor}${buildType}'
44 | * // 'devDisabledIn${buildType}'
45 | *
46 | * // the root of your project, i.e. where "package.json" lives
47 | * root: "../../",
48 | *
49 | * // where to put the JS bundle asset in debug mode
50 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
51 | *
52 | * // where to put the JS bundle asset in release mode
53 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
54 | *
55 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
56 | * // require('./image.png')), in debug mode
57 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
58 | *
59 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
60 | * // require('./image.png')), in release mode
61 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
62 | *
63 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
64 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
65 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle
66 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
67 | * // for ObjcRuntimeExample, you might want to remove it from here.
68 | * inputExcludes: ["android/**", "ios/**"],
69 | *
70 | * // override which node gets called and with what additional arguments
71 | * nodeExecutableAndArgs: ["node"],
72 | *
73 | * // supply additional arguments to the packager
74 | * extraPackagerArgs: []
75 | * ]
76 | */
77 |
78 | project.ext.react = [
79 | enableHermes: false, // clean and rebuild if changing
80 | entryFile: "index.tsx",
81 | ]
82 |
83 | apply from: "../../node_modules/react-native/react.gradle"
84 |
85 | /**
86 | * Set this to true to create two separate APKs instead of one:
87 | * - An APK that only works on ARM devices
88 | * - An APK that only works on x86 devices
89 | * The advantage is the size of the APK is reduced by about 4MB.
90 | * Upload all the APKs to the Play Store and people will download
91 | * the correct one based on the CPU architecture of their device.
92 | */
93 | def enableSeparateBuildPerCPUArchitecture = false
94 |
95 | /**
96 | * Run Proguard to shrink the Java bytecode in release builds.
97 | */
98 | def enableProguardInReleaseBuilds = false
99 |
100 | /**
101 | * The preferred build flavor of JavaScriptCore.
102 | *
103 | * For ObjcRuntimeExample, to use the international variant, you can use:
104 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105 | *
106 | * The international variant includes ICU i18n library and necessary data
107 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
108 | * give correct results when using with locales other than en-US. Note that
109 | * this variant is about 6MiB larger per architecture than default.
110 | */
111 | def jscFlavor = 'org.webkit:android-jsc:+'
112 |
113 | /**
114 | * Whether to enable the Hermes VM.
115 | *
116 | * This should be set on project.ext.react and mirrored here. If it is not set
117 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118 | * and the benefits of using Hermes will therefore be sharply reduced.
119 | */
120 | def enableHermes = project.ext.react.get("enableHermes", false);
121 |
122 | android {
123 | compileSdkVersion rootProject.ext.compileSdkVersion
124 |
125 | compileOptions {
126 | sourceCompatibility JavaVersion.VERSION_1_8
127 | targetCompatibility JavaVersion.VERSION_1_8
128 | }
129 |
130 | defaultConfig {
131 | applicationId "com.example.reactnativeobjcruntime"
132 | minSdkVersion rootProject.ext.minSdkVersion
133 | targetSdkVersion rootProject.ext.targetSdkVersion
134 | versionCode 1
135 | versionName "1.0"
136 | }
137 | splits {
138 | abi {
139 | reset()
140 | enable enableSeparateBuildPerCPUArchitecture
141 | universalApk false // If true, also generate a universal APK
142 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
143 | }
144 | }
145 | signingConfigs {
146 | debug {
147 | storeFile file('debug.keystore')
148 | storePassword 'android'
149 | keyAlias 'androiddebugkey'
150 | keyPassword 'android'
151 | }
152 | }
153 | buildTypes {
154 | debug {
155 | signingConfig signingConfigs.debug
156 | }
157 | release {
158 | // Caution! In production, you need to generate your own keystore file.
159 | // see https://reactnative.dev/docs/signed-apk-android.
160 | signingConfig signingConfigs.debug
161 | minifyEnabled enableProguardInReleaseBuilds
162 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
163 | }
164 | }
165 | // applicationVariants are e.g. debug, release
166 | applicationVariants.all { variant ->
167 | variant.outputs.each { output ->
168 | // For each separate APK per architecture, set a unique version code as described here:
169 | // https://developer.android.com/studio/build/configure-apk-splits.html
170 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
171 | def abi = output.getFilter(OutputFile.ABI)
172 | if (abi != null) { // null for the universal-debug, universal-release variants
173 | output.versionCodeOverride =
174 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
175 | }
176 |
177 | }
178 | }
179 | }
180 |
181 | dependencies {
182 | implementation fileTree(dir: "libs", include: ["*.jar"])
183 | //noinspection GradleDynamicVersion
184 | implementation "com.facebook.react:react-native:+" // From node_modules
185 |
186 |
187 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
188 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
189 | exclude group:'com.facebook.fbjni'
190 | }
191 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
192 | exclude group:'com.facebook.flipper'
193 | exclude group:'com.squareup.okhttp3', module:'okhttp'
194 | }
195 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
196 | exclude group:'com.facebook.flipper'
197 | }
198 |
199 | if (enableHermes) {
200 | def hermesPath = "../../node_modules/hermes-engine/android/";
201 | debugImplementation files(hermesPath + "hermes-debug.aar")
202 | releaseImplementation files(hermesPath + "hermes-release.aar")
203 | } else {
204 | implementation jscFlavor
205 | }
206 |
207 | implementation project(':reactnativeobjcruntime')
208 | }
209 |
210 | // Run this once to be able to run the application with BUCK
211 | // puts all compile dependencies into folder libs for BUCK to use
212 | task copyDownloadableDepsToLibs(type: Copy) {
213 | from configurations.compile
214 | into 'libs'
215 | }
216 |
217 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
218 |
--------------------------------------------------------------------------------
/example/android/app/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shirakaba/react-native-native-runtime/2d1d04ef32dd23643594a3cb4179e59897fc1725/example/android/app/debug.keystore
--------------------------------------------------------------------------------
/example/android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/java/com/example/reactnativeobjcruntime/ReactNativeFlipper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | *