├── .editorconfig
├── .gitattributes
├── .github
├── actions
│ └── setup
│ │ └── action.yml
└── workflows
│ └── ci.yml
├── .gitignore
├── .nvmrc
├── .watchmanconfig
├── .yarn
├── plugins
│ └── @yarnpkg
│ │ ├── plugin-interactive-tools.cjs
│ │ └── plugin-workspace-tools.cjs
└── releases
│ └── yarn-3.6.1.cjs
├── .yarnrc.yml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── android
├── build.gradle
├── gradle.properties
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── AndroidManifestNew.xml
│ └── java
│ └── com
│ └── webworker
│ ├── WebWorkerModule.kt
│ └── WebWorkerPackage.kt
├── babel.config.js
├── example
├── .bundle
│ └── config
├── .watchmanconfig
├── Gemfile
├── Gemfile.lock
├── README.md
├── android
│ ├── app
│ │ ├── build.gradle
│ │ ├── debug.keystore
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ ├── debug
│ │ │ └── AndroidManifest.xml
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ └── webworker
│ │ │ │ └── example
│ │ │ │ ├── MainActivity.kt
│ │ │ │ └── MainApplication.kt
│ │ │ └── res
│ │ │ ├── drawable
│ │ │ └── rn_edit_text_material.xml
│ │ │ ├── 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.js
├── ios
│ ├── .xcode.env
│ ├── File.swift
│ ├── Podfile
│ ├── Podfile.lock
│ ├── WebworkerExample-Bridging-Header.h
│ ├── WebworkerExample.xcodeproj
│ │ ├── project.pbxproj
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── WebworkerExample.xcscheme
│ ├── WebworkerExample.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ ├── WebworkerExample
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.mm
│ │ ├── Images.xcassets
│ │ │ ├── AppIcon.appiconset
│ │ │ │ └── Contents.json
│ │ │ └── Contents.json
│ │ ├── Info.plist
│ │ ├── LaunchScreen.storyboard
│ │ ├── PrivacyInfo.xcprivacy
│ │ └── main.m
│ └── WebworkerExampleTests
│ │ ├── Info.plist
│ │ └── WebworkerExampleTests.m
├── jest.config.js
├── metro.config.js
├── package.json
├── react-native.config.js
├── src
│ └── App.tsx
├── worker-light.js
└── worker-react-native.js
├── ios
├── RNWWEnvironment.h
├── RNWWEnvironmentBridge.h
├── RNWWEnvironmentBridge.mm
├── RNWWEnvironmentLight.h
├── RNWWEnvironmentLight.mm
├── RNWWSelf.h
├── RNWWSelf.mm
├── RNWWWebWorker.h
├── RNWWWebWorker.mm
└── Webworker.xcodeproj
│ └── project.pbxproj
├── lefthook.yml
├── package.json
├── react-native-web-worker.podspec
├── src
├── NativeSelf.ts
├── NativeWebWorker.ts
├── WebWorker.ts
├── index.ts
└── self.ts
├── tsconfig.build.json
├── tsconfig.json
├── turbo.json
└── yarn.lock
/.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
--------------------------------------------------------------------------------
/.github/actions/setup/action.yml:
--------------------------------------------------------------------------------
1 | name: Setup
2 | description: Setup Node.js and install dependencies
3 |
4 | runs:
5 | using: composite
6 | steps:
7 | - name: Setup Node.js
8 | uses: actions/setup-node@v3
9 | with:
10 | node-version-file: .nvmrc
11 |
12 | - name: Cache dependencies
13 | id: yarn-cache
14 | uses: actions/cache@v3
15 | with:
16 | path: |
17 | **/node_modules
18 | .yarn/install-state.gz
19 | key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }}
20 | restore-keys: |
21 | ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
22 | ${{ runner.os }}-yarn-
23 |
24 | - name: Install dependencies
25 | if: steps.yarn-cache.outputs.cache-hit != 'true'
26 | run: yarn install --immutable
27 | shell: bash
28 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on:
3 | push:
4 | branches:
5 | - main
6 | pull_request:
7 | branches:
8 | - main
9 | merge_group:
10 | types:
11 | - checks_requested
12 |
13 | jobs:
14 | lint:
15 | runs-on: ubuntu-latest
16 | steps:
17 | - name: Checkout
18 | uses: actions/checkout@v3
19 |
20 | - name: Setup
21 | uses: ./.github/actions/setup
22 |
23 | - name: Lint files
24 | run: yarn lint
25 |
26 | - name: Typecheck files
27 | run: yarn typecheck
28 |
29 | test:
30 | runs-on: ubuntu-latest
31 | steps:
32 | - name: Checkout
33 | uses: actions/checkout@v3
34 |
35 | - name: Setup
36 | uses: ./.github/actions/setup
37 |
38 | - name: Run unit tests
39 | run: yarn test --maxWorkers=2 --coverage
40 |
41 | build-library:
42 | runs-on: ubuntu-latest
43 | steps:
44 | - name: Checkout
45 | uses: actions/checkout@v3
46 |
47 | - name: Setup
48 | uses: ./.github/actions/setup
49 |
50 | - name: Build package
51 | run: yarn prepare
52 |
53 | build-android:
54 | runs-on: ubuntu-latest
55 | env:
56 | TURBO_CACHE_DIR: .turbo/android
57 | steps:
58 | - name: Checkout
59 | uses: actions/checkout@v3
60 |
61 | - name: Setup
62 | uses: ./.github/actions/setup
63 |
64 | - name: Cache turborepo for Android
65 | uses: actions/cache@v3
66 | with:
67 | path: ${{ env.TURBO_CACHE_DIR }}
68 | key: ${{ runner.os }}-turborepo-android-${{ hashFiles('yarn.lock') }}
69 | restore-keys: |
70 | ${{ runner.os }}-turborepo-android-
71 |
72 | - name: Check turborepo cache for Android
73 | run: |
74 | TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
75 |
76 | if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
77 | echo "turbo_cache_hit=1" >> $GITHUB_ENV
78 | fi
79 |
80 | - name: Install JDK
81 | if: env.turbo_cache_hit != 1
82 | uses: actions/setup-java@v3
83 | with:
84 | distribution: 'zulu'
85 | java-version: '17'
86 |
87 | - name: Finalize Android SDK
88 | if: env.turbo_cache_hit != 1
89 | run: |
90 | /bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
91 |
92 | - name: Cache Gradle
93 | if: env.turbo_cache_hit != 1
94 | uses: actions/cache@v3
95 | with:
96 | path: |
97 | ~/.gradle/wrapper
98 | ~/.gradle/caches
99 | key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
100 | restore-keys: |
101 | ${{ runner.os }}-gradle-
102 |
103 | - name: Build example for Android
104 | env:
105 | JAVA_OPTS: "-XX:MaxHeapSize=6g"
106 | run: |
107 | yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
108 |
109 | build-ios:
110 | runs-on: macos-14
111 | env:
112 | TURBO_CACHE_DIR: .turbo/ios
113 | steps:
114 | - name: Checkout
115 | uses: actions/checkout@v3
116 |
117 | - name: Setup
118 | uses: ./.github/actions/setup
119 |
120 | - name: Cache turborepo for iOS
121 | uses: actions/cache@v3
122 | with:
123 | path: ${{ env.TURBO_CACHE_DIR }}
124 | key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }}
125 | restore-keys: |
126 | ${{ runner.os }}-turborepo-ios-
127 |
128 | - name: Check turborepo cache for iOS
129 | run: |
130 | TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
131 |
132 | if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
133 | echo "turbo_cache_hit=1" >> $GITHUB_ENV
134 | fi
135 |
136 | - name: Cache cocoapods
137 | if: env.turbo_cache_hit != 1
138 | id: cocoapods-cache
139 | uses: actions/cache@v3
140 | with:
141 | path: |
142 | **/ios/Pods
143 | key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
144 | restore-keys: |
145 | ${{ runner.os }}-cocoapods-
146 |
147 | - name: Install cocoapods
148 | if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
149 | run: |
150 | cd example/ios
151 | pod install
152 | env:
153 | NO_FLIPPER: 1
154 |
155 | - name: Build example for iOS
156 | run: |
157 | yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
158 |
--------------------------------------------------------------------------------
/.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 | # Ruby
48 | example/vendor/
49 |
50 | # node.js
51 | #
52 | node_modules/
53 | npm-debug.log
54 | yarn-debug.log
55 | yarn-error.log
56 |
57 | # BUCK
58 | buck-out/
59 | \.buckd/
60 | android/app/libs
61 | android/keystores/debug.keystore
62 |
63 | # Yarn
64 | .yarn/*
65 | !.yarn/patches
66 | !.yarn/plugins
67 | !.yarn/releases
68 | !.yarn/sdks
69 | !.yarn/versions
70 |
71 | # Expo
72 | .expo/
73 |
74 | # Turborepo
75 | .turbo/
76 |
77 | # generated by bob
78 | lib/
79 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | v18
2 |
--------------------------------------------------------------------------------
/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/.yarnrc.yml:
--------------------------------------------------------------------------------
1 | nodeLinker: node-modules
2 | nmHoistingLimits: workspaces
3 |
4 | plugins:
5 | - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
6 | spec: "@yarnpkg/plugin-interactive-tools"
7 | - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
8 | spec: "@yarnpkg/plugin-workspace-tools"
9 |
10 | yarnPath: .yarn/releases/yarn-3.6.1.cjs
11 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 |
2 | # Contributor Covenant Code of Conduct
3 |
4 | ## Our Pledge
5 |
6 | We as members, contributors, and leaders pledge to make participation in our
7 | community a harassment-free experience for everyone, regardless of age, body
8 | size, visible or invisible disability, ethnicity, sex characteristics, gender
9 | identity and expression, level of experience, education, socio-economic status,
10 | nationality, personal appearance, race, caste, color, religion, or sexual
11 | identity and orientation.
12 |
13 | We pledge to act and interact in ways that contribute to an open, welcoming,
14 | diverse, inclusive, and healthy community.
15 |
16 | ## Our Standards
17 |
18 | Examples of behavior that contributes to a positive environment for our
19 | community include:
20 |
21 | * Demonstrating empathy and kindness toward other people
22 | * Being respectful of differing opinions, viewpoints, and experiences
23 | * Giving and gracefully accepting constructive feedback
24 | * Accepting responsibility and apologizing to those affected by our mistakes,
25 | and learning from the experience
26 | * Focusing on what is best not just for us as individuals, but for the overall
27 | community
28 |
29 | Examples of unacceptable behavior include:
30 |
31 | * The use of sexualized language or imagery, and sexual attention or advances of
32 | any kind
33 | * Trolling, insulting or derogatory comments, and personal or political attacks
34 | * Public or private harassment
35 | * Publishing others' private information, such as a physical or email address,
36 | without their explicit permission
37 | * Other conduct which could reasonably be considered inappropriate in a
38 | professional setting
39 |
40 | ## Enforcement Responsibilities
41 |
42 | Community leaders are responsible for clarifying and enforcing our standards of
43 | acceptable behavior and will take appropriate and fair corrective action in
44 | response to any behavior that they deem inappropriate, threatening, offensive,
45 | or harmful.
46 |
47 | Community leaders have the right and responsibility to remove, edit, or reject
48 | comments, commits, code, wiki edits, issues, and other contributions that are
49 | not aligned to this Code of Conduct, and will communicate reasons for moderation
50 | decisions when appropriate.
51 |
52 | ## Scope
53 |
54 | This Code of Conduct applies within all community spaces, and also applies when
55 | an individual is officially representing the community in public spaces.
56 | Examples of representing our community include using an official e-mail address,
57 | posting via an official social media account, or acting as an appointed
58 | representative at an online or offline event.
59 |
60 | ## Enforcement
61 |
62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
63 | reported to the community leaders responsible for enforcement at
64 | [INSERT CONTACT METHOD].
65 | All complaints will be reviewed and investigated promptly and fairly.
66 |
67 | All community leaders are obligated to respect the privacy and security of the
68 | reporter of any incident.
69 |
70 | ## Enforcement Guidelines
71 |
72 | Community leaders will follow these Community Impact Guidelines in determining
73 | the consequences for any action they deem in violation of this Code of Conduct:
74 |
75 | ### 1. Correction
76 |
77 | **Community Impact**: Use of inappropriate language or other behavior deemed
78 | unprofessional or unwelcome in the community.
79 |
80 | **Consequence**: A private, written warning from community leaders, providing
81 | clarity around the nature of the violation and an explanation of why the
82 | behavior was inappropriate. A public apology may be requested.
83 |
84 | ### 2. Warning
85 |
86 | **Community Impact**: A violation through a single incident or series of
87 | actions.
88 |
89 | **Consequence**: A warning with consequences for continued behavior. No
90 | interaction with the people involved, including unsolicited interaction with
91 | those enforcing the Code of Conduct, for a specified period of time. This
92 | includes avoiding interactions in community spaces as well as external channels
93 | like social media. Violating these terms may lead to a temporary or permanent
94 | ban.
95 |
96 | ### 3. Temporary Ban
97 |
98 | **Community Impact**: A serious violation of community standards, including
99 | sustained inappropriate behavior.
100 |
101 | **Consequence**: A temporary ban from any sort of interaction or public
102 | communication with the community for a specified period of time. No public or
103 | private interaction with the people involved, including unsolicited interaction
104 | with those enforcing the Code of Conduct, is allowed during this period.
105 | Violating these terms may lead to a permanent ban.
106 |
107 | ### 4. Permanent Ban
108 |
109 | **Community Impact**: Demonstrating a pattern of violation of community
110 | standards, including sustained inappropriate behavior, harassment of an
111 | individual, or aggression toward or disparagement of classes of individuals.
112 |
113 | **Consequence**: A permanent ban from any sort of public interaction within the
114 | community.
115 |
116 | ## Attribution
117 |
118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119 | version 2.1, available at
120 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
121 |
122 | Community Impact Guidelines were inspired by
123 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124 |
125 | For answers to common questions about this code of conduct, see the FAQ at
126 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
127 | [https://www.contributor-covenant.org/translations][translations].
128 |
129 | [homepage]: https://www.contributor-covenant.org
130 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
131 | [Mozilla CoC]: https://github.com/mozilla/diversity
132 | [FAQ]: https://www.contributor-covenant.org/faq
133 | [translations]: https://www.contributor-covenant.org/translations
134 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are always welcome, no matter how large or small!
4 |
5 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md).
6 |
7 | ## Development workflow
8 |
9 | This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/features/workspaces). It contains the following packages:
10 |
11 | - The library package in the root directory.
12 | - An example app in the `example/` directory.
13 |
14 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
15 |
16 | ```sh
17 | yarn
18 | ```
19 |
20 | > Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
21 |
22 | The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.
23 |
24 | It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.
25 |
26 | If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/WebWorkerExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-web-worker`.
27 |
28 | To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-web-worker` under `Android`.
29 |
30 | You can use various commands from the root directory to work with the project.
31 |
32 | To start the packager:
33 |
34 | ```sh
35 | yarn example start
36 | ```
37 |
38 | To run the example app on Android:
39 |
40 | ```sh
41 | yarn example android
42 | ```
43 |
44 | To run the example app on iOS:
45 |
46 | ```sh
47 | yarn example ios
48 | ```
49 |
50 | Make sure your code passes TypeScript and ESLint. Run the following to verify:
51 |
52 | ```sh
53 | yarn typecheck
54 | yarn lint
55 | ```
56 |
57 | To fix formatting errors, run the following:
58 |
59 | ```sh
60 | yarn lint --fix
61 | ```
62 |
63 | Remember to add tests for your change if possible. Run the unit tests by:
64 |
65 | ```sh
66 | yarn test
67 | ```
68 |
69 | ### Commit message convention
70 |
71 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
72 |
73 | - `fix`: bug fixes, e.g. fix crash due to deprecated method.
74 | - `feat`: new features, e.g. add new method to the module.
75 | - `refactor`: code refactor, e.g. migrate from class components to hooks.
76 | - `docs`: changes into documentation, e.g. add usage example for the module..
77 | - `test`: adding or updating tests, e.g. add integration tests using detox.
78 | - `chore`: tooling changes, e.g. change CI config.
79 |
80 | Our pre-commit hooks verify that your commit message matches this format when committing.
81 |
82 | ### Linting and tests
83 |
84 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
85 |
86 | 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.
87 |
88 | Our pre-commit hooks verify that the linter and tests pass when committing.
89 |
90 | ### Publishing to npm
91 |
92 | 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.
93 |
94 | To publish new versions, run the following:
95 |
96 | ```sh
97 | yarn release
98 | ```
99 |
100 | ### Scripts
101 |
102 | The `package.json` file contains various scripts for common tasks:
103 |
104 | - `yarn`: setup project by installing dependencies.
105 | - `yarn typecheck`: type-check files with TypeScript.
106 | - `yarn lint`: lint files with ESLint.
107 | - `yarn test`: run unit tests with Jest.
108 | - `yarn example start`: start the Metro server for the example app.
109 | - `yarn example android`: run the example app on Android.
110 | - `yarn example ios`: run the example app on iOS.
111 |
112 | ### Sending a pull request
113 |
114 | > **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).
115 |
116 | When you're sending a pull request:
117 |
118 | - Prefer small pull requests focused on one change.
119 | - Verify that linters and tests are passing.
120 | - Review the documentation to make sure it looks good.
121 | - Follow the pull request template when opening a pull request.
122 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
123 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Jacob Parker
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-webworker
2 |
3 |
4 |
5 | [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) for React Native
6 |
7 | Work based off [react-native-threads](https://github.com/joltup/react-native-threads)
8 |
9 | ~~Supports the new architecture~~, using either [Hermes](https://hermesengine.dev) or JavaScriptCore
10 |
11 | Currently only supports iOS
12 |
13 | ## Usage
14 |
15 | ```
16 | npm install @jacobp100/react-native-webworker
17 | (cd ios; bundle exec pod install)
18 | ```
19 |
20 | In your application code (React components, etc.):
21 |
22 | ```js
23 | import { WebWorker } from '@jacobp100/react-native-webworker';
24 |
25 | // Start a new react native JS process
26 | // The worker JS file has to be at the top level (where the package.json is)
27 | // But you can call it anything you want - and have multiple
28 | const worker = new WebWorker('/worker.js');
29 |
30 | // Send a message, strings only
31 | worker.postMessage('hello');
32 |
33 | // Listen for messages
34 | worker.onmessage = (e) => console.log(e.data);
35 |
36 | // Listen for errors
37 | worker.onerror = (e) => console.log(e.message);
38 |
39 | // Stop the JS process
40 | worker.terminate();
41 | ```
42 |
43 | In your thread code (dedicated file such as `worker.js`):
44 |
45 | ```js
46 | import { self } from 'react-native-threads';
47 |
48 | // Listen for messages
49 | self.onmessage = (e) => {
50 | // Message is a string
51 | const message = e.data;
52 | };
53 |
54 | // Send a message, strings only
55 | self.postMessage('hello');
56 | ```
57 |
58 | ## Thread Lifecycle
59 |
60 | - Threads are paused when the app enters in the background
61 | - Threads are resumed once the app is running in the foreground
62 | - During development, when you reload the main JS bundle (shake device -> `Reload`) the threads are killed
63 |
64 | ## Debugging
65 |
66 | Instantiating Threads creates multiple react native JS processes and can make debugging remotely behave unpredictably. I recommend using a third party debugging tool like [Reactotron](https://github.com/infinitered/reactotron) to aid with this. Each process, including your main application as well as your thread code can connect to Reactotron and log debugging messages.
67 |
68 | ## Building for Release
69 |
70 | Depending on if you're using [Hermes](https://hermesengine.dev) (the default) or JavaScript Core, the commands differ. For iOS, the commands you'll need to add are:-
71 |
72 | ```bash
73 | # Bundle your worker JS
74 | npx react-native bundle --dev false --assets-dest ./ios --entry-file worker.js --platform ios --bundle-output ./ios/worker.jsbundle
75 | ```
76 |
77 | ##### Hermes
78 |
79 | If you're using Hermes, you'll also need to add the following command:-
80 |
81 | ```bash
82 | # Convert bundled JS to Hermes ByteCode
83 | ./ios/Pods/hermes-engine/destroot/bin/hermesc -emit-binary ./ios/worker.jsbundle -out ./ios/worker.jsbundle
84 | ```
85 |
86 | Once you have generated the bundle file in your ios folder, you will also need to add the bundle file to you project in Xcode. In Xcode's file explorer you should see a folder with the same name as your app, containing a `main.jsbundle` file as well as an `AppDelegate.m` file. Right click on that folder and select the 'Add Files to ' option, which will open up finder and allow you to select your `ios/worker.jsbundle` file. You will only need to do this once, and the file will be included in all future builds.
87 |
88 | For convenience I recommend adding these thread building commands as npm scripts to your project.
89 |
90 | ## Optimisations (Experimental)
91 |
92 | By default, you can use most of React Native and it's related infrastructure in your workers. This includes globals like `fetch`, `setTimeout` etc. However, including this makes your worker file about 800kb larger.
93 |
94 | If your worker does not use those globals - maybe it only does heavy computation that would lock the UI thread - you can run the worker using a lighter environment, and get the benefit of a smaller bundle.
95 |
96 | The light environment will use will use either Hermes or JavaScriptCore - depending on what's used in your app.
97 |
98 | When using Hermes, JS exceptions are caught and reported, but the message cannot (yet) be recovered, and are always reported as _Unknown error_.
99 |
100 | ```js
101 | import { WebWorker } from '@jacobp100/react-native-webworker';
102 |
103 | const worker = new WebWorker('path/to/worker.js', {
104 | environment: 'light',
105 | });
106 | ```
107 |
108 | In your worker, **do not import react-native or any react-native related packages** - it'll cause a crash. The `self` variable is exposed as a global.
109 |
110 | ```js
111 | self.onmessage = (e) => {
112 | self.postMessage(`Hello ${e.data}`);
113 | };
114 | ```
115 |
116 | ## Infinite Loops
117 |
118 | If you're using JavaScriptCore, there is no mechanism to terminate currently executing code. This means if your worker code goes into an infinite loop, calling `worker.terminate()` will not stop the execution.
119 |
120 | Hermes does support this, and will do so automatically in development builds, but needs additional setup for release builds. In your build command, you'll need to add the `-emit-async-break-check` to the hermes compile command.
121 |
122 | ```diff
123 | -./ios/Pods/hermes-engine/destroot/bin/hermesc -emit-binary ./ios/worker.jsbundle -out ./ios/worker.jsbundle
124 | +./ios/Pods/hermes-engine/destroot/bin/hermesc -emit-binary -emit-async-break-check ./ios/worker.jsbundle -out ./ios/worker.jsbundle
125 | ```
126 |
127 | In the case you are terminating the worker only to stop long running code, and intend on re-initializing the worker afterwards, you can skip some steps and just abort just the long running code, leaving the worker otherwise in-tact. This saves the need to re-parse the JavaScript and re-initialize the worker. Be cautious when doing this - you must be consider any global state in your worker, and if terminating half way through will cause correctness issues.
128 |
129 | If this scenario is suitable for your use-case, you can call `worker.terminate({ mode: 'execution' })`. This will call the `onerror` handler. You can continue to call `worker.postMessage`, and you do not need to wait for the `onerror` handler to fire.
130 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3 | def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["WebWorker_kotlinVersion"]
4 |
5 | repositories {
6 | google()
7 | mavenCentral()
8 | }
9 |
10 | dependencies {
11 | classpath "com.android.tools.build:gradle:7.2.1"
12 | // noinspection DifferentKotlinGradleVersion
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 | }
15 | }
16 |
17 | def reactNativeArchitectures() {
18 | def value = rootProject.getProperties().get("reactNativeArchitectures")
19 | return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
20 | }
21 |
22 | def isNewArchitectureEnabled() {
23 | return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
24 | }
25 |
26 | apply plugin: "com.android.library"
27 | apply plugin: "kotlin-android"
28 |
29 | if (isNewArchitectureEnabled()) {
30 | apply plugin: "com.facebook.react"
31 | }
32 |
33 | def getExtOrDefault(name) {
34 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["WebWorker_" + name]
35 | }
36 |
37 | def getExtOrIntegerDefault(name) {
38 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["WebWorker_" + name]).toInteger()
39 | }
40 |
41 | def supportsNamespace() {
42 | def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
43 | def major = parsed[0].toInteger()
44 | def minor = parsed[1].toInteger()
45 |
46 | // Namespace support was added in 7.3.0
47 | return (major == 7 && minor >= 3) || major >= 8
48 | }
49 |
50 | android {
51 | if (supportsNamespace()) {
52 | namespace "com.webworker"
53 |
54 | sourceSets {
55 | main {
56 | manifest.srcFile "src/main/AndroidManifestNew.xml"
57 | }
58 | }
59 | }
60 |
61 | compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
62 |
63 | defaultConfig {
64 | minSdkVersion getExtOrIntegerDefault("minSdkVersion")
65 | targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
66 |
67 | }
68 |
69 | buildTypes {
70 | release {
71 | minifyEnabled false
72 | }
73 | }
74 |
75 | lintOptions {
76 | disable "GradleCompatible"
77 | }
78 |
79 | compileOptions {
80 | sourceCompatibility JavaVersion.VERSION_1_8
81 | targetCompatibility JavaVersion.VERSION_1_8
82 | }
83 | }
84 |
85 | repositories {
86 | mavenCentral()
87 | google()
88 | }
89 |
90 | def kotlin_version = getExtOrDefault("kotlinVersion")
91 |
92 | dependencies {
93 | // For < 0.71, this will be from the local maven repo
94 | // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
95 | //noinspection GradleDynamicVersion
96 | implementation "com.facebook.react:react-native:+"
97 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
98 | }
99 |
100 |
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | WebWorker_kotlinVersion=1.7.0
2 | WebWorker_minSdkVersion=21
3 | WebWorker_targetSdkVersion=31
4 | WebWorker_compileSdkVersion=31
5 | WebWorker_ndkversion=21.4.7075529
6 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifestNew.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/android/src/main/java/com/webworker/WebWorkerModule.kt:
--------------------------------------------------------------------------------
1 | package com.webworker
2 |
3 | import com.facebook.react.bridge.ReactApplicationContext
4 | import com.facebook.react.bridge.ReactContextBaseJavaModule
5 | import com.facebook.react.bridge.ReactMethod
6 | import com.facebook.react.bridge.Promise
7 |
8 | class WebWorkerModule(reactContext: ReactApplicationContext) :
9 | ReactContextBaseJavaModule(reactContext) {
10 |
11 | override fun getName(): String {
12 | return NAME
13 | }
14 |
15 | // Example method
16 | // See https://reactnative.dev/docs/native-modules-android
17 | @ReactMethod
18 | fun multiply(a: Double, b: Double, promise: Promise) {
19 | promise.resolve(a * b)
20 | }
21 |
22 | companion object {
23 | const val NAME = "WebWorker"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/android/src/main/java/com/webworker/WebWorkerPackage.kt:
--------------------------------------------------------------------------------
1 | package com.webworker
2 |
3 | import com.facebook.react.ReactPackage
4 | import com.facebook.react.bridge.NativeModule
5 | import com.facebook.react.bridge.ReactApplicationContext
6 | import com.facebook.react.uimanager.ViewManager
7 |
8 |
9 | class WebWorkerPackage : ReactPackage {
10 | override fun createNativeModules(reactContext: ReactApplicationContext): List {
11 | return listOf(WebWorkerModule(reactContext))
12 | }
13 |
14 | override fun createViewManagers(reactContext: ReactApplicationContext): List> {
15 | return emptyList()
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | ['module:react-native-builder-bob/babel-preset', { modules: 'commonjs' }],
4 | ],
5 | };
6 |
--------------------------------------------------------------------------------
/example/.bundle/config:
--------------------------------------------------------------------------------
1 | BUNDLE_PATH: "vendor/bundle"
2 | BUNDLE_FORCE_RUBY_PLATFORM: 1
3 |
--------------------------------------------------------------------------------
/example/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/example/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4 | ruby ">= 2.6.10"
5 |
6 | # Cocoapods 1.15 introduced a bug which break the build. We will remove the upper
7 | # bound in the template on Cocoapods with next React Native release.
8 | gem 'cocoapods', '>= 1.13', '< 1.15'
9 | gem 'activesupport', '>= 6.1.7.5', '< 7.1.0'
10 |
--------------------------------------------------------------------------------
/example/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | CFPropertyList (3.0.7)
5 | base64
6 | nkf
7 | rexml
8 | activesupport (6.1.7.8)
9 | concurrent-ruby (~> 1.0, >= 1.0.2)
10 | i18n (>= 1.6, < 2)
11 | minitest (>= 5.1)
12 | tzinfo (~> 2.0)
13 | zeitwerk (~> 2.3)
14 | addressable (2.8.7)
15 | public_suffix (>= 2.0.2, < 7.0)
16 | algoliasearch (1.27.5)
17 | httpclient (~> 2.8, >= 2.8.3)
18 | json (>= 1.5.1)
19 | atomos (0.1.3)
20 | base64 (0.2.0)
21 | claide (1.1.0)
22 | cocoapods (1.14.3)
23 | addressable (~> 2.8)
24 | claide (>= 1.0.2, < 2.0)
25 | cocoapods-core (= 1.14.3)
26 | cocoapods-deintegrate (>= 1.0.3, < 2.0)
27 | cocoapods-downloader (>= 2.1, < 3.0)
28 | cocoapods-plugins (>= 1.0.0, < 2.0)
29 | cocoapods-search (>= 1.0.0, < 2.0)
30 | cocoapods-trunk (>= 1.6.0, < 2.0)
31 | cocoapods-try (>= 1.1.0, < 2.0)
32 | colored2 (~> 3.1)
33 | escape (~> 0.0.4)
34 | fourflusher (>= 2.3.0, < 3.0)
35 | gh_inspector (~> 1.0)
36 | molinillo (~> 0.8.0)
37 | nap (~> 1.0)
38 | ruby-macho (>= 2.3.0, < 3.0)
39 | xcodeproj (>= 1.23.0, < 2.0)
40 | cocoapods-core (1.14.3)
41 | activesupport (>= 5.0, < 8)
42 | addressable (~> 2.8)
43 | algoliasearch (~> 1.0)
44 | concurrent-ruby (~> 1.1)
45 | fuzzy_match (~> 2.0.4)
46 | nap (~> 1.0)
47 | netrc (~> 0.11)
48 | public_suffix (~> 4.0)
49 | typhoeus (~> 1.0)
50 | cocoapods-deintegrate (1.0.5)
51 | cocoapods-downloader (2.1)
52 | cocoapods-plugins (1.0.0)
53 | nap
54 | cocoapods-search (1.0.1)
55 | cocoapods-trunk (1.6.0)
56 | nap (>= 0.8, < 2.0)
57 | netrc (~> 0.11)
58 | cocoapods-try (1.2.0)
59 | colored2 (3.1.2)
60 | concurrent-ruby (1.3.4)
61 | escape (0.0.4)
62 | ethon (0.16.0)
63 | ffi (>= 1.15.0)
64 | ffi (1.17.0)
65 | fourflusher (2.3.1)
66 | fuzzy_match (2.0.4)
67 | gh_inspector (1.1.3)
68 | httpclient (2.8.3)
69 | i18n (1.14.5)
70 | concurrent-ruby (~> 1.0)
71 | json (2.7.2)
72 | minitest (5.24.1)
73 | molinillo (0.8.0)
74 | nanaimo (0.3.0)
75 | nap (1.1.0)
76 | netrc (0.11.0)
77 | nkf (0.2.0)
78 | public_suffix (4.0.7)
79 | rexml (3.3.5)
80 | strscan
81 | ruby-macho (2.5.1)
82 | strscan (3.1.0)
83 | typhoeus (1.4.1)
84 | ethon (>= 0.9.0)
85 | tzinfo (2.0.6)
86 | concurrent-ruby (~> 1.0)
87 | xcodeproj (1.25.0)
88 | CFPropertyList (>= 2.3.3, < 4.0)
89 | atomos (~> 0.1.3)
90 | claide (>= 1.0.2, < 2.0)
91 | colored2 (~> 3.1)
92 | nanaimo (~> 0.3.0)
93 | rexml (>= 3.3.2, < 4.0)
94 | zeitwerk (2.6.17)
95 |
96 | PLATFORMS
97 | ruby
98 |
99 | DEPENDENCIES
100 | activesupport (>= 6.1.7.5, < 7.1.0)
101 | cocoapods (>= 1.13, < 1.15)
102 |
103 | RUBY VERSION
104 | ruby 2.6.10p210
105 |
106 | BUNDLED WITH
107 | 2.3.25
108 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).
2 |
3 | # Getting Started
4 |
5 | >**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding.
6 |
7 | ## Step 1: Start the Metro Server
8 |
9 | First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native.
10 |
11 | To start Metro, run the following command from the _root_ of your React Native project:
12 |
13 | ```bash
14 | # using npm
15 | npm start
16 |
17 | # OR using Yarn
18 | yarn start
19 | ```
20 |
21 | ## Step 2: Start your Application
22 |
23 | Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app:
24 |
25 | ### For Android
26 |
27 | ```bash
28 | # using npm
29 | npm run android
30 |
31 | # OR using Yarn
32 | yarn android
33 | ```
34 |
35 | ### For iOS
36 |
37 | ```bash
38 | # using npm
39 | npm run ios
40 |
41 | # OR using Yarn
42 | yarn ios
43 | ```
44 |
45 | If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly.
46 |
47 | This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively.
48 |
49 | ## Step 3: Modifying your App
50 |
51 | Now that you have successfully run the app, let's modify it.
52 |
53 | 1. Open `App.tsx` in your text editor of choice and edit some lines.
54 | 2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes!
55 |
56 | For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes!
57 |
58 | ## Congratulations! :tada:
59 |
60 | You've successfully run and modified your React Native App. :partying_face:
61 |
62 | ### Now what?
63 |
64 | - If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps).
65 | - If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started).
66 |
67 | # Troubleshooting
68 |
69 | If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.
70 |
71 | # Learn More
72 |
73 | To learn more about React Native, take a look at the following resources:
74 |
75 | - [React Native Website](https://reactnative.dev) - learn more about React Native.
76 | - [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment.
77 | - [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**.
78 | - [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts.
79 | - [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native.
80 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 | apply plugin: "org.jetbrains.kotlin.android"
3 | apply plugin: "com.facebook.react"
4 |
5 | /**
6 | * This is the configuration block to customize your React Native Android app.
7 | * By default you don't need to apply any configuration, just uncomment the lines you need.
8 | */
9 | react {
10 | /* Folders */
11 | // The root of your project, i.e. where "package.json" lives. Default is '..'
12 | // root = file("../")
13 | // The folder where the react-native NPM package is. Default is ../node_modules/react-native
14 | // reactNativeDir = file("../node_modules/react-native")
15 | // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
16 | // codegenDir = file("../node_modules/@react-native/codegen")
17 | // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
18 | // cliFile = file("../node_modules/react-native/cli.js")
19 |
20 | /* Variants */
21 | // The list of variants to that are debuggable. For those we're going to
22 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
23 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
24 | // debuggableVariants = ["liteDebug", "prodDebug"]
25 |
26 | /* Bundling */
27 | // A list containing the node command and its flags. Default is just 'node'.
28 | // nodeExecutableAndArgs = ["node"]
29 | //
30 | // The command to run when bundling. By default is 'bundle'
31 | // bundleCommand = "ram-bundle"
32 | //
33 | // The path to the CLI configuration file. Default is empty.
34 | // bundleConfig = file(../rn-cli.config.js)
35 | //
36 | // The name of the generated asset file containing your JS bundle
37 | // bundleAssetName = "MyApplication.android.bundle"
38 | //
39 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
40 | // entryFile = file("../js/MyApplication.android.js")
41 | //
42 | // A list of extra flags to pass to the 'bundle' commands.
43 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
44 | // extraPackagerArgs = []
45 |
46 | /* Hermes Commands */
47 | // The hermes compiler command to run. By default it is 'hermesc'
48 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
49 | //
50 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
51 | // hermesFlags = ["-O", "-output-source-map"]
52 | }
53 |
54 | /**
55 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
56 | */
57 | def enableProguardInReleaseBuilds = false
58 |
59 | /**
60 | * The preferred build flavor of JavaScriptCore (JSC)
61 | *
62 | * For example, to use the international variant, you can use:
63 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
64 | *
65 | * The international variant includes ICU i18n library and necessary data
66 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
67 | * give correct results when using with locales other than en-US. Note that
68 | * this variant is about 6MiB larger per architecture than default.
69 | */
70 | def jscFlavor = 'org.webkit:android-jsc:+'
71 |
72 | android {
73 | ndkVersion rootProject.ext.ndkVersion
74 | buildToolsVersion rootProject.ext.buildToolsVersion
75 | compileSdk rootProject.ext.compileSdkVersion
76 |
77 | namespace "webworker.example"
78 | defaultConfig {
79 | applicationId "webworker.example"
80 | minSdkVersion rootProject.ext.minSdkVersion
81 | targetSdkVersion rootProject.ext.targetSdkVersion
82 | versionCode 1
83 | versionName "1.0"
84 | }
85 | signingConfigs {
86 | debug {
87 | storeFile file('debug.keystore')
88 | storePassword 'android'
89 | keyAlias 'androiddebugkey'
90 | keyPassword 'android'
91 | }
92 | }
93 | buildTypes {
94 | debug {
95 | signingConfig signingConfigs.debug
96 | }
97 | release {
98 | // Caution! In production, you need to generate your own keystore file.
99 | // see https://reactnative.dev/docs/signed-apk-android.
100 | signingConfig signingConfigs.debug
101 | minifyEnabled enableProguardInReleaseBuilds
102 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
103 | }
104 | }
105 | }
106 |
107 | dependencies {
108 | // The version of react-native is set by the React Native Gradle Plugin
109 | implementation("com.facebook.react:react-android")
110 |
111 | if (hermesEnabled.toBoolean()) {
112 | implementation("com.facebook.react:hermes-android")
113 | } else {
114 | implementation jscFlavor
115 | }
116 | }
117 |
118 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
119 |
--------------------------------------------------------------------------------
/example/android/app/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/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 |
9 |
10 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/webworker/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package webworker.example
2 |
3 | import com.facebook.react.ReactActivity
4 | import com.facebook.react.ReactActivityDelegate
5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
6 | import com.facebook.react.defaults.DefaultReactActivityDelegate
7 |
8 | class MainActivity : ReactActivity() {
9 |
10 | /**
11 | * Returns the name of the main component registered from JavaScript. This is used to schedule
12 | * rendering of the component.
13 | */
14 | override fun getMainComponentName(): String = "WebWorkerExample"
15 |
16 | /**
17 | * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
18 | * which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
19 | */
20 | override fun createReactActivityDelegate(): ReactActivityDelegate =
21 | DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
22 | }
23 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/webworker/example/MainApplication.kt:
--------------------------------------------------------------------------------
1 | package webworker.example
2 |
3 | import android.app.Application
4 | import com.facebook.react.PackageList
5 | import com.facebook.react.ReactApplication
6 | import com.facebook.react.ReactHost
7 | import com.facebook.react.ReactNativeHost
8 | import com.facebook.react.ReactPackage
9 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
10 | import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
11 | import com.facebook.react.defaults.DefaultReactNativeHost
12 | import com.facebook.soloader.SoLoader
13 |
14 | class MainApplication : Application(), ReactApplication {
15 |
16 | override val reactNativeHost: ReactNativeHost =
17 | object : DefaultReactNativeHost(this) {
18 | override fun getPackages(): List =
19 | PackageList(this).packages.apply {
20 | // Packages that cannot be autolinked yet can be added manually here, for example:
21 | // add(MyReactNativePackage())
22 | }
23 |
24 | override fun getJSMainModuleName(): String = "index"
25 |
26 | override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
27 |
28 | override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
29 | override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
30 | }
31 |
32 | override val reactHost: ReactHost
33 | get() = getDefaultReactHost(applicationContext, reactNativeHost)
34 |
35 | override fun onCreate() {
36 | super.onCreate()
37 | SoLoader.init(this, false)
38 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
39 | // If you opted-in for the New Architecture, we load the native entry point for this app.
40 | load()
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable/rn_edit_text_material.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
22 |
23 |
24 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WebWorkerExample
3 |
4 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | buildToolsVersion = "34.0.0"
4 | minSdkVersion = 23
5 | compileSdkVersion = 34
6 | targetSdkVersion = 34
7 | ndkVersion = "26.1.10909125"
8 | kotlinVersion = "1.9.22"
9 | }
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | dependencies {
15 | classpath("com.android.tools.build:gradle")
16 | classpath("com.facebook.react:react-native-gradle-plugin")
17 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
18 | }
19 | }
20 |
21 | apply plugin: "com.facebook.react.rootproject"
22 |
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | # AndroidX package structure to make it clearer which packages are bundled with the
21 | # Android operating system, and which are packaged with your app's APK
22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
23 | android.useAndroidX=true
24 | # Automatically convert third-party libraries to use AndroidX
25 | android.enableJetifier=false
26 |
27 | # Use this property to specify which architecture you want to build.
28 | # You can also override it from the CLI using
29 | # ./gradlew -PreactNativeArchitectures=x86_64
30 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
31 |
32 | # Use this property to enable support to the new architecture.
33 | # This will allow you to use TurboModules and the Fabric render in
34 | # your application. You should enable this flag either if you want
35 | # to write custom TurboModules/Fabric components OR use libraries that
36 | # are providing them.
37 | newArchEnabled=false
38 |
39 | # Use this property to enable or disable the Hermes JS engine.
40 | # If set to false, you will be using JSC instead.
41 | hermesEnabled=true
42 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jacobp100/react-native-web-worker/87e10c79bf90ad4cc43bc00b0ca2d2961e60b5be/example/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/example/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
88 |
89 | # Use the maximum available, or set MAX_FD != -1 to use that value.
90 | MAX_FD=maximum
91 |
92 | warn () {
93 | echo "$*"
94 | } >&2
95 |
96 | die () {
97 | echo
98 | echo "$*"
99 | echo
100 | exit 1
101 | } >&2
102 |
103 | # OS specific support (must be 'true' or 'false').
104 | cygwin=false
105 | msys=false
106 | darwin=false
107 | nonstop=false
108 | case "$( uname )" in #(
109 | CYGWIN* ) cygwin=true ;; #(
110 | Darwin* ) darwin=true ;; #(
111 | MSYS* | MINGW* ) msys=true ;; #(
112 | NONSTOP* ) nonstop=true ;;
113 | esac
114 |
115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
116 |
117 |
118 | # Determine the Java command to use to start the JVM.
119 | if [ -n "$JAVA_HOME" ] ; then
120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
121 | # IBM's JDK on AIX uses strange locations for the executables
122 | JAVACMD=$JAVA_HOME/jre/sh/java
123 | else
124 | JAVACMD=$JAVA_HOME/bin/java
125 | fi
126 | if [ ! -x "$JAVACMD" ] ; then
127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
128 |
129 | Please set the JAVA_HOME variable in your environment to match the
130 | location of your Java installation."
131 | fi
132 | else
133 | JAVACMD=java
134 | if ! command -v java >/dev/null 2>&1
135 | then
136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 | fi
142 |
143 | # Increase the maximum file descriptors if we can.
144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
145 | case $MAX_FD in #(
146 | max*)
147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
148 | # shellcheck disable=SC2039,SC3045
149 | MAX_FD=$( ulimit -H -n ) ||
150 | warn "Could not query maximum file descriptor limit"
151 | esac
152 | case $MAX_FD in #(
153 | '' | soft) :;; #(
154 | *)
155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
156 | # shellcheck disable=SC2039,SC3045
157 | ulimit -n "$MAX_FD" ||
158 | warn "Could not set maximum file descriptor limit to $MAX_FD"
159 | esac
160 | fi
161 |
162 | # Collect all arguments for the java command, stacking in reverse order:
163 | # * args from the command line
164 | # * the main class name
165 | # * -classpath
166 | # * -D...appname settings
167 | # * --module-path (only if needed)
168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
169 |
170 | # For Cygwin or MSYS, switch paths to Windows format before running java
171 | if "$cygwin" || "$msys" ; then
172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
174 |
175 | JAVACMD=$( cygpath --unix "$JAVACMD" )
176 |
177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
178 | for arg do
179 | if
180 | case $arg in #(
181 | -*) false ;; # don't mess with options #(
182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
183 | [ -e "$t" ] ;; #(
184 | *) false ;;
185 | esac
186 | then
187 | arg=$( cygpath --path --ignore --mixed "$arg" )
188 | fi
189 | # Roll the args list around exactly as many times as the number of
190 | # args, so each arg winds up back in the position where it started, but
191 | # possibly modified.
192 | #
193 | # NB: a `for` loop captures its iteration list before it begins, so
194 | # changing the positional parameters here affects neither the number of
195 | # iterations, nor the values presented in `arg`.
196 | shift # remove old arg
197 | set -- "$@" "$arg" # push replacement arg
198 | done
199 | fi
200 |
201 |
202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204 |
205 | # Collect all arguments for the java command:
206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207 | # and any embedded shellness will be escaped.
208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209 | # treated as '${Hostname}' itself on the command line.
210 |
211 | set -- \
212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
213 | -classpath "$CLASSPATH" \
214 | org.gradle.wrapper.GradleWrapperMain \
215 | "$@"
216 |
217 | # Stop when "xargs" is not available.
218 | if ! command -v xargs >/dev/null 2>&1
219 | then
220 | die "xargs is not available"
221 | fi
222 |
223 | # Use "xargs" to parse quoted args.
224 | #
225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
226 | #
227 | # In Bash we could simply go:
228 | #
229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
230 | # set -- "${ARGS[@]}" "$@"
231 | #
232 | # but POSIX shell has neither arrays nor command substitution, so instead we
233 | # post-process each arg (as a line of input to sed) to backslash-escape any
234 | # character that might be a shell metacharacter, then use eval to reverse
235 | # that process (while maintaining the separation between arguments), and wrap
236 | # the whole thing up as a single "set" statement.
237 | #
238 | # This will of course break if any of these variables contains a newline or
239 | # an unmatched quote.
240 | #
241 |
242 | eval "set -- $(
243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
244 | xargs -n1 |
245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
246 | tr '\n' ' '
247 | )" '"$@"'
248 |
249 | exec "$JAVACMD" "$@"
250 |
--------------------------------------------------------------------------------
/example/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo. 1>&2
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48 | echo. 1>&2
49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50 | echo location of your Java installation. 1>&2
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo. 1>&2
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62 | echo. 1>&2
63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64 | echo location of your Java installation. 1>&2
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'webworker.example'
2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
3 | include ':app'
4 | includeBuild('../node_modules/@react-native/gradle-plugin')
5 |
--------------------------------------------------------------------------------
/example/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "WebWorkerExample",
3 | "displayName": "WebWorkerExample"
4 | }
5 |
--------------------------------------------------------------------------------
/example/babel.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const { getConfig } = require('react-native-builder-bob/babel-config');
3 | const pkg = require('../package.json');
4 |
5 | const root = path.resolve(__dirname, '..');
6 |
7 | module.exports = getConfig(
8 | {
9 | presets: ['module:@react-native/babel-preset'],
10 | },
11 | { root, pkg }
12 | );
13 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | import { AppRegistry } from 'react-native';
2 | import App from './src/App';
3 | import { name as appName } from './app.json';
4 |
5 | AppRegistry.registerComponent(appName, () => App);
6 |
--------------------------------------------------------------------------------
/example/ios/.xcode.env:
--------------------------------------------------------------------------------
1 | # This `.xcode.env` file is versioned and is used to source the environment
2 | # used when running script phases inside Xcode.
3 | # To customize your local environment, you can create an `.xcode.env.local`
4 | # file that is not versioned.
5 |
6 | # NODE_BINARY variable contains the PATH to the node executable.
7 | #
8 | # Customize the NODE_BINARY variable here.
9 | # For example, to use nvm with brew, add the following line
10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use
11 | export NODE_BINARY=$(command -v node)
12 |
--------------------------------------------------------------------------------
/example/ios/File.swift:
--------------------------------------------------------------------------------
1 | //
2 | // File.swift
3 | // WebWorkerExample
4 | //
5 |
6 | import Foundation
7 |
--------------------------------------------------------------------------------
/example/ios/Podfile:
--------------------------------------------------------------------------------
1 | # Resolve react_native_pods.rb with node to allow for hoisting
2 | require Pod::Executable.execute_command('node', ['-p',
3 | 'require.resolve(
4 | "react-native/scripts/react_native_pods.rb",
5 | {paths: [process.argv[1]]},
6 | )', __dir__]).strip
7 |
8 | platform :ios, min_ios_version_supported
9 | prepare_react_native_project!
10 |
11 | linkage = ENV['USE_FRAMEWORKS']
12 | if linkage != nil
13 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
14 | use_frameworks! :linkage => linkage.to_sym
15 | end
16 |
17 | target 'WebWorkerExample' do
18 | config = use_native_modules!
19 |
20 | use_react_native!(
21 | :path => config[:reactNativePath],
22 | # An absolute path to your application root.
23 | :app_path => "#{Pod::Config.instance.installation_root}/.."
24 | )
25 |
26 | target 'WebWorkerExampleTests' do
27 | inherit! :complete
28 | # Pods for testing
29 | end
30 |
31 | post_install do |installer|
32 | # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
33 | react_native_post_install(
34 | installer,
35 | config[:reactNativePath],
36 | :mac_catalyst_enabled => false,
37 | # :ccache_enabled => true
38 | )
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | //
2 | // Use this file to import your target's public headers that you would like to expose to Swift.
3 | //
4 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 54;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 00E356F31AD99517003FC87E /* WebWorkerExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* WebWorkerExampleTests.m */; };
11 | 0C80B921A6F3F58F76C31292 /* libPods-WebWorkerExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-WebWorkerExample.a */; };
12 | 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
13 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
14 | 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
15 | 7699B88040F8A987B510C191 /* libPods-WebWorkerExample-WebWorkerExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-WebWorkerExample-WebWorkerExampleTests.a */; };
16 | 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
17 | B70B766EB16FC794FB8981F5 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 25FE08CE0B0C89DE7F213433 /* PrivacyInfo.xcprivacy */; };
18 | /* End PBXBuildFile section */
19 |
20 | /* Begin PBXContainerItemProxy section */
21 | 00E356F41AD99517003FC87E /* PBXContainerItemProxy */ = {
22 | isa = PBXContainerItemProxy;
23 | containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */;
24 | proxyType = 1;
25 | remoteGlobalIDString = 13B07F861A680F5B00A75B9A;
26 | remoteInfo = WebWorkerExample;
27 | };
28 | /* End PBXContainerItemProxy section */
29 |
30 | /* Begin PBXFileReference section */
31 | 00E356EE1AD99517003FC87E /* WebWorkerExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WebWorkerExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
32 | 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
33 | 00E356F21AD99517003FC87E /* WebWorkerExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WebWorkerExampleTests.m; sourceTree = ""; };
34 | 13B07F961A680F5B00A75B9A /* WebWorkerExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WebWorkerExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
35 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = WebWorkerExample/AppDelegate.h; sourceTree = ""; };
36 | 13B07FB01A68108700A75B9A /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = WebWorkerExample/AppDelegate.mm; sourceTree = ""; };
37 | 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = WebWorkerExample/Images.xcassets; sourceTree = ""; };
38 | 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = WebWorkerExample/Info.plist; sourceTree = ""; };
39 | 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = WebWorkerExample/main.m; sourceTree = ""; };
40 | 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = PrivacyInfo.xcprivacy; path = WebWorkerExample/PrivacyInfo.xcprivacy; sourceTree = ""; };
41 | 19F6CBCC0A4E27FBF8BF4A61 /* libPods-WebWorkerExample-WebWorkerExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WebWorkerExample-WebWorkerExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
42 | 25FE08CE0B0C89DE7F213433 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; name = PrivacyInfo.xcprivacy; path = WebWorkerExample/PrivacyInfo.xcprivacy; sourceTree = ""; };
43 | 3B4392A12AC88292D35C810B /* Pods-WebWorkerExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WebWorkerExample.debug.xcconfig"; path = "Target Support Files/Pods-WebWorkerExample/Pods-WebWorkerExample.debug.xcconfig"; sourceTree = ""; };
44 | 5709B34CF0A7D63546082F79 /* Pods-WebWorkerExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WebWorkerExample.release.xcconfig"; path = "Target Support Files/Pods-WebWorkerExample/Pods-WebWorkerExample.release.xcconfig"; sourceTree = ""; };
45 | 5B7EB9410499542E8C5724F5 /* Pods-WebWorkerExample-WebWorkerExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WebWorkerExample-WebWorkerExampleTests.debug.xcconfig"; path = "Target Support Files/Pods-WebWorkerExample-WebWorkerExampleTests/Pods-WebWorkerExample-WebWorkerExampleTests.debug.xcconfig"; sourceTree = ""; };
46 | 5DCACB8F33CDC322A6C60F78 /* libPods-WebWorkerExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WebWorkerExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
47 | 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = WebWorkerExample/LaunchScreen.storyboard; sourceTree = ""; };
48 | 89C6BE57DB24E9ADA2F236DE /* Pods-WebWorkerExample-WebWorkerExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WebWorkerExample-WebWorkerExampleTests.release.xcconfig"; path = "Target Support Files/Pods-WebWorkerExample-WebWorkerExampleTests/Pods-WebWorkerExample-WebWorkerExampleTests.release.xcconfig"; sourceTree = ""; };
49 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
50 | /* End PBXFileReference section */
51 |
52 | /* Begin PBXFrameworksBuildPhase section */
53 | 00E356EB1AD99517003FC87E /* Frameworks */ = {
54 | isa = PBXFrameworksBuildPhase;
55 | buildActionMask = 2147483647;
56 | files = (
57 | 7699B88040F8A987B510C191 /* libPods-WebWorkerExample-WebWorkerExampleTests.a in Frameworks */,
58 | );
59 | runOnlyForDeploymentPostprocessing = 0;
60 | };
61 | 13B07F8C1A680F5B00A75B9A /* Frameworks */ = {
62 | isa = PBXFrameworksBuildPhase;
63 | buildActionMask = 2147483647;
64 | files = (
65 | 0C80B921A6F3F58F76C31292 /* libPods-WebWorkerExample.a in Frameworks */,
66 | );
67 | runOnlyForDeploymentPostprocessing = 0;
68 | };
69 | /* End PBXFrameworksBuildPhase section */
70 |
71 | /* Begin PBXGroup section */
72 | 00E356EF1AD99517003FC87E /* WebWorkerExampleTests */ = {
73 | isa = PBXGroup;
74 | children = (
75 | 00E356F21AD99517003FC87E /* WebWorkerExampleTests.m */,
76 | 00E356F01AD99517003FC87E /* Supporting Files */,
77 | );
78 | path = WebWorkerExampleTests;
79 | sourceTree = "";
80 | };
81 | 00E356F01AD99517003FC87E /* Supporting Files */ = {
82 | isa = PBXGroup;
83 | children = (
84 | 00E356F11AD99517003FC87E /* Info.plist */,
85 | );
86 | name = "Supporting Files";
87 | sourceTree = "";
88 | };
89 | 13B07FAE1A68108700A75B9A /* WebWorkerExample */ = {
90 | isa = PBXGroup;
91 | children = (
92 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */,
93 | 13B07FB01A68108700A75B9A /* AppDelegate.mm */,
94 | 13B07FB51A68108700A75B9A /* Images.xcassets */,
95 | 13B07FB61A68108700A75B9A /* Info.plist */,
96 | 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
97 | 13B07FB71A68108700A75B9A /* main.m */,
98 | 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */,
99 | 25FE08CE0B0C89DE7F213433 /* PrivacyInfo.xcprivacy */,
100 | );
101 | name = WebWorkerExample;
102 | sourceTree = "";
103 | };
104 | 2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
105 | isa = PBXGroup;
106 | children = (
107 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
108 | 5DCACB8F33CDC322A6C60F78 /* libPods-WebWorkerExample.a */,
109 | 19F6CBCC0A4E27FBF8BF4A61 /* libPods-WebWorkerExample-WebWorkerExampleTests.a */,
110 | );
111 | name = Frameworks;
112 | sourceTree = "";
113 | };
114 | 832341AE1AAA6A7D00B99B32 /* Libraries */ = {
115 | isa = PBXGroup;
116 | children = (
117 | );
118 | name = Libraries;
119 | sourceTree = "";
120 | };
121 | 83CBB9F61A601CBA00E9B192 = {
122 | isa = PBXGroup;
123 | children = (
124 | 13B07FAE1A68108700A75B9A /* WebWorkerExample */,
125 | 832341AE1AAA6A7D00B99B32 /* Libraries */,
126 | 00E356EF1AD99517003FC87E /* WebWorkerExampleTests */,
127 | 83CBBA001A601CBA00E9B192 /* Products */,
128 | 2D16E6871FA4F8E400B85C8A /* Frameworks */,
129 | BBD78D7AC51CEA395F1C20DB /* Pods */,
130 | );
131 | indentWidth = 2;
132 | sourceTree = "";
133 | tabWidth = 2;
134 | usesTabs = 0;
135 | };
136 | 83CBBA001A601CBA00E9B192 /* Products */ = {
137 | isa = PBXGroup;
138 | children = (
139 | 13B07F961A680F5B00A75B9A /* WebWorkerExample.app */,
140 | 00E356EE1AD99517003FC87E /* WebWorkerExampleTests.xctest */,
141 | );
142 | name = Products;
143 | sourceTree = "";
144 | };
145 | BBD78D7AC51CEA395F1C20DB /* Pods */ = {
146 | isa = PBXGroup;
147 | children = (
148 | 3B4392A12AC88292D35C810B /* Pods-WebWorkerExample.debug.xcconfig */,
149 | 5709B34CF0A7D63546082F79 /* Pods-WebWorkerExample.release.xcconfig */,
150 | 5B7EB9410499542E8C5724F5 /* Pods-WebWorkerExample-WebWorkerExampleTests.debug.xcconfig */,
151 | 89C6BE57DB24E9ADA2F236DE /* Pods-WebWorkerExample-WebWorkerExampleTests.release.xcconfig */,
152 | );
153 | path = Pods;
154 | sourceTree = "";
155 | };
156 | /* End PBXGroup section */
157 |
158 | /* Begin PBXNativeTarget section */
159 | 00E356ED1AD99517003FC87E /* WebWorkerExampleTests */ = {
160 | isa = PBXNativeTarget;
161 | buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "WebWorkerExampleTests" */;
162 | buildPhases = (
163 | A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */,
164 | 00E356EA1AD99517003FC87E /* Sources */,
165 | 00E356EB1AD99517003FC87E /* Frameworks */,
166 | 00E356EC1AD99517003FC87E /* Resources */,
167 | C59DA0FBD6956966B86A3779 /* [CP] Embed Pods Frameworks */,
168 | F6A41C54EA430FDDC6A6ED99 /* [CP] Copy Pods Resources */,
169 | );
170 | buildRules = (
171 | );
172 | dependencies = (
173 | 00E356F51AD99517003FC87E /* PBXTargetDependency */,
174 | );
175 | name = WebWorkerExampleTests;
176 | productName = WebWorkerExampleTests;
177 | productReference = 00E356EE1AD99517003FC87E /* WebWorkerExampleTests.xctest */;
178 | productType = "com.apple.product-type.bundle.unit-test";
179 | };
180 | 13B07F861A680F5B00A75B9A /* WebWorkerExample */ = {
181 | isa = PBXNativeTarget;
182 | buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "WebWorkerExample" */;
183 | buildPhases = (
184 | C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */,
185 | 13B07F871A680F5B00A75B9A /* Sources */,
186 | 13B07F8C1A680F5B00A75B9A /* Frameworks */,
187 | 13B07F8E1A680F5B00A75B9A /* Resources */,
188 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
189 | 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */,
190 | E235C05ADACE081382539298 /* [CP] Copy Pods Resources */,
191 | );
192 | buildRules = (
193 | );
194 | dependencies = (
195 | );
196 | name = WebWorkerExample;
197 | productName = WebWorkerExample;
198 | productReference = 13B07F961A680F5B00A75B9A /* WebWorkerExample.app */;
199 | productType = "com.apple.product-type.application";
200 | };
201 | /* End PBXNativeTarget section */
202 |
203 | /* Begin PBXProject section */
204 | 83CBB9F71A601CBA00E9B192 /* Project object */ = {
205 | isa = PBXProject;
206 | attributes = {
207 | LastUpgradeCheck = 1210;
208 | TargetAttributes = {
209 | 00E356ED1AD99517003FC87E = {
210 | CreatedOnToolsVersion = 6.2;
211 | TestTargetID = 13B07F861A680F5B00A75B9A;
212 | };
213 | 13B07F861A680F5B00A75B9A = {
214 | LastSwiftMigration = 1120;
215 | };
216 | };
217 | };
218 | buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "WebWorkerExample" */;
219 | compatibilityVersion = "Xcode 12.0";
220 | developmentRegion = en;
221 | hasScannedForEncodings = 0;
222 | knownRegions = (
223 | en,
224 | Base,
225 | );
226 | mainGroup = 83CBB9F61A601CBA00E9B192;
227 | productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
228 | projectDirPath = "";
229 | projectRoot = "";
230 | targets = (
231 | 13B07F861A680F5B00A75B9A /* WebWorkerExample */,
232 | 00E356ED1AD99517003FC87E /* WebWorkerExampleTests */,
233 | );
234 | };
235 | /* End PBXProject section */
236 |
237 | /* Begin PBXResourcesBuildPhase section */
238 | 00E356EC1AD99517003FC87E /* Resources */ = {
239 | isa = PBXResourcesBuildPhase;
240 | buildActionMask = 2147483647;
241 | files = (
242 | );
243 | runOnlyForDeploymentPostprocessing = 0;
244 | };
245 | 13B07F8E1A680F5B00A75B9A /* Resources */ = {
246 | isa = PBXResourcesBuildPhase;
247 | buildActionMask = 2147483647;
248 | files = (
249 | 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
250 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
251 | B70B766EB16FC794FB8981F5 /* PrivacyInfo.xcprivacy in Resources */,
252 | );
253 | runOnlyForDeploymentPostprocessing = 0;
254 | };
255 | /* End PBXResourcesBuildPhase section */
256 |
257 | /* Begin PBXShellScriptBuildPhase section */
258 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = {
259 | isa = PBXShellScriptBuildPhase;
260 | buildActionMask = 2147483647;
261 | files = (
262 | );
263 | inputPaths = (
264 | "$(SRCROOT)/.xcode.env.local",
265 | "$(SRCROOT)/.xcode.env",
266 | );
267 | name = "Bundle React Native code and images";
268 | outputPaths = (
269 | );
270 | runOnlyForDeploymentPostprocessing = 0;
271 | shellPath = /bin/sh;
272 | shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
273 | };
274 | 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
275 | isa = PBXShellScriptBuildPhase;
276 | buildActionMask = 2147483647;
277 | files = (
278 | );
279 | inputFileListPaths = (
280 | "${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample/Pods-WebWorkerExample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
281 | );
282 | name = "[CP] Embed Pods Frameworks";
283 | outputFileListPaths = (
284 | "${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample/Pods-WebWorkerExample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
285 | );
286 | runOnlyForDeploymentPostprocessing = 0;
287 | shellPath = /bin/sh;
288 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample/Pods-WebWorkerExample-frameworks.sh\"\n";
289 | showEnvVarsInLog = 0;
290 | };
291 | A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */ = {
292 | isa = PBXShellScriptBuildPhase;
293 | buildActionMask = 2147483647;
294 | files = (
295 | );
296 | inputFileListPaths = (
297 | );
298 | inputPaths = (
299 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock",
300 | "${PODS_ROOT}/Manifest.lock",
301 | );
302 | name = "[CP] Check Pods Manifest.lock";
303 | outputFileListPaths = (
304 | );
305 | outputPaths = (
306 | "$(DERIVED_FILE_DIR)/Pods-WebWorkerExample-WebWorkerExampleTests-checkManifestLockResult.txt",
307 | );
308 | runOnlyForDeploymentPostprocessing = 0;
309 | shellPath = /bin/sh;
310 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
311 | showEnvVarsInLog = 0;
312 | };
313 | C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */ = {
314 | isa = PBXShellScriptBuildPhase;
315 | buildActionMask = 2147483647;
316 | files = (
317 | );
318 | inputFileListPaths = (
319 | );
320 | inputPaths = (
321 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock",
322 | "${PODS_ROOT}/Manifest.lock",
323 | );
324 | name = "[CP] Check Pods Manifest.lock";
325 | outputFileListPaths = (
326 | );
327 | outputPaths = (
328 | "$(DERIVED_FILE_DIR)/Pods-WebWorkerExample-checkManifestLockResult.txt",
329 | );
330 | runOnlyForDeploymentPostprocessing = 0;
331 | shellPath = /bin/sh;
332 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
333 | showEnvVarsInLog = 0;
334 | };
335 | C59DA0FBD6956966B86A3779 /* [CP] Embed Pods Frameworks */ = {
336 | isa = PBXShellScriptBuildPhase;
337 | buildActionMask = 2147483647;
338 | files = (
339 | );
340 | inputFileListPaths = (
341 | "${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample-WebWorkerExampleTests/Pods-WebWorkerExample-WebWorkerExampleTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
342 | );
343 | name = "[CP] Embed Pods Frameworks";
344 | outputFileListPaths = (
345 | "${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample-WebWorkerExampleTests/Pods-WebWorkerExample-WebWorkerExampleTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
346 | );
347 | runOnlyForDeploymentPostprocessing = 0;
348 | shellPath = /bin/sh;
349 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample-WebWorkerExampleTests/Pods-WebWorkerExample-WebWorkerExampleTests-frameworks.sh\"\n";
350 | showEnvVarsInLog = 0;
351 | };
352 | E235C05ADACE081382539298 /* [CP] Copy Pods Resources */ = {
353 | isa = PBXShellScriptBuildPhase;
354 | buildActionMask = 2147483647;
355 | files = (
356 | );
357 | inputFileListPaths = (
358 | "${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample/Pods-WebWorkerExample-resources-${CONFIGURATION}-input-files.xcfilelist",
359 | );
360 | name = "[CP] Copy Pods Resources";
361 | outputFileListPaths = (
362 | "${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample/Pods-WebWorkerExample-resources-${CONFIGURATION}-output-files.xcfilelist",
363 | );
364 | runOnlyForDeploymentPostprocessing = 0;
365 | shellPath = /bin/sh;
366 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample/Pods-WebWorkerExample-resources.sh\"\n";
367 | showEnvVarsInLog = 0;
368 | };
369 | F6A41C54EA430FDDC6A6ED99 /* [CP] Copy Pods Resources */ = {
370 | isa = PBXShellScriptBuildPhase;
371 | buildActionMask = 2147483647;
372 | files = (
373 | );
374 | inputFileListPaths = (
375 | "${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample-WebWorkerExampleTests/Pods-WebWorkerExample-WebWorkerExampleTests-resources-${CONFIGURATION}-input-files.xcfilelist",
376 | );
377 | name = "[CP] Copy Pods Resources";
378 | outputFileListPaths = (
379 | "${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample-WebWorkerExampleTests/Pods-WebWorkerExample-WebWorkerExampleTests-resources-${CONFIGURATION}-output-files.xcfilelist",
380 | );
381 | runOnlyForDeploymentPostprocessing = 0;
382 | shellPath = /bin/sh;
383 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-WebWorkerExample-WebWorkerExampleTests/Pods-WebWorkerExample-WebWorkerExampleTests-resources.sh\"\n";
384 | showEnvVarsInLog = 0;
385 | };
386 | /* End PBXShellScriptBuildPhase section */
387 |
388 | /* Begin PBXSourcesBuildPhase section */
389 | 00E356EA1AD99517003FC87E /* Sources */ = {
390 | isa = PBXSourcesBuildPhase;
391 | buildActionMask = 2147483647;
392 | files = (
393 | 00E356F31AD99517003FC87E /* WebWorkerExampleTests.m in Sources */,
394 | );
395 | runOnlyForDeploymentPostprocessing = 0;
396 | };
397 | 13B07F871A680F5B00A75B9A /* Sources */ = {
398 | isa = PBXSourcesBuildPhase;
399 | buildActionMask = 2147483647;
400 | files = (
401 | 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */,
402 | 13B07FC11A68108700A75B9A /* main.m in Sources */,
403 | );
404 | runOnlyForDeploymentPostprocessing = 0;
405 | };
406 | /* End PBXSourcesBuildPhase section */
407 |
408 | /* Begin PBXTargetDependency section */
409 | 00E356F51AD99517003FC87E /* PBXTargetDependency */ = {
410 | isa = PBXTargetDependency;
411 | target = 13B07F861A680F5B00A75B9A /* WebWorkerExample */;
412 | targetProxy = 00E356F41AD99517003FC87E /* PBXContainerItemProxy */;
413 | };
414 | /* End PBXTargetDependency section */
415 |
416 | /* Begin XCBuildConfiguration section */
417 | 00E356F61AD99517003FC87E /* Debug */ = {
418 | isa = XCBuildConfiguration;
419 | baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-WebWorkerExample-WebWorkerExampleTests.debug.xcconfig */;
420 | buildSettings = {
421 | BUNDLE_LOADER = "$(TEST_HOST)";
422 | GCC_PREPROCESSOR_DEFINITIONS = (
423 | "DEBUG=1",
424 | "$(inherited)",
425 | );
426 | INFOPLIST_FILE = WebWorkerExampleTests/Info.plist;
427 | IPHONEOS_DEPLOYMENT_TARGET = 13.4;
428 | LD_RUNPATH_SEARCH_PATHS = (
429 | "$(inherited)",
430 | "@executable_path/Frameworks",
431 | "@loader_path/Frameworks",
432 | );
433 | OTHER_LDFLAGS = (
434 | "-ObjC",
435 | "-lc++",
436 | "$(inherited)",
437 | );
438 | PRODUCT_BUNDLE_IDENTIFIER = webworker.example;
439 | PRODUCT_NAME = "$(TARGET_NAME)";
440 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WebWorkerExample.app/WebWorkerExample";
441 | };
442 | name = Debug;
443 | };
444 | 00E356F71AD99517003FC87E /* Release */ = {
445 | isa = XCBuildConfiguration;
446 | baseConfigurationReference = 89C6BE57DB24E9ADA2F236DE /* Pods-WebWorkerExample-WebWorkerExampleTests.release.xcconfig */;
447 | buildSettings = {
448 | BUNDLE_LOADER = "$(TEST_HOST)";
449 | COPY_PHASE_STRIP = NO;
450 | INFOPLIST_FILE = WebWorkerExampleTests/Info.plist;
451 | IPHONEOS_DEPLOYMENT_TARGET = 13.4;
452 | LD_RUNPATH_SEARCH_PATHS = (
453 | "$(inherited)",
454 | "@executable_path/Frameworks",
455 | "@loader_path/Frameworks",
456 | );
457 | OTHER_LDFLAGS = (
458 | "-ObjC",
459 | "-lc++",
460 | "$(inherited)",
461 | );
462 | PRODUCT_BUNDLE_IDENTIFIER = webworker.example;
463 | PRODUCT_NAME = "$(TARGET_NAME)";
464 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WebWorkerExample.app/WebWorkerExample";
465 | };
466 | name = Release;
467 | };
468 | 13B07F941A680F5B00A75B9A /* Debug */ = {
469 | isa = XCBuildConfiguration;
470 | baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-WebWorkerExample.debug.xcconfig */;
471 | buildSettings = {
472 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
473 | CLANG_ENABLE_MODULES = YES;
474 | CURRENT_PROJECT_VERSION = 1;
475 | ENABLE_BITCODE = NO;
476 | INFOPLIST_FILE = WebWorkerExample/Info.plist;
477 | LD_RUNPATH_SEARCH_PATHS = (
478 | "$(inherited)",
479 | "@executable_path/Frameworks",
480 | );
481 | MARKETING_VERSION = 1.0;
482 | OTHER_LDFLAGS = (
483 | "$(inherited)",
484 | "-ObjC",
485 | "-lc++",
486 | );
487 | PRODUCT_BUNDLE_IDENTIFIER = webworker.example;
488 | PRODUCT_NAME = WebWorkerExample;
489 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
490 | SWIFT_VERSION = 5.0;
491 | VERSIONING_SYSTEM = "apple-generic";
492 | };
493 | name = Debug;
494 | };
495 | 13B07F951A680F5B00A75B9A /* Release */ = {
496 | isa = XCBuildConfiguration;
497 | baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-WebWorkerExample.release.xcconfig */;
498 | buildSettings = {
499 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
500 | CLANG_ENABLE_MODULES = YES;
501 | CURRENT_PROJECT_VERSION = 1;
502 | INFOPLIST_FILE = WebWorkerExample/Info.plist;
503 | LD_RUNPATH_SEARCH_PATHS = (
504 | "$(inherited)",
505 | "@executable_path/Frameworks",
506 | );
507 | MARKETING_VERSION = 1.0;
508 | OTHER_LDFLAGS = (
509 | "$(inherited)",
510 | "-ObjC",
511 | "-lc++",
512 | );
513 | PRODUCT_BUNDLE_IDENTIFIER = webworker.example;
514 | PRODUCT_NAME = WebWorkerExample;
515 | SWIFT_VERSION = 5.0;
516 | VERSIONING_SYSTEM = "apple-generic";
517 | };
518 | name = Release;
519 | };
520 | 83CBBA201A601CBA00E9B192 /* Debug */ = {
521 | isa = XCBuildConfiguration;
522 | buildSettings = {
523 | ALWAYS_SEARCH_USER_PATHS = NO;
524 | CC = "";
525 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
526 | CLANG_CXX_LANGUAGE_STANDARD = "c++20";
527 | CLANG_CXX_LIBRARY = "libc++";
528 | CLANG_ENABLE_MODULES = YES;
529 | CLANG_ENABLE_OBJC_ARC = YES;
530 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
531 | CLANG_WARN_BOOL_CONVERSION = YES;
532 | CLANG_WARN_COMMA = YES;
533 | CLANG_WARN_CONSTANT_CONVERSION = YES;
534 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
535 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
536 | CLANG_WARN_EMPTY_BODY = YES;
537 | CLANG_WARN_ENUM_CONVERSION = YES;
538 | CLANG_WARN_INFINITE_RECURSION = YES;
539 | CLANG_WARN_INT_CONVERSION = YES;
540 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
541 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
542 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
543 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
544 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
545 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
546 | CLANG_WARN_STRICT_PROTOTYPES = YES;
547 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
548 | CLANG_WARN_UNREACHABLE_CODE = YES;
549 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
550 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
551 | COPY_PHASE_STRIP = NO;
552 | CXX = "";
553 | ENABLE_STRICT_OBJC_MSGSEND = YES;
554 | ENABLE_TESTABILITY = YES;
555 | "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
556 | GCC_C_LANGUAGE_STANDARD = gnu99;
557 | GCC_DYNAMIC_NO_PIC = NO;
558 | GCC_NO_COMMON_BLOCKS = YES;
559 | GCC_OPTIMIZATION_LEVEL = 0;
560 | GCC_PREPROCESSOR_DEFINITIONS = (
561 | "DEBUG=1",
562 | "$(inherited)",
563 | );
564 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
565 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
566 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
567 | GCC_WARN_UNDECLARED_SELECTOR = YES;
568 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
569 | GCC_WARN_UNUSED_FUNCTION = YES;
570 | GCC_WARN_UNUSED_VARIABLE = YES;
571 | IPHONEOS_DEPLOYMENT_TARGET = 13.4;
572 | LD = "";
573 | LDPLUSPLUS = "";
574 | LD_RUNPATH_SEARCH_PATHS = (
575 | /usr/lib/swift,
576 | "$(inherited)",
577 | );
578 | LIBRARY_SEARCH_PATHS = (
579 | "\"$(SDKROOT)/usr/lib/swift\"",
580 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
581 | "\"$(inherited)\"",
582 | );
583 | MTL_ENABLE_DEBUG_INFO = YES;
584 | ONLY_ACTIVE_ARCH = YES;
585 | OTHER_CPLUSPLUSFLAGS = (
586 | "$(OTHER_CFLAGS)",
587 | "-DFOLLY_NO_CONFIG",
588 | "-DFOLLY_MOBILE=1",
589 | "-DFOLLY_USE_LIBCPP=1",
590 | "-DFOLLY_CFG_NO_COROUTINES=1",
591 | "-DFOLLY_HAVE_CLOCK_GETTIME=1",
592 | );
593 | OTHER_LDFLAGS = (
594 | "$(inherited)",
595 | " ",
596 | );
597 | REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
598 | SDKROOT = iphoneos;
599 | USE_HERMES = true;
600 | };
601 | name = Debug;
602 | };
603 | 83CBBA211A601CBA00E9B192 /* Release */ = {
604 | isa = XCBuildConfiguration;
605 | buildSettings = {
606 | ALWAYS_SEARCH_USER_PATHS = NO;
607 | CC = "";
608 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
609 | CLANG_CXX_LANGUAGE_STANDARD = "c++20";
610 | CLANG_CXX_LIBRARY = "libc++";
611 | CLANG_ENABLE_MODULES = YES;
612 | CLANG_ENABLE_OBJC_ARC = YES;
613 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
614 | CLANG_WARN_BOOL_CONVERSION = YES;
615 | CLANG_WARN_COMMA = YES;
616 | CLANG_WARN_CONSTANT_CONVERSION = YES;
617 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
618 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
619 | CLANG_WARN_EMPTY_BODY = YES;
620 | CLANG_WARN_ENUM_CONVERSION = YES;
621 | CLANG_WARN_INFINITE_RECURSION = YES;
622 | CLANG_WARN_INT_CONVERSION = YES;
623 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
624 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
625 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
626 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
627 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
628 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
629 | CLANG_WARN_STRICT_PROTOTYPES = YES;
630 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
631 | CLANG_WARN_UNREACHABLE_CODE = YES;
632 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
633 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
634 | COPY_PHASE_STRIP = YES;
635 | CXX = "";
636 | ENABLE_NS_ASSERTIONS = NO;
637 | ENABLE_STRICT_OBJC_MSGSEND = YES;
638 | "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
639 | GCC_C_LANGUAGE_STANDARD = gnu99;
640 | GCC_NO_COMMON_BLOCKS = YES;
641 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
642 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
643 | GCC_WARN_UNDECLARED_SELECTOR = YES;
644 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
645 | GCC_WARN_UNUSED_FUNCTION = YES;
646 | GCC_WARN_UNUSED_VARIABLE = YES;
647 | IPHONEOS_DEPLOYMENT_TARGET = 13.4;
648 | LD = "";
649 | LDPLUSPLUS = "";
650 | LD_RUNPATH_SEARCH_PATHS = (
651 | /usr/lib/swift,
652 | "$(inherited)",
653 | );
654 | LIBRARY_SEARCH_PATHS = (
655 | "\"$(SDKROOT)/usr/lib/swift\"",
656 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
657 | "\"$(inherited)\"",
658 | );
659 | MTL_ENABLE_DEBUG_INFO = NO;
660 | OTHER_CPLUSPLUSFLAGS = (
661 | "$(OTHER_CFLAGS)",
662 | "-DFOLLY_NO_CONFIG",
663 | "-DFOLLY_MOBILE=1",
664 | "-DFOLLY_USE_LIBCPP=1",
665 | "-DFOLLY_CFG_NO_COROUTINES=1",
666 | "-DFOLLY_HAVE_CLOCK_GETTIME=1",
667 | );
668 | OTHER_LDFLAGS = (
669 | "$(inherited)",
670 | " ",
671 | );
672 | REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
673 | SDKROOT = iphoneos;
674 | USE_HERMES = true;
675 | VALIDATE_PRODUCT = YES;
676 | };
677 | name = Release;
678 | };
679 | /* End XCBuildConfiguration section */
680 |
681 | /* Begin XCConfigurationList section */
682 | 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "WebWorkerExampleTests" */ = {
683 | isa = XCConfigurationList;
684 | buildConfigurations = (
685 | 00E356F61AD99517003FC87E /* Debug */,
686 | 00E356F71AD99517003FC87E /* Release */,
687 | );
688 | defaultConfigurationIsVisible = 0;
689 | defaultConfigurationName = Release;
690 | };
691 | 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "WebWorkerExample" */ = {
692 | isa = XCConfigurationList;
693 | buildConfigurations = (
694 | 13B07F941A680F5B00A75B9A /* Debug */,
695 | 13B07F951A680F5B00A75B9A /* Release */,
696 | );
697 | defaultConfigurationIsVisible = 0;
698 | defaultConfigurationName = Release;
699 | };
700 | 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "WebWorkerExample" */ = {
701 | isa = XCConfigurationList;
702 | buildConfigurations = (
703 | 83CBBA201A601CBA00E9B192 /* Debug */,
704 | 83CBBA211A601CBA00E9B192 /* Release */,
705 | );
706 | defaultConfigurationIsVisible = 0;
707 | defaultConfigurationName = Release;
708 | };
709 | /* End XCConfigurationList section */
710 | };
711 | rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */;
712 | }
713 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample.xcodeproj/xcshareddata/xcschemes/WebworkerExample.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
53 |
55 |
61 |
62 |
63 |
64 |
70 |
72 |
78 |
79 |
80 |
81 |
83 |
84 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample/AppDelegate.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 |
4 | @interface AppDelegate : RCTAppDelegate
5 |
6 | @end
7 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample/AppDelegate.mm:
--------------------------------------------------------------------------------
1 | #import "AppDelegate.h"
2 |
3 | #import
4 |
5 | @implementation AppDelegate
6 |
7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
8 | {
9 | self.moduleName = @"WebWorkerExample";
10 | // You can add your custom initial props in the dictionary below.
11 | // They will be passed down to the ViewController used by React Native.
12 | self.initialProps = @{};
13 |
14 | return [super application:application didFinishLaunchingWithOptions:launchOptions];
15 | }
16 |
17 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
18 | {
19 | return [self bundleURL];
20 | }
21 |
22 | - (NSURL *)bundleURL
23 | {
24 | #if DEBUG
25 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
26 | #else
27 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
28 | #endif
29 | }
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "scale" : "2x",
6 | "size" : "20x20"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "scale" : "3x",
11 | "size" : "20x20"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "scale" : "2x",
16 | "size" : "29x29"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "scale" : "3x",
21 | "size" : "29x29"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "scale" : "2x",
26 | "size" : "40x40"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "scale" : "3x",
31 | "size" : "40x40"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "scale" : "2x",
36 | "size" : "60x60"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "scale" : "3x",
41 | "size" : "60x60"
42 | },
43 | {
44 | "idiom" : "ios-marketing",
45 | "scale" : "1x",
46 | "size" : "1024x1024"
47 | }
48 | ],
49 | "info" : {
50 | "author" : "xcode",
51 | "version" : 1
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample/Images.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | WebWorkerExample
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(MARKETING_VERSION)
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(CURRENT_PROJECT_VERSION)
25 | LSRequiresIPhoneOS
26 |
27 | NSAppTransportSecurity
28 |
29 |
30 | NSAllowsArbitraryLoads
31 |
32 | NSAllowsLocalNetworking
33 |
34 |
35 | NSLocationWhenInUseUsageDescription
36 |
37 | UILaunchStoryboardName
38 | LaunchScreen
39 | UIRequiredDeviceCapabilities
40 |
41 | arm64
42 |
43 | UISupportedInterfaceOrientations
44 |
45 | UIInterfaceOrientationPortrait
46 | UIInterfaceOrientationLandscapeLeft
47 | UIInterfaceOrientationLandscapeRight
48 |
49 | UIViewControllerBasedStatusBarAppearance
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample/PrivacyInfo.xcprivacy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSPrivacyAccessedAPITypes
6 |
7 |
8 | NSPrivacyAccessedAPIType
9 | NSPrivacyAccessedAPICategoryFileTimestamp
10 | NSPrivacyAccessedAPITypeReasons
11 |
12 | C617.1
13 |
14 |
15 |
16 | NSPrivacyAccessedAPIType
17 | NSPrivacyAccessedAPICategoryUserDefaults
18 | NSPrivacyAccessedAPITypeReasons
19 |
20 | CA92.1
21 |
22 |
23 |
24 | NSPrivacyAccessedAPIType
25 | NSPrivacyAccessedAPICategorySystemBootTime
26 | NSPrivacyAccessedAPITypeReasons
27 |
28 | 35F9.1
29 |
30 |
31 |
32 | NSPrivacyCollectedDataTypes
33 |
34 | NSPrivacyTracking
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExample/main.m:
--------------------------------------------------------------------------------
1 | #import
2 |
3 | #import "AppDelegate.h"
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | @autoreleasepool {
8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExampleTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/example/ios/WebworkerExampleTests/WebworkerExampleTests.m:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 |
4 | #import
5 | #import
6 |
7 | #define TIMEOUT_SECONDS 600
8 | #define TEXT_TO_LOOK_FOR @"Welcome to React"
9 |
10 | @interface WebWorkerExampleTests : XCTestCase
11 |
12 | @end
13 |
14 | @implementation WebWorkerExampleTests
15 |
16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test
17 | {
18 | if (test(view)) {
19 | return YES;
20 | }
21 | for (UIView *subview in [view subviews]) {
22 | if ([self findSubviewInView:subview matching:test]) {
23 | return YES;
24 | }
25 | }
26 | return NO;
27 | }
28 |
29 | - (void)testRendersWelcomeScreen
30 | {
31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
33 | BOOL foundElement = NO;
34 |
35 | __block NSString *redboxError = nil;
36 | #ifdef DEBUG
37 | RCTSetLogFunction(
38 | ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
39 | if (level >= RCTLogLevelError) {
40 | redboxError = message;
41 | }
42 | });
43 | #endif
44 |
45 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
46 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
47 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
48 |
49 | foundElement = [self findSubviewInView:vc.view
50 | matching:^BOOL(UIView *view) {
51 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
52 | return YES;
53 | }
54 | return NO;
55 | }];
56 | }
57 |
58 | #ifdef DEBUG
59 | RCTSetLogFunction(RCTDefaultLogFunction);
60 | #endif
61 |
62 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
63 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
64 | }
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/example/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | preset: 'react-native',
3 | };
4 |
--------------------------------------------------------------------------------
/example/metro.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const { getDefaultConfig } = require('@react-native/metro-config');
3 | const { getConfig } = require('react-native-builder-bob/metro-config');
4 | const pkg = require('../package.json');
5 |
6 | const root = path.resolve(__dirname, '..');
7 |
8 | /**
9 | * Metro configuration
10 | * https://facebook.github.io/metro/docs/configuration
11 | *
12 | * @type {import('metro-config').MetroConfig}
13 | */
14 | module.exports = getConfig(getDefaultConfig(__dirname), {
15 | root,
16 | pkg,
17 | project: __dirname,
18 | });
19 |
20 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-web-worker-example",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "android": "react-native run-android",
7 | "ios": "react-native run-ios",
8 | "start": "react-native start",
9 | "build:android": "react-native build-android --extra-params \"--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a\"",
10 | "build:ios": "react-native build-ios --scheme WebWorkerExample --mode Debug --extra-params \"-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO\""
11 | },
12 | "dependencies": {
13 | "react": "18.2.0",
14 | "react-native": "0.74.5"
15 | },
16 | "devDependencies": {
17 | "@babel/core": "^7.20.0",
18 | "@babel/preset-env": "^7.20.0",
19 | "@babel/runtime": "^7.20.0",
20 | "@react-native/babel-preset": "0.74.87",
21 | "@react-native/metro-config": "0.74.87",
22 | "@react-native/typescript-config": "0.74.87",
23 | "react-native-builder-bob": "^0.29.1"
24 | },
25 | "engines": {
26 | "node": ">=18"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/example/react-native.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const pkg = require('../package.json');
3 |
4 | module.exports = {
5 | project: {
6 | ios: {
7 | automaticPodsInstallation: true,
8 | },
9 | },
10 | dependencies: {
11 | [pkg.name]: {
12 | root: path.join(__dirname, '..'),
13 | },
14 | },
15 | };
16 |
--------------------------------------------------------------------------------
/example/src/App.tsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useRef, useState } from 'react';
2 | import {
3 | Button,
4 | SafeAreaView,
5 | StyleSheet,
6 | Text,
7 | ScrollView,
8 | } from 'react-native';
9 | import { WebWorker } from '@jacobp100/react-native-webworker';
10 |
11 | export default () => {
12 | const [messages, setMessages] = useState([]);
13 | const [environment, setEnvironment] = useState<'light' | 'react-native'>(
14 | 'light'
15 | );
16 | const workerRef = useRef();
17 |
18 | useEffect(() => {
19 | console.log(`Create worker: ${environment}`);
20 | const worker = new WebWorker(`./worker-${environment}.js`, { environment });
21 | worker.onmessage = ({ data }) => {
22 | setMessages((m) => [...m, data]);
23 | };
24 | workerRef.current = worker;
25 | return () => {
26 | console.log(`Terminate worker: ${environment}`);
27 | worker.terminate();
28 | workerRef.current = undefined;
29 | };
30 | }, [environment]);
31 |
32 | const postMessage = () => {
33 | workerRef.current!.postMessage(`Message ${messages.length + 1}`);
34 | };
35 |
36 | return (
37 |
38 |
39 | Welcome to React Native WebWorker!
40 |
41 | Environment: {environment}
42 |
60 |
61 | );
62 | };
63 |
64 | const styles = StyleSheet.create({
65 | container: {
66 | flex: 1,
67 | },
68 | contentContainer: {
69 | padding: 20,
70 | },
71 | welcome: {
72 | fontSize: 20,
73 | textAlign: 'center',
74 | marginTop: 10,
75 | marginBottom: 20,
76 | },
77 | messages: {
78 | fontSize: 14,
79 | fontWeight: '600',
80 | marginTop: 20,
81 | marginBottom: 3,
82 | },
83 | message: {
84 | fontSize: 11,
85 | fontVariant: ['tabular-nums'],
86 | },
87 | });
88 |
--------------------------------------------------------------------------------
/example/worker-light.js:
--------------------------------------------------------------------------------
1 | self.onmessage = ({ data }) => {
2 | self.postMessage(`Message from worker: "${data}"!`);
3 | };
4 |
--------------------------------------------------------------------------------
/example/worker-react-native.js:
--------------------------------------------------------------------------------
1 | import { self } from '@jacobp100/react-native-webworker';
2 |
3 | self.onmessage = ({ data }) => {
4 | self.postMessage(`Message from worker: "${data}"!`);
5 | };
6 |
--------------------------------------------------------------------------------
/ios/RNWWEnvironment.h:
--------------------------------------------------------------------------------
1 | @protocol RNWWEnvironmentDelegate;
2 |
3 | @protocol RNWWEnvironment
4 |
5 | @property (nonatomic, weak) id delegate;
6 | @property (nonatomic, copy) NSNumber *threadId;
7 |
8 | - (void)invalidate;
9 |
10 | - (void)postMessage:(NSString *)message;
11 | - (void)abortExecution;
12 |
13 | @end
14 |
15 | @protocol RNWWEnvironmentDelegate
16 |
17 | - (void)didReceiveMessage:(id)sender
18 | data:(NSString *)data;
19 |
20 | - (void)didReceiveError:(id)sender
21 | message:(NSString *)message
22 | name:(NSString *)name;
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/ios/RNWWEnvironmentBridge.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 | #import
4 |
5 | #import "RNWWEnvironment.h"
6 | #import "RNWWSelf.h"
7 |
8 | @interface RNWWEnvironmentBridge : NSObject
9 |
10 | @property (nonatomic, weak) id delegate;
11 | @property (nonatomic, copy) NSNumber *threadId;
12 |
13 | - (instancetype)initWithBridge:(RCTBridge *)bridge
14 | threadId:(NSNumber *)threadId
15 | url:(NSURL *)url;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/ios/RNWWEnvironmentBridge.mm:
--------------------------------------------------------------------------------
1 | #import "RNWWEnvironmentBridge.h"
2 | #import
3 | #import
4 | #include
5 |
6 | #if RCT_NEW_ARCH_ENABLED
7 | #import
8 | #import
9 | #import
10 | #import
11 | #import
12 | #import
13 | #import
14 |
15 | @interface RNWWEnvironmentBridge ()
16 | @end
17 | #endif
18 |
19 | @implementation RNWWEnvironmentBridge {
20 | NSURL *_url;
21 | RCTBridge *_threadBridge;
22 | }
23 |
24 | - (instancetype)initWithBridge:(RCTBridge *)bridge
25 | threadId:(NSNumber *)threadId
26 | url:(NSURL *)url
27 | {
28 | self = [super init];
29 | if (self) {
30 | self.threadId = threadId;
31 | _url = url;
32 |
33 | #if RCT_DEV
34 | RCTDevMenu *mainDevMenu = [bridge moduleForClass:RCTDevMenu.class];
35 | // We have to read this early as the value may change when loading a new thread
36 | BOOL hotkeysEnabled = [mainDevMenu hotkeysEnabled];
37 | #endif
38 |
39 | _threadBridge = [[RCTBridge alloc] initWithDelegate:self
40 | launchOptions:nil];
41 |
42 | RNWWSelf *threadSelf = [_threadBridge moduleForClass:RNWWSelf.class];
43 | threadSelf.delegate = self;
44 |
45 | #if RCT_DEV
46 | // When we start a new thread, we'll initialize a new DevMenu class, which will
47 | // then override the existing handlers for shake and key presses
48 | // We can turn some of this behaviour off; however, it gets stored in the user settings,
49 | // and applied to the main DevMenu class
50 | // Here, we do the best effort to un-initialize the key commands
51 |
52 | // First, disable the main keyboard shortcuts so we know re-enabling later won't no-op
53 | [mainDevMenu setHotkeysEnabled:NO];
54 |
55 | RCTDevMenu *threadDevMenu = [_threadBridge moduleForClass:RCTDevMenu.class];
56 | // Disable the shake gesture handler
57 | [[NSNotificationCenter defaultCenter] removeObserver:threadDevMenu];
58 | // Disable thread keyboard shortcuts
59 | [threadDevMenu setHotkeysEnabled:NO];
60 |
61 | // Lastly, re-enable the main keyboard shortcuts if they were enabled
62 | [mainDevMenu setHotkeysEnabled:hotkeysEnabled];
63 | #endif
64 | }
65 | return self;
66 | }
67 |
68 | - (void)invalidate
69 | {
70 | [_threadBridge invalidate];
71 | }
72 |
73 | - (void)postMessage:(NSString *)message
74 | {
75 | RNWWSelf *threadSelf = [_threadBridge moduleForClass:RNWWSelf.class];
76 | [threadSelf postMessage:message];
77 | }
78 |
79 | RCT_NOT_IMPLEMENTED(- (void)abortExecution)
80 |
81 | - (void)didReceiveMessage:(RNWWSelf *)sender
82 | data:(NSString *)data
83 | {
84 | [self.delegate didReceiveMessage:self
85 | data:data];
86 | }
87 |
88 | - (void)didReceiveError:(RNWWSelf *)sender
89 | message:(NSString *)message
90 | name:(NSString *)name
91 | {
92 | [self.delegate didReceiveError:self
93 | message:message
94 | name:name];
95 | }
96 |
97 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
98 | {
99 | return _url;
100 | }
101 |
102 | #if RCT_NEW_ARCH_ENABLED
103 |
104 | #pragma mark - RCTCxxBridgeDelegate
105 |
106 | - (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge
107 | {
108 | std::shared_ptr _runtimeScheduler = std::make_shared(RCTRuntimeExecutorFromBridge(bridge));
109 | std::shared_ptr callInvoker =
110 | std::make_shared(_runtimeScheduler);
111 | RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc]
112 | initWithBridge:bridge
113 | delegate:self
114 | jsInvoker:bridge.jsCallInvoker];
115 | return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
116 | }
117 |
118 | #pragma mark RCTTurboModuleManagerDelegate
119 |
120 | - (Class)getModuleClassFromName:(const char *)name
121 | {
122 | return RCTCoreModulesClassProvider(name);
123 | }
124 |
125 | - (std::shared_ptr)getTurboModule:(const std::string &)name
126 | jsInvoker:(std::shared_ptr)jsInvoker
127 | {
128 | return nullptr;
129 | }
130 |
131 | - (std::shared_ptr)getTurboModule:(const std::string &)name
132 | initParams:
133 | (const facebook::react::ObjCTurboModule::InitParams &)params
134 | {
135 | return nullptr;
136 | }
137 |
138 | - (id)getModuleInstanceFromClass:(Class)moduleClass
139 | {
140 | return RCTAppSetupDefaultModuleFromClass(moduleClass);
141 | }
142 |
143 | #endif
144 |
145 | @end
146 |
--------------------------------------------------------------------------------
/ios/RNWWEnvironmentLight.h:
--------------------------------------------------------------------------------
1 | #import "RNWWEnvironment.h"
2 |
3 | #if __has_include()
4 | #define RNWW_USE_HERMES 1
5 | #else
6 | #define RNWW_USE_HERMES 0
7 | #endif
8 |
9 | @interface RNWWEnvironmentLight : NSObject
10 |
11 | @property (nonatomic, weak) id delegate;
12 | @property (nonatomic, copy) NSNumber *threadId;
13 |
14 | - (instancetype)initWithThreadId:(NSNumber *)threadId
15 | url:(NSURL *)url;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/ios/RNWWEnvironmentLight.mm:
--------------------------------------------------------------------------------
1 | #import "RNWWEnvironmentLight.h"
2 |
3 | #import
4 | #import
5 |
6 | #if RNWW_USE_HERMES
7 | #import
8 |
9 | #include
10 |
11 | using namespace facebook::jsi;
12 | using namespace facebook::hermes;
13 |
14 | #define RUNTIME std::shared_ptr
15 | #else
16 | #import
17 |
18 | #define RUNTIME JSContext *
19 | #endif
20 |
21 | typedef NS_ENUM(NSUInteger, QueuedEventType) {
22 | QueuedEventTypeMessage,
23 | QueuedEventTypeAbortExecution
24 | };
25 |
26 | @interface QueuedEvent : NSObject
27 | @property (nonatomic, assign) QueuedEventType type;
28 | @property (nonatomic, copy) NSString *message;
29 | @end
30 |
31 | @implementation QueuedEvent
32 | @end
33 |
34 | @implementation RNWWEnvironmentLight {
35 | RUNTIME _runtime;
36 | dispatch_queue_t _queue;
37 | // Messages queued here until the JS has loaded (lazily created)
38 | NSMutableArray *_pendingEvents;
39 | BOOL _jsInitialized;
40 | }
41 |
42 | + (RUNTIME)initRuntime:(void (^)(NSString *))onMessageBlock
43 | onError:(void (^)(NSString *))onErrorBlock
44 | {
45 | #if RNWW_USE_HERMES
46 | RUNTIME runtime = makeHermesRuntime();
47 |
48 | runtime->global().setProperty(*runtime, "self", runtime->global());
49 |
50 | Function postMessage =
51 | Function::createFromHostFunction(*runtime,
52 | PropNameID::forAscii(*runtime, "postMessage"),
53 | 1,
54 | [onMessageBlock](Runtime &rt, const Value &thisVal, const Value *args, size_t count) {
55 | if (args->isString()) {
56 | std::string utf8 = args->asString(rt).utf8(rt);
57 | NSString *message = [NSString stringWithCString:utf8.c_str()
58 | encoding:NSUTF8StringEncoding];
59 | onMessageBlock(message);
60 | }
61 |
62 | return Value::undefined();
63 | });
64 | runtime->global().setProperty(*runtime, "postMessage", postMessage);
65 |
66 | return runtime;
67 | #else
68 | RUNTIME runtime = [JSContext new];
69 |
70 | runtime[@"self"] = runtime.globalObject;
71 | runtime[@"postMessage"] = ^(NSString *message) {
72 | onMessageBlock(message);
73 | };
74 | runtime.exceptionHandler = ^(JSContext *context, JSValue *exception) {
75 | JSValue *messageValue = exception[@"message"];
76 | NSString *message = messageValue.isString
77 | ? messageValue.toString
78 | : @"Unknown error";
79 | onErrorBlock(message);
80 | };
81 |
82 | return runtime;
83 | #endif
84 | }
85 |
86 | - (instancetype)initWithThreadId:(NSNumber *)threadId
87 | url:(NSURL *)url
88 | {
89 | self = [super init];
90 | if (self) {
91 | self.threadId = threadId;
92 | _jsInitialized = NO;
93 | dispatch_queue_attr_t qos = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL,
94 | QOS_CLASS_DEFAULT,
95 | -1);
96 | _queue = dispatch_queue_create("hermes", qos);
97 |
98 | __weak __typeof(self) weakSelf = self;
99 |
100 | _runtime = [RNWWEnvironmentLight initRuntime:^(NSString *data) {
101 | __strong __typeof(self) strongSelf = weakSelf;
102 | if (strongSelf == nil) {
103 | return;
104 | }
105 |
106 | [strongSelf.delegate didReceiveMessage:strongSelf
107 | data:data];
108 | } onError:^(NSString *message) {
109 | __strong __typeof(self) strongSelf = weakSelf;
110 | if (strongSelf == nil) {
111 | return;
112 | }
113 |
114 | [strongSelf.delegate didReceiveError:strongSelf
115 | message:message
116 | name:@"Error"];
117 | }];
118 |
119 | [RCTJavaScriptLoader loadBundleAtURL:url
120 | onProgress:^(RCTLoadingProgress *progressData) {}
121 | onComplete:^(NSError *error, RCTSource *source) {
122 | __strong __typeof(self) strongSelf = weakSelf;
123 | if (strongSelf == nil) {
124 | return;
125 | }
126 |
127 | if (source == nil) {
128 | NSLog(@"Could not load worker");
129 | return;
130 | }
131 |
132 | __weak __typeof(self) weakSelf = self;
133 | [strongSelf runAsync:^(RUNTIME rt) {
134 | #if RNWW_USE_HERMES
135 | std::string script(static_cast(source.data.bytes),
136 | source.data.length);
137 | rt->evaluateJavaScript(std::make_shared(script),
138 | url.absoluteString.UTF8String);
139 | #else
140 | NSString *script = [[NSString alloc] initWithData:source.data
141 | encoding:NSUTF8StringEncoding];
142 | [rt evaluateScript:script
143 | withSourceURL:url];
144 | #endif
145 | } onComplete:^() {
146 | __strong __typeof(self) strongSelf = weakSelf;
147 | if (strongSelf == nil) {
148 | return;
149 | }
150 |
151 | strongSelf->_jsInitialized = YES;
152 | [strongSelf dispatchEventsIfNeeded];
153 | }];
154 | }];
155 | }
156 | return self;
157 | }
158 |
159 | - (void)dealloc
160 | {
161 | if (_runtime != nil) {
162 | [self invalidate];
163 | }
164 | }
165 |
166 | - (void)invalidate
167 | {
168 | #if RNWW_USE_HERMES
169 | _runtime->watchTimeLimit(0);
170 | #endif
171 | _runtime = nil;
172 | }
173 |
174 | - (void)runAsync:(void (^)(RUNTIME))block
175 | onComplete:(nullable void (^)())onComplete
176 | {
177 | __weak __typeof(self) weakSelf = self;
178 | dispatch_async(_queue, ^{
179 | __strong __typeof(self) strongSelf = weakSelf;
180 | if (strongSelf == nil) {
181 | return;
182 | }
183 |
184 | NSString * _Nullable errorName = nil;
185 | NSString * _Nullable errorMessage = nil;
186 |
187 | RUNTIME rt = strongSelf->_runtime;
188 | try {
189 | if (rt != nil) {
190 | block(rt);
191 | } else {
192 | errorName = @"TimeoutError";
193 | errorMessage = @"Worker was terminated";
194 | }
195 | #if RNWW_USE_HERMES
196 | } catch (const JSError &e) {
197 | errorMessage = @(e.getMessage().data());
198 |
199 | try {
200 | std::string constructorName = e
201 | .value()
202 | .asObject(*rt)
203 | .getProperty(*rt, "name")
204 | .asString(*rt)
205 | .utf8(*rt);
206 | errorName = @(constructorName.data());
207 | } catch (...) {
208 | }
209 | #endif
210 | } catch (const std::exception &e) {
211 | errorMessage = @(e.what());
212 | } catch (...) {
213 | errorMessage = @"Unknown error";
214 | }
215 |
216 | if (errorMessage != nil) {
217 | errorName = errorName ?: @"Error";
218 | [strongSelf.delegate didReceiveError:strongSelf
219 | message:errorMessage
220 | name:errorName];
221 | }
222 |
223 | if (onComplete != nil) {
224 | onComplete();
225 | }
226 | });
227 | }
228 |
229 | - (void)runAsync:(void (^)(RUNTIME))block
230 | {
231 | [self runAsync:block onComplete:nil];
232 | }
233 |
234 | - (void)dispatchMessage:(NSString *)message
235 | {
236 | [self runAsync:^(RUNTIME rt) {
237 | #if RNWW_USE_HERMES
238 | Value onMessageValue = rt->global().getProperty(*rt, "onmessage");
239 | if (!onMessageValue.isObject()) {
240 | return;
241 | }
242 |
243 | Object onMessageObject = onMessageValue.asObject(*rt);
244 | if (!onMessageObject.isFunction(*rt)) {
245 | return;
246 | }
247 |
248 | std::string messageCString([message cStringUsingEncoding:NSUTF8StringEncoding]);
249 | Value data = String::createFromUtf8(*rt, messageCString);
250 |
251 | Object event = Object(*rt);
252 | event.setProperty(*rt, "data", data);
253 |
254 | Function onMessage = onMessageObject.getFunction(*rt);
255 |
256 | onMessage.call(*rt, event, 1);
257 | #else
258 | JSValue *onMessage = rt[@"onmessage"];
259 | if (onMessage.isUndefined || onMessage.isNull) {
260 | return;
261 | }
262 |
263 | id event = @{ @"data": message };
264 | [onMessage callWithArguments:@[event]];
265 | #endif
266 | }];
267 | }
268 |
269 | - (void)dispatchAbortExecution
270 | {
271 | #if RNWW_USE_HERMES
272 | _runtime->asyncTriggerTimeout();
273 | #endif
274 | }
275 |
276 | - (void)dispatchEventsIfNeeded
277 | {
278 | if (!_pendingEvents) {
279 | return;
280 | }
281 |
282 | for (QueuedEvent *event in _pendingEvents) {
283 | switch (event.type) {
284 | case QueuedEventTypeMessage:
285 | [self dispatchMessage:event.message];
286 | break;
287 | case QueuedEventTypeAbortExecution:
288 | [self dispatchAbortExecution];
289 | break;
290 | }
291 | }
292 |
293 | [_pendingEvents removeAllObjects];
294 | _pendingEvents = nil;
295 | }
296 |
297 |
298 | - (void)postMessage:(NSString *)message
299 | {
300 | if (_jsInitialized) {
301 | [self dispatchEventsIfNeeded];
302 | [self dispatchMessage:message];
303 | } else {
304 | _pendingEvents = _pendingEvents ?: [[NSMutableArray alloc] initWithCapacity:1];
305 | QueuedEvent *event = [QueuedEvent new];
306 | event.type = QueuedEventTypeMessage;
307 | event.message = message;
308 | [_pendingEvents addObject:event];
309 | }
310 | }
311 |
312 | #if RNWW_USE_HERMES
313 | - (void)abortExecution
314 | {
315 | if (_jsInitialized) {
316 | [self dispatchEventsIfNeeded];
317 | [self dispatchAbortExecution];
318 | } else {
319 | _pendingEvents = _pendingEvents ?: [[NSMutableArray alloc] initWithCapacity:1];
320 | QueuedEvent *event = [QueuedEvent new];
321 | event.type = QueuedEventTypeAbortExecution;
322 | [_pendingEvents addObject:event];
323 | }
324 | }
325 | #else
326 | RCT_NOT_IMPLEMENTED(- (void)abortExecution)
327 | #endif
328 |
329 | @end
330 |
--------------------------------------------------------------------------------
/ios/RNWWSelf.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 |
4 | @protocol RNWWSelfDelegate
5 | - (void)didReceiveMessage:(id)sender
6 | data:(NSString *)data;
7 | - (void)didReceiveError:(id)sender
8 | message:(NSString *)message
9 | name:(NSString *)name;
10 | @end
11 |
12 | @interface RNWWSelf : RCTEventEmitter
13 | @property (nonatomic, weak) id delegate;
14 | - (void)postMessage:(NSString *)message;
15 | @end
16 |
--------------------------------------------------------------------------------
/ios/RNWWSelf.mm:
--------------------------------------------------------------------------------
1 | #import "RNWWSelf.h"
2 | #include
3 |
4 | #if RCT_NEW_ARCH_ENABLED
5 | #import "RNWebworkerSpec.h"
6 | #endif
7 |
8 | @implementation RNWWSelf {
9 | // Messages queued here until the JS has loaded (lazily created)
10 | NSMutableArray *_pendingEvents;
11 | }
12 |
13 | RCT_EXPORT_MODULE(Self);
14 |
15 | + (BOOL)requiresMainQueueSetup
16 | {
17 | return NO;
18 | }
19 |
20 | - (instancetype)init
21 | {
22 | if (self = [super init]) {
23 | [NSNotificationCenter.defaultCenter
24 | addObserver:self
25 | selector:@selector(handleBridgeDidLoadJavaScriptNotification:)
26 | name:RCTJavaScriptDidLoadNotification
27 | object:self.bridge];
28 | }
29 | return self;
30 | }
31 |
32 | - (void)invalidate
33 | {
34 | [NSNotificationCenter.defaultCenter removeObserver:self];
35 |
36 | [_pendingEvents removeAllObjects];
37 | _pendingEvents = nil;
38 |
39 | [super invalidate];
40 | }
41 |
42 | - (NSArray *)supportedEvents
43 | {
44 | return @[@"message"];
45 | }
46 |
47 | - (void)dispatchMessagesIfNeeded
48 | {
49 | if (!_pendingEvents || self.bridge.isLoading) {
50 | return;
51 | }
52 |
53 | for (NSString *message in _pendingEvents) {
54 | [self sendEventWithName:@"message" body:message];
55 | }
56 |
57 | [_pendingEvents removeAllObjects];
58 | _pendingEvents = nil;
59 | }
60 |
61 | - (void)handleBridgeDidLoadJavaScriptNotification:(NSNotification *)notification
62 | {
63 | [self dispatchMessagesIfNeeded];
64 | }
65 |
66 | - (void)postMessage:(NSString *)message
67 | {
68 | if (!self.bridge.isLoading) {
69 | [self dispatchMessagesIfNeeded];
70 | [self sendEventWithName:@"message" body:message];
71 | } else if (_pendingEvents) {
72 | [_pendingEvents addObject:message];
73 | } else {
74 | _pendingEvents = [[NSMutableArray alloc] initWithObjects:message, nil];
75 | }
76 | }
77 |
78 | RCT_REMAP_METHOD(postMessage,
79 | didReceiveMessage:(NSString *)data)
80 | {
81 | if (self.delegate == nil) {
82 | NSLog(@"ERROR: postMessage sent outside worker context");
83 | return;
84 | }
85 |
86 | [self.delegate didReceiveMessage:self
87 | data:data];
88 | }
89 |
90 | RCT_REMAP_METHOD(postError,
91 | didReceiveError:(NSString *)message
92 | name:(NSString *)name)
93 | {
94 | if (self.delegate == nil) {
95 | NSLog(@"ERROR: postMessage sent outside worker context");
96 | return;
97 | }
98 |
99 | [self.delegate didReceiveError:self
100 | message:message
101 | name:name];
102 | }
103 |
104 | #ifdef RCT_NEW_ARCH_ENABLED
105 | - (std::shared_ptr)getTurboModule:
106 | (const facebook::react::ObjCTurboModule::InitParams &)params
107 | {
108 | return std::make_shared(params);
109 | }
110 | #endif
111 |
112 | @end
113 |
--------------------------------------------------------------------------------
/ios/RNWWWebWorker.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 | #import
4 | #import
5 |
6 | #import "RNWWEnvironment.h"
7 |
8 | @interface RNWWWebWorker : RCTEventEmitter
9 | @end
10 |
--------------------------------------------------------------------------------
/ios/RNWWWebWorker.mm:
--------------------------------------------------------------------------------
1 | #import "RNWWWebWorker.h"
2 | #import
3 | #import
4 | #include
5 |
6 | #import "RNWWEnvironment.h"
7 | #import "RNWWEnvironmentBridge.h"
8 | #import "RNWWEnvironmentLight.h"
9 |
10 | #if RCT_NEW_ARCH_ENABLED
11 | #import "RNWebworkerSpec.h"
12 | #endif
13 |
14 | @implementation RNWWWebWorker {
15 | NSMutableDictionary> *_threads;
16 | }
17 |
18 | RCT_EXPORT_MODULE(WebWorker);
19 |
20 | @synthesize bridge = _bridge;
21 |
22 | + (BOOL)requiresMainQueueSetup
23 | {
24 | return NO;
25 | }
26 |
27 | - (instancetype)init
28 | {
29 | if (self = [super init]) {
30 | _threads = [NSMutableDictionary new];
31 | }
32 | return self;
33 | }
34 |
35 | - (void)invalidate {
36 | for (NSNumber *threadId in _threads) {
37 | id environment = _threads[threadId];
38 | [environment invalidate];
39 | }
40 |
41 | [_threads removeAllObjects];
42 | _threads = nil;
43 |
44 | [super invalidate];
45 | }
46 |
47 | - (NSArray *)supportedEvents
48 | {
49 | return @[@"message", @"error"];
50 | }
51 |
52 | #if RCT_DEV
53 | // Calls to setHotkeysEnabled must be on the main thread
54 | - (dispatch_queue_t)methodQueue
55 | {
56 | return dispatch_get_main_queue();
57 | }
58 | #endif
59 |
60 | RCT_EXPORT_METHOD(startThread:(nonnull NSNumber *)threadId
61 | name:(NSString *)name
62 | environment:(NSString *)environment)
63 | {
64 | #if DEBUG
65 | NSURL *url = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:name];
66 | #else
67 | NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:@"jsbundle"];
68 | #endif
69 |
70 | id thread;
71 | if ([environment isEqualToString:@"light"]) {
72 | thread = [[RNWWEnvironmentLight alloc] initWithThreadId:threadId
73 | url:url];
74 | } else {
75 | thread = [[RNWWEnvironmentBridge alloc] initWithBridge:_bridge
76 | threadId:threadId
77 | url:url];
78 | }
79 |
80 | thread.delegate = self;
81 | [_threads setObject:thread
82 | forKey:threadId];
83 | }
84 |
85 | RCT_EXPORT_METHOD(stopThread:(nonnull NSNumber *)threadId
86 | mode:(NSString *)mode)
87 | {
88 | id thread = _threads[threadId];
89 | if (thread == nil) {
90 | return;
91 | }
92 |
93 | if ([mode isEqualToString:@"execution"]) {
94 | [thread abortExecution];
95 | } else {
96 | [thread invalidate];
97 | [_threads removeObjectForKey:threadId];
98 | }
99 | }
100 |
101 | RCT_EXPORT_METHOD(postThreadMessage:(nonnull NSNumber *)threadId
102 | data:(NSString *)data)
103 | {
104 | id thread = _threads[threadId];
105 | if (thread == nil) {
106 | NSLog(@"Could not post to thread with id %@", threadId);
107 | return;
108 | }
109 |
110 | [thread postMessage:data];
111 | }
112 |
113 | - (void)didReceiveMessage:(id)sender
114 | data:(NSString *)data
115 | {
116 | id body = @{
117 | @"id": sender.threadId,
118 | @"data": data,
119 | };
120 | [self sendEventWithName:@"message"
121 | body:body];
122 | }
123 |
124 | - (void)didReceiveError:(id)sender
125 | message:(NSString *)message
126 | name:(NSString *)name
127 | {
128 | id body = @{
129 | @"id": sender.threadId,
130 | @"message": message,
131 | @"name": name,
132 | };
133 | [self sendEventWithName:@"error"
134 | body:body];
135 | }
136 |
137 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
138 | {
139 | return bridge.launchOptions[@"threadUrl"];
140 | }
141 |
142 | #if RCT_NEW_ARCH_ENABLED
143 | - (std::shared_ptr)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params
144 | {
145 | return std::make_shared(params);
146 | }
147 | #endif
148 |
149 | @end
150 |
--------------------------------------------------------------------------------
/ios/Webworker.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 5E555C0D2413F4C50049A1A2 /* WebWorker.mm in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* WebWorker.mm */; };
11 | /* End PBXBuildFile section */
12 |
13 | /* Begin PBXCopyFilesBuildPhase section */
14 | 58B511D91A9E6C8500147676 /* CopyFiles */ = {
15 | isa = PBXCopyFilesBuildPhase;
16 | buildActionMask = 2147483647;
17 | dstPath = "include/$(PRODUCT_NAME)";
18 | dstSubfolderSpec = 16;
19 | files = (
20 | );
21 | runOnlyForDeploymentPostprocessing = 0;
22 | };
23 | /* End PBXCopyFilesBuildPhase section */
24 |
25 | /* Begin PBXFileReference section */
26 | 134814201AA4EA6300B7C361 /* libWebWorker.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWebWorker.a; sourceTree = BUILT_PRODUCTS_DIR; };
27 | B3E7B5881CC2AC0600A0062D /* WebWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebWorker.h; sourceTree = ""; };
28 | B3E7B5891CC2AC0600A0062D /* WebWorker.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebWorker.mm; sourceTree = ""; };
29 | /* End PBXFileReference section */
30 |
31 | /* Begin PBXFrameworksBuildPhase section */
32 | 58B511D81A9E6C8500147676 /* Frameworks */ = {
33 | isa = PBXFrameworksBuildPhase;
34 | buildActionMask = 2147483647;
35 | files = (
36 | );
37 | runOnlyForDeploymentPostprocessing = 0;
38 | };
39 | /* End PBXFrameworksBuildPhase section */
40 |
41 | /* Begin PBXGroup section */
42 | 134814211AA4EA7D00B7C361 /* Products */ = {
43 | isa = PBXGroup;
44 | children = (
45 | 134814201AA4EA6300B7C361 /* libWebWorker.a */,
46 | );
47 | name = Products;
48 | sourceTree = "";
49 | };
50 | 58B511D21A9E6C8500147676 = {
51 | isa = PBXGroup;
52 | children = (
53 | B3E7B5881CC2AC0600A0062D /* WebWorker.h */,
54 | B3E7B5891CC2AC0600A0062D /* WebWorker.mm */,
55 | 134814211AA4EA7D00B7C361 /* Products */,
56 | );
57 | sourceTree = "";
58 | };
59 | /* End PBXGroup section */
60 |
61 | /* Begin PBXNativeTarget section */
62 | 58B511DA1A9E6C8500147676 /* WebWorker */ = {
63 | isa = PBXNativeTarget;
64 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "WebWorker" */;
65 | buildPhases = (
66 | 58B511D71A9E6C8500147676 /* Sources */,
67 | 58B511D81A9E6C8500147676 /* Frameworks */,
68 | 58B511D91A9E6C8500147676 /* CopyFiles */,
69 | );
70 | buildRules = (
71 | );
72 | dependencies = (
73 | );
74 | name = WebWorker;
75 | productName = RCTDataManager;
76 | productReference = 134814201AA4EA6300B7C361 /* libWebWorker.a */;
77 | productType = "com.apple.product-type.library.static";
78 | };
79 | /* End PBXNativeTarget section */
80 |
81 | /* Begin PBXProject section */
82 | 58B511D31A9E6C8500147676 /* Project object */ = {
83 | isa = PBXProject;
84 | attributes = {
85 | LastUpgradeCheck = 0920;
86 | ORGANIZATIONNAME = Facebook;
87 | TargetAttributes = {
88 | 58B511DA1A9E6C8500147676 = {
89 | CreatedOnToolsVersion = 6.1.1;
90 | };
91 | };
92 | };
93 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "WebWorker" */;
94 | compatibilityVersion = "Xcode 3.2";
95 | developmentRegion = English;
96 | hasScannedForEncodings = 0;
97 | knownRegions = (
98 | English,
99 | en,
100 | );
101 | mainGroup = 58B511D21A9E6C8500147676;
102 | productRefGroup = 58B511D21A9E6C8500147676;
103 | projectDirPath = "";
104 | projectRoot = "";
105 | targets = (
106 | 58B511DA1A9E6C8500147676 /* WebWorker */,
107 | );
108 | };
109 | /* End PBXProject section */
110 |
111 | /* Begin PBXSourcesBuildPhase section */
112 | 58B511D71A9E6C8500147676 /* Sources */ = {
113 | isa = PBXSourcesBuildPhase;
114 | buildActionMask = 2147483647;
115 | files = (
116 | B3E7B58A1CC2AC0600A0062D /* WebWorker.mm in Sources */,
117 | );
118 | runOnlyForDeploymentPostprocessing = 0;
119 | };
120 | /* End PBXSourcesBuildPhase section */
121 |
122 | /* Begin XCBuildConfiguration section */
123 | 58B511ED1A9E6C8500147676 /* Debug */ = {
124 | isa = XCBuildConfiguration;
125 | buildSettings = {
126 | ALWAYS_SEARCH_USER_PATHS = NO;
127 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
128 | CLANG_CXX_LIBRARY = "libc++";
129 | CLANG_ENABLE_MODULES = YES;
130 | CLANG_ENABLE_OBJC_ARC = YES;
131 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
132 | CLANG_WARN_BOOL_CONVERSION = YES;
133 | CLANG_WARN_COMMA = YES;
134 | CLANG_WARN_CONSTANT_CONVERSION = YES;
135 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
136 | CLANG_WARN_EMPTY_BODY = YES;
137 | CLANG_WARN_ENUM_CONVERSION = YES;
138 | CLANG_WARN_INFINITE_RECURSION = YES;
139 | CLANG_WARN_INT_CONVERSION = YES;
140 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
141 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
142 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
143 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
144 | CLANG_WARN_STRICT_PROTOTYPES = YES;
145 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
146 | CLANG_WARN_UNREACHABLE_CODE = YES;
147 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
148 | COPY_PHASE_STRIP = NO;
149 | ENABLE_STRICT_OBJC_MSGSEND = YES;
150 | ENABLE_TESTABILITY = YES;
151 | "EXCLUDED_ARCHS[sdk=*]" = arm64;
152 | GCC_C_LANGUAGE_STANDARD = gnu99;
153 | GCC_DYNAMIC_NO_PIC = NO;
154 | GCC_NO_COMMON_BLOCKS = YES;
155 | GCC_OPTIMIZATION_LEVEL = 0;
156 | GCC_PREPROCESSOR_DEFINITIONS = (
157 | "DEBUG=1",
158 | "$(inherited)",
159 | );
160 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
161 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
162 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
163 | GCC_WARN_UNDECLARED_SELECTOR = YES;
164 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
165 | GCC_WARN_UNUSED_FUNCTION = YES;
166 | GCC_WARN_UNUSED_VARIABLE = YES;
167 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
168 | MTL_ENABLE_DEBUG_INFO = YES;
169 | ONLY_ACTIVE_ARCH = YES;
170 | SDKROOT = iphoneos;
171 | };
172 | name = Debug;
173 | };
174 | 58B511EE1A9E6C8500147676 /* Release */ = {
175 | isa = XCBuildConfiguration;
176 | buildSettings = {
177 | ALWAYS_SEARCH_USER_PATHS = NO;
178 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
179 | CLANG_CXX_LIBRARY = "libc++";
180 | CLANG_ENABLE_MODULES = YES;
181 | CLANG_ENABLE_OBJC_ARC = YES;
182 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
183 | CLANG_WARN_BOOL_CONVERSION = YES;
184 | CLANG_WARN_COMMA = YES;
185 | CLANG_WARN_CONSTANT_CONVERSION = YES;
186 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
187 | CLANG_WARN_EMPTY_BODY = YES;
188 | CLANG_WARN_ENUM_CONVERSION = YES;
189 | CLANG_WARN_INFINITE_RECURSION = YES;
190 | CLANG_WARN_INT_CONVERSION = YES;
191 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
192 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
194 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
195 | CLANG_WARN_STRICT_PROTOTYPES = YES;
196 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
197 | CLANG_WARN_UNREACHABLE_CODE = YES;
198 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
199 | COPY_PHASE_STRIP = YES;
200 | ENABLE_NS_ASSERTIONS = NO;
201 | ENABLE_STRICT_OBJC_MSGSEND = YES;
202 | "EXCLUDED_ARCHS[sdk=*]" = arm64;
203 | GCC_C_LANGUAGE_STANDARD = gnu99;
204 | GCC_NO_COMMON_BLOCKS = YES;
205 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
206 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
207 | GCC_WARN_UNDECLARED_SELECTOR = YES;
208 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
209 | GCC_WARN_UNUSED_FUNCTION = YES;
210 | GCC_WARN_UNUSED_VARIABLE = YES;
211 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
212 | MTL_ENABLE_DEBUG_INFO = NO;
213 | SDKROOT = iphoneos;
214 | VALIDATE_PRODUCT = YES;
215 | };
216 | name = Release;
217 | };
218 | 58B511F01A9E6C8500147676 /* Debug */ = {
219 | isa = XCBuildConfiguration;
220 | buildSettings = {
221 | HEADER_SEARCH_PATHS = (
222 | "$(inherited)",
223 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
224 | "$(SRCROOT)/../../../React/**",
225 | "$(SRCROOT)/../../react-native/React/**",
226 | );
227 | LIBRARY_SEARCH_PATHS = "$(inherited)";
228 | OTHER_LDFLAGS = "-ObjC";
229 | PRODUCT_NAME = WebWorker;
230 | SKIP_INSTALL = YES;
231 | };
232 | name = Debug;
233 | };
234 | 58B511F11A9E6C8500147676 /* Release */ = {
235 | isa = XCBuildConfiguration;
236 | buildSettings = {
237 | HEADER_SEARCH_PATHS = (
238 | "$(inherited)",
239 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
240 | "$(SRCROOT)/../../../React/**",
241 | "$(SRCROOT)/../../react-native/React/**",
242 | );
243 | LIBRARY_SEARCH_PATHS = "$(inherited)";
244 | OTHER_LDFLAGS = "-ObjC";
245 | PRODUCT_NAME = WebWorker;
246 | SKIP_INSTALL = YES;
247 | };
248 | name = Release;
249 | };
250 | /* End XCBuildConfiguration section */
251 |
252 | /* Begin XCConfigurationList section */
253 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "WebWorker" */ = {
254 | isa = XCConfigurationList;
255 | buildConfigurations = (
256 | 58B511ED1A9E6C8500147676 /* Debug */,
257 | 58B511EE1A9E6C8500147676 /* Release */,
258 | );
259 | defaultConfigurationIsVisible = 0;
260 | defaultConfigurationName = Release;
261 | };
262 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "WebWorker" */ = {
263 | isa = XCConfigurationList;
264 | buildConfigurations = (
265 | 58B511F01A9E6C8500147676 /* Debug */,
266 | 58B511F11A9E6C8500147676 /* Release */,
267 | );
268 | defaultConfigurationIsVisible = 0;
269 | defaultConfigurationName = Release;
270 | };
271 | /* End XCConfigurationList section */
272 | };
273 | rootObject = 58B511D31A9E6C8500147676 /* Project object */;
274 | }
275 |
--------------------------------------------------------------------------------
/lefthook.yml:
--------------------------------------------------------------------------------
1 | pre-commit:
2 | parallel: true
3 | commands:
4 | lint:
5 | glob: "*.{js,ts,jsx,tsx}"
6 | run: npx eslint {staged_files}
7 | types:
8 | glob: "*.{js,ts, jsx, tsx}"
9 | run: npx tsc
10 | commit-msg:
11 | parallel: true
12 | commands:
13 | commitlint:
14 | run: npx commitlint --edit
15 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@jacobp100/react-native-webworker",
3 | "version": "0.2.11",
4 | "description": "WebWorkers for React Native",
5 | "source": "./src/index.ts",
6 | "main": "./lib/commonjs/index.js",
7 | "module": "./lib/module/index.js",
8 | "exports": {
9 | ".": {
10 | "import": {
11 | "types": "./lib/typescript/module/src/index.d.ts",
12 | "default": "./lib/module/index.js"
13 | },
14 | "require": {
15 | "types": "./lib/typescript/commonjs/src/index.d.ts",
16 | "default": "./lib/commonjs/index.js"
17 | }
18 | }
19 | },
20 | "files": [
21 | "src",
22 | "lib",
23 | "android",
24 | "ios",
25 | "cpp",
26 | "*.podspec",
27 | "!ios/build",
28 | "!android/build",
29 | "!android/gradle",
30 | "!android/gradlew",
31 | "!android/gradlew.bat",
32 | "!android/local.properties",
33 | "!**/__tests__",
34 | "!**/__fixtures__",
35 | "!**/__mocks__",
36 | "!**/.*"
37 | ],
38 | "scripts": {
39 | "example": "yarn workspace react-native-web-worker-example",
40 | "test": "jest",
41 | "typecheck": "tsc",
42 | "lint": "eslint \"**/*.{js,ts,tsx}\"",
43 | "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
44 | "prepare": "bob build",
45 | "release": "release-it"
46 | },
47 | "keywords": [
48 | "react-native",
49 | "ios",
50 | "android"
51 | ],
52 | "repository": {
53 | "type": "git",
54 | "url": "git+https://github.com/jacobp100/react-native-web-worker.git"
55 | },
56 | "author": "Jacob Parker (https://github.com/jacobp100)",
57 | "license": "MIT",
58 | "bugs": {
59 | "url": "https://github.com/jacobp100/react-native-web-worker/issues"
60 | },
61 | "homepage": "https://github.com/jacobp100/react-native-web-worker#readme",
62 | "publishConfig": {
63 | "registry": "https://registry.npmjs.org/"
64 | },
65 | "devDependencies": {
66 | "@commitlint/config-conventional": "^17.0.2",
67 | "@evilmartians/lefthook": "^1.5.0",
68 | "@react-native/eslint-config": "^0.73.1",
69 | "@release-it/conventional-changelog": "^5.0.0",
70 | "@types/jest": "^29.5.5",
71 | "@types/react": "^18.2.44",
72 | "commitlint": "^17.0.2",
73 | "del-cli": "^5.1.0",
74 | "eslint": "^8.51.0",
75 | "eslint-config-prettier": "^9.0.0",
76 | "eslint-plugin-prettier": "^5.0.1",
77 | "jest": "^29.7.0",
78 | "prettier": "^3.0.3",
79 | "react": "18.2.0",
80 | "react-native": "0.74.5",
81 | "react-native-builder-bob": "^0.29.1",
82 | "release-it": "^15.0.0",
83 | "turbo": "^1.10.7",
84 | "typescript": "^5.2.2"
85 | },
86 | "resolutions": {
87 | "@types/react": "^18.2.44"
88 | },
89 | "peerDependencies": {
90 | "react": "*",
91 | "react-native": "*"
92 | },
93 | "workspaces": [
94 | "example"
95 | ],
96 | "packageManager": "yarn@3.6.1",
97 | "jest": {
98 | "preset": "react-native",
99 | "modulePathIgnorePatterns": [
100 | "/example/node_modules",
101 | "/lib/"
102 | ]
103 | },
104 | "commitlint": {
105 | "extends": [
106 | "@commitlint/config-conventional"
107 | ]
108 | },
109 | "release-it": {
110 | "git": {
111 | "commitMessage": "chore: release ${version}",
112 | "tagName": "v${version}"
113 | },
114 | "npm": {
115 | "publish": true
116 | },
117 | "github": {
118 | "release": true
119 | },
120 | "plugins": {
121 | "@release-it/conventional-changelog": {
122 | "preset": "angular"
123 | }
124 | }
125 | },
126 | "eslintConfig": {
127 | "root": true,
128 | "extends": [
129 | "@react-native",
130 | "prettier"
131 | ],
132 | "rules": {
133 | "react/react-in-jsx-scope": "off",
134 | "prettier/prettier": [
135 | "error",
136 | {
137 | "quoteProps": "consistent",
138 | "singleQuote": true,
139 | "tabWidth": 2,
140 | "trailingComma": "es5",
141 | "useTabs": false
142 | }
143 | ]
144 | }
145 | },
146 | "eslintIgnore": [
147 | "node_modules/",
148 | "lib/"
149 | ],
150 | "prettier": {
151 | "quoteProps": "consistent",
152 | "singleQuote": true,
153 | "tabWidth": 2,
154 | "trailingComma": "es5",
155 | "useTabs": false
156 | },
157 | "react-native-builder-bob": {
158 | "source": "src",
159 | "output": "lib",
160 | "targets": [
161 | [
162 | "commonjs",
163 | {
164 | "esm": true
165 | }
166 | ],
167 | [
168 | "module",
169 | {
170 | "esm": true
171 | }
172 | ],
173 | [
174 | "typescript",
175 | {
176 | "project": "tsconfig.build.json",
177 | "esm": true
178 | }
179 | ]
180 | ]
181 | },
182 | "create-react-native-library": {
183 | "type": "module-legacy",
184 | "languages": "kotlin-objc",
185 | "version": "0.40.0"
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/react-native-web-worker.podspec:
--------------------------------------------------------------------------------
1 | require "json"
2 |
3 | package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4 | folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5 |
6 | Pod::Spec.new do |s|
7 | s.name = "react-native-web-worker"
8 | s.version = package["version"]
9 | s.summary = package["description"]
10 | s.homepage = package["homepage"]
11 | s.license = package["license"]
12 | s.authors = package["author"]
13 |
14 | s.platforms = { :ios => min_ios_version_supported }
15 | s.source = { :git => "https://github.com/jacobp100/react-native-web-worker.git", :tag => "#{s.version}" }
16 |
17 | s.source_files = "ios/**/*.{h,m,mm}"
18 |
19 | # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
20 | # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
21 | if respond_to?(:install_modules_dependencies, true)
22 | install_modules_dependencies(s)
23 | else
24 | s.dependency "React-Core"
25 | end
26 |
27 | use_hermes = false
28 | # Hermes is default so env var may be unset
29 | if ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == '1' then
30 | use_hermes = true
31 | elsif ENV['RNWW_USE_HERMES'] != nil then
32 | # Use Hermes for the worker, but not for RN
33 | # The only real use-case is if Hermes does not work with some libraries you use
34 | # But it does work for the worker - AND you need to be able to terminate the worker
35 | # To do this, open your Podfile andmake the following changes
36 | #
37 | # + ENV['RNWW_USE_HERMES'] = '1'
38 | #
39 | # target 'YourProject' do
40 | # ...
41 | # use_react_native!(...)
42 | # ...
43 | # + setup_hermes!()
44 | # +
45 | # + pre_install do |installer|
46 | # + installer.pod_targets.each do |pod|
47 | # + if pod.name == 'React-jsi'
48 | # + s = pod.root_spec
49 | # + s.dependency 'hermes-engine'
50 | # + s.exclude_files = [
51 | # + 'jsi/jsilib-posix.cpp',
52 | # + 'jsi/jsilib-windows.cpp',
53 | # + '**/test/*',
54 | # + 'jsi/jsi.cpp'
55 | # + ]
56 | # + end
57 | # + end
58 | # + end
59 | #
60 | # post_install do |installer|
61 | # ...
62 | # end
63 | # end
64 | #
65 | # Check the pre_install against the current source for React-jsi.podspec
66 | # It may have changed, and you may need to reflect some of the changes
67 | use_hermes = true
68 | end
69 |
70 | if use_hermes then
71 | s.dependency "hermes-engine"
72 | end
73 |
74 | # Don't install the dependencies when we run `pod install` in the old architecture.
75 | if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
76 | s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
77 | s.pod_target_xcconfig = {
78 | "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/Headers/Private/React-Core\" \"$(PODS_ROOT)/Headers/Private/React-Fabric\"",
79 | "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
80 | "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
81 | }
82 | s.dependency "React-Codegen"
83 | s.dependency "RCT-Folly"
84 | s.dependency "RCTRequired"
85 | s.dependency "RCTTypeSafety"
86 | s.dependency "ReactCommon/turbomodule/core"
87 |
88 | # Needed for AppSetupUtils
89 | s.dependency "React-RCTAppDelegate"
90 | end
91 | end
92 |
--------------------------------------------------------------------------------
/src/NativeSelf.ts:
--------------------------------------------------------------------------------
1 | import type { TurboModule } from 'react-native';
2 | import { TurboModuleRegistry } from 'react-native';
3 |
4 | export interface Spec extends TurboModule {
5 | postMessage: (data: string) => void;
6 | postError: (message: string, name: string) => void;
7 | // RCTEventEmitter
8 | addListener: (eventName: string) => void;
9 | removeListeners: (count: number) => void;
10 | }
11 |
12 | export default TurboModuleRegistry.getEnforcing('Self');
13 |
--------------------------------------------------------------------------------
/src/NativeWebWorker.ts:
--------------------------------------------------------------------------------
1 | import type { TurboModule } from 'react-native';
2 | import { TurboModuleRegistry } from 'react-native';
3 |
4 | export interface Spec extends TurboModule {
5 | startThread: (threadId: number, name: string, environment: string) => void;
6 | stopThread: (threadId: number) => void;
7 | postMessage: (threadId: number, message: string) => void;
8 | // RCTEventEmitter
9 | addListener: (eventName: string) => void;
10 | removeListeners: (count: number) => void;
11 | }
12 |
13 | export default TurboModuleRegistry.getEnforcing('WebWorker');
14 |
--------------------------------------------------------------------------------
/src/WebWorker.ts:
--------------------------------------------------------------------------------
1 | import { NativeModules, NativeEventEmitter } from 'react-native';
2 |
3 | // @ts-expect-error
4 | const isTurboModuleEnabled = global.__turboModuleProxy != null;
5 |
6 | const WebWorkerModule = isTurboModuleEnabled
7 | ? require('./NativeWebWorker').default
8 | : NativeModules.WebWorker;
9 | const ThreadEvents = new NativeEventEmitter(WebWorkerModule);
10 |
11 | let currentId = 0;
12 |
13 | type MessageEvent = { id: number; data: string };
14 | type ErrorEvent = { id: number; message: string; name: string };
15 |
16 | type WorkerOptions = {
17 | environment?: 'react-native' | 'light';
18 | };
19 |
20 | type TerminateOptions = {
21 | mode?: 'worker' | 'execution';
22 | };
23 |
24 | export default class Thread {
25 | id: number;
26 | onmessage: ((event: { data: string }) => void) | undefined;
27 | onerror: ((event: { message: string; name: string }) => void) | undefined;
28 |
29 | private terminated: boolean;
30 | private messageListener: { remove: () => void };
31 | private errorListener: { remove: () => void };
32 |
33 | constructor(
34 | jsPath: string,
35 | { environment = 'react-native' }: WorkerOptions = {}
36 | ) {
37 | if (typeof jsPath !== 'string' || !jsPath.endsWith('.js')) {
38 | throw new Error('Invalid path for thread. Only js files are supported');
39 | }
40 |
41 | this.id = currentId++;
42 | this.terminated = false;
43 |
44 | this.onmessage = undefined;
45 | this.onerror = undefined;
46 |
47 | this.messageListener = ThreadEvents.addListener(
48 | 'message',
49 | ({ id, data }: MessageEvent) => {
50 | if (
51 | !this.terminated &&
52 | id === this.id &&
53 | typeof this.onmessage === 'function'
54 | ) {
55 | this.onmessage({ data });
56 | }
57 | }
58 | );
59 |
60 | this.errorListener = ThreadEvents.addListener(
61 | 'error',
62 | ({ id, message, name }: ErrorEvent) => {
63 | if (
64 | !this.terminated &&
65 | id === this.id &&
66 | typeof this.onerror === 'function'
67 | ) {
68 | this.onerror({ message, name });
69 | }
70 | }
71 | );
72 |
73 | const name = jsPath.slice(0, -'.js'.length);
74 | WebWorkerModule.startThread(this.id, name, environment);
75 | }
76 |
77 | postMessage(message: string) {
78 | if (this.terminated) {
79 | if (__DEV__) {
80 | console.warn('Attempted to call postMessage on terminated worker');
81 | }
82 | return;
83 | }
84 |
85 | WebWorkerModule.postThreadMessage(this.id, message);
86 | }
87 |
88 | terminate({ mode = 'worker' }: TerminateOptions = {}) {
89 | if (this.terminated) {
90 | if (__DEV__) {
91 | console.warn('Attempted to call terminate on terminated worker');
92 | }
93 | return;
94 | }
95 |
96 | if (mode !== 'execution') {
97 | this.terminated = true;
98 | this.messageListener.remove();
99 | this.errorListener.remove();
100 | }
101 | WebWorkerModule.stopThread(this.id, mode);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export { default as self } from './self';
2 | export { default as WebWorker } from './WebWorker';
3 |
--------------------------------------------------------------------------------
/src/self.ts:
--------------------------------------------------------------------------------
1 | import { AppRegistry, NativeModules, NativeEventEmitter } from 'react-native';
2 |
3 | // @ts-expect-error
4 | const isTurboModuleEnabled = global.__turboModuleProxy != null;
5 |
6 | const SelfModule = isTurboModuleEnabled
7 | ? require('./NativeSelf').default
8 | : NativeModules.Self;
9 | const ThreadSelfManagerEvents = new NativeEventEmitter(SelfModule);
10 |
11 | export type Self = {
12 | postMessage: (message: string) => void;
13 | onmessage: ((event: { data: string }) => void) | undefined;
14 | };
15 |
16 | // Force AppRegistry to be required - even after minification
17 | // Without doing this, the UI freezes after seinding messages
18 | AppRegistry.getRunnable('x');
19 |
20 | const self: Self = {
21 | postMessage(data: string) {
22 | if (data != null) {
23 | SelfModule.postMessage(data);
24 | }
25 | },
26 | onmessage: undefined,
27 | };
28 |
29 | ThreadSelfManagerEvents.addListener('message', (data: string) => {
30 | if (typeof self.onmessage === 'function') {
31 | try {
32 | self.onmessage({ data });
33 | } catch (e: any) {
34 | SelfModule.postError(e.message ?? 'Unknown error', e.name);
35 | }
36 | }
37 | });
38 |
39 | export default self;
40 |
--------------------------------------------------------------------------------
/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig",
3 | "exclude": ["example", "lib"]
4 | }
5 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "rootDir": ".",
4 | "paths": {
5 | "@jacobp100/react-native-webworker": ["./src/index"]
6 | },
7 | "allowUnreachableCode": false,
8 | "allowUnusedLabels": false,
9 | "esModuleInterop": true,
10 | "forceConsistentCasingInFileNames": true,
11 | "jsx": "react-jsx",
12 | "lib": ["ESNext"],
13 | "module": "ESNext",
14 | "moduleResolution": "Bundler",
15 | "noEmit": true,
16 | "noFallthroughCasesInSwitch": true,
17 | "noImplicitReturns": true,
18 | "noImplicitUseStrict": false,
19 | "noStrictGenericChecks": false,
20 | "noUncheckedIndexedAccess": true,
21 | "noUnusedLocals": true,
22 | "noUnusedParameters": true,
23 | "resolveJsonModule": true,
24 | "skipLibCheck": true,
25 | "strict": true,
26 | "target": "ESNext",
27 | "verbatimModuleSyntax": true
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/turbo.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://turbo.build/schema.json",
3 | "pipeline": {
4 | "build:android": {
5 | "inputs": [
6 | "package.json",
7 | "android",
8 | "!android/build",
9 | "src/*.ts",
10 | "src/*.tsx",
11 | "example/package.json",
12 | "example/android",
13 | "!example/android/.gradle",
14 | "!example/android/build",
15 | "!example/android/app/build"
16 | ],
17 | "outputs": []
18 | },
19 | "build:ios": {
20 | "inputs": [
21 | "package.json",
22 | "*.podspec",
23 | "ios",
24 | "src/*.ts",
25 | "src/*.tsx",
26 | "example/package.json",
27 | "example/ios",
28 | "!example/ios/build",
29 | "!example/ios/Pods"
30 | ],
31 | "outputs": []
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------