@exodus/react-native-webview 11.26.1-exodus.26 → 11.26.1-exodus.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/.all-contributorsrc +185 -0
  2. package/.circleci/config.yml +66 -0
  3. package/.eslintignore +2 -0
  4. package/.eslintrc.js +94 -0
  5. package/.flowconfig +88 -0
  6. package/.flowconfig.android +88 -0
  7. package/.gitattributes +12 -0
  8. package/.github/CODEOWNERS +1 -0
  9. package/.github/ISSUE_TEMPLATE/bug-report.md +42 -0
  10. package/.github/ISSUE_TEMPLATE/feature_request.md +30 -0
  11. package/.github/workflows/android-ci.yml +35 -0
  12. package/.github/workflows/detox.yml +20 -0
  13. package/.github/workflows/ios-ci.yml +31 -0
  14. package/.github/workflows/scripts/install-vs-features.ps1 +108 -0
  15. package/.github/workflows/stale.yml +17 -0
  16. package/.gitignore +62 -0
  17. package/.prettierrc.js +10 -0
  18. package/.releaserc +15 -0
  19. package/.vscode/settings.json +9 -0
  20. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  21. package/android/.gradle/8.9/checksums/md5-checksums.bin +0 -0
  22. package/android/.gradle/8.9/checksums/sha1-checksums.bin +0 -0
  23. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  24. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  25. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  26. package/android/.gradle/8.9/gc.properties +0 -0
  27. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  28. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  29. package/android/.gradle/vcs-1/gc.properties +0 -0
  30. package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +1 -0
  31. package/apple/RNCWebView.m +10 -2
  32. package/babel.config.js +11 -0
  33. package/bin/setup +26 -0
  34. package/docs/Contributing.md +102 -0
  35. package/docs/Custom-Android.md +222 -0
  36. package/docs/Custom-iOS.md +236 -0
  37. package/docs/Debugging.md +101 -0
  38. package/docs/Getting-Started.md +142 -0
  39. package/docs/Guide.md +613 -0
  40. package/docs/Reference.md +1639 -0
  41. package/example/.gitignore +14 -0
  42. package/example/.watchmanconfig +1 -0
  43. package/example/App.tsx +262 -0
  44. package/example/android/.gradle/7.3.3/checksums/checksums.lock +0 -0
  45. package/example/android/.gradle/7.3.3/checksums/md5-checksums.bin +0 -0
  46. package/example/android/.gradle/7.3.3/checksums/sha1-checksums.bin +0 -0
  47. package/example/android/.gradle/7.3.3/dependencies-accessors/dependencies-accessors.lock +0 -0
  48. package/example/android/.gradle/7.3.3/dependencies-accessors/gc.properties +0 -0
  49. package/example/android/.gradle/7.3.3/executionHistory/executionHistory.lock +0 -0
  50. package/example/android/.gradle/7.3.3/fileChanges/last-build.bin +0 -0
  51. package/example/android/.gradle/7.3.3/fileHashes/fileHashes.lock +0 -0
  52. package/example/android/.gradle/7.3.3/gc.properties +0 -0
  53. package/example/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  54. package/example/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  55. package/example/android/.gradle/vcs-1/gc.properties +0 -0
  56. package/example/android/app/build/intermediates/cxx/abi_configuration_1a4zb4f4.json +14 -0
  57. package/example/android/app/build/intermediates/cxx/abi_configuration_1a4zb4f4.log +1 -0
  58. package/example/android/app/build/intermediates/cxx/abi_configuration_1a4zb4f4_key.json +18 -0
  59. package/example/android/app/build/intermediates/cxx/create_cxx_tasks_21_timing.txt +62 -0
  60. package/example/android/app/build/intermediates/cxx/ndk_locator_record_5i2h5t59.json +11 -0
  61. package/example/android/app/build/intermediates/cxx/ndk_locator_record_5i2h5t59.log +128 -0
  62. package/example/android/app/build/intermediates/cxx/ndk_locator_record_5i2h5t59_key.json +7 -0
  63. package/example/android/app/build/intermediates/cxx/ndk_locator_record_6n5y632q.json +11 -0
  64. package/example/android/app/build/intermediates/cxx/ndk_locator_record_6n5y632q.log +72 -0
  65. package/example/android/app/build/intermediates/cxx/ndk_locator_record_6n5y632q_key.json +8 -0
  66. package/example/android/build.gradle +15 -0
  67. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  68. package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  69. package/example/android/gradle.properties +34 -0
  70. package/example/android/gradlew +234 -0
  71. package/example/android/gradlew.bat +89 -0
  72. package/example/android/settings.gradle +12 -0
  73. package/example/app.json +20 -0
  74. package/example/assets/test.html +9 -0
  75. package/example/babel.config.js +3 -0
  76. package/example/examples/Alerts.tsx +72 -0
  77. package/example/examples/ApplePay.tsx +23 -0
  78. package/example/examples/Background.tsx +54 -0
  79. package/example/examples/Downloads.tsx +57 -0
  80. package/example/examples/Injection.tsx +161 -0
  81. package/example/examples/LocalPageLoad.tsx +16 -0
  82. package/example/examples/Messaging.tsx +63 -0
  83. package/example/examples/NativeWebpage.tsx +22 -0
  84. package/example/examples/Scrolling.tsx +68 -0
  85. package/example/examples/Uploads.tsx +69 -0
  86. package/example/index.js +9 -0
  87. package/example/ios/Podfile +8 -0
  88. package/example/ios/Podfile.lock +445 -0
  89. package/jest-setups/jest.setup.js +8 -0
  90. package/jest.config.js +184 -0
  91. package/lib/WebView.android.d.ts.map +1 -0
  92. package/lib/WebView.d.ts.map +1 -0
  93. package/lib/WebView.ios.d.ts.map +1 -0
  94. package/lib/WebView.styles.d.ts.map +1 -0
  95. package/lib/WebViewNativeComponent.android.d.ts.map +1 -0
  96. package/lib/WebViewNativeComponent.ios.d.ts.map +1 -0
  97. package/lib/WebViewShared.d.ts +1 -1
  98. package/lib/WebViewShared.d.ts.map +1 -0
  99. package/lib/WebViewShared.js +1 -3
  100. package/lib/WebViewTypes.d.ts.map +1 -0
  101. package/lib/index.d.ts.map +1 -0
  102. package/metro.config.js +57 -0
  103. package/package.json +2 -2
  104. package/src/WebView.android.tsx +255 -0
  105. package/src/WebView.ios.tsx +227 -0
  106. package/src/WebView.styles.ts +44 -0
  107. package/src/WebView.tsx +18 -0
  108. package/src/WebViewNativeComponent.android.ts +8 -0
  109. package/src/WebViewNativeComponent.ios.ts +8 -0
  110. package/src/WebViewShared.tsx +318 -0
  111. package/src/WebViewTypes.ts +941 -0
  112. package/src/__tests__/WebViewShared-test.js +292 -0
  113. package/src/__tests__/__snapshots__/WebViewShared-test.js.snap +13 -0
  114. package/src/index.ts +4 -0
  115. package/tsconfig.json +24 -0
  116. package/yarn.lock +13397 -0
@@ -0,0 +1,31 @@
1
+ name: iOS
2
+ on: [push, pull_request]
3
+ jobs:
4
+ build:
5
+ runs-on: macos-12
6
+ steps:
7
+ - name: Checkout
8
+ uses: actions/checkout@v2
9
+ - name: Set up Node.js
10
+ uses: actions/setup-node@v2.5.1
11
+ with:
12
+ node-version: 16
13
+ - name: Cache /node_modules
14
+ uses: actions/cache@v2
15
+ with:
16
+ path: node_modules
17
+ key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
18
+ - name: Install npm dependencies
19
+ run: yarn --frozen-lockfile
20
+ - name: Install Pods
21
+ run: pod install
22
+ working-directory: example/ios
23
+ - name: Build iOS test app
24
+ run: |
25
+ device_name='iPhone 13'
26
+ device=$(xcrun simctl list devices "${device_name}" available | grep "${device_name} (")
27
+ re='\(([-0-9A-Fa-f]+)\)'
28
+ [[ $device =~ $re ]] || exit 1
29
+ xcodebuild -workspace WebviewExample.xcworkspace -scheme ReactTestApp -destination "platform=iOS Simulator,id=${BASH_REMATCH[1]}" CODE_SIGNING_ALLOWED=NO COMPILER_INDEX_STORE_ENABLE=NO build
30
+ working-directory: example/ios
31
+ timeout-minutes: 60
@@ -0,0 +1,108 @@
1
+ param (
2
+ [Parameter(Mandatory=$true)]
3
+ [string[]] $Components,
4
+
5
+ [uri] $InstallerUri = "https://download.visualstudio.microsoft.com/download/pr/c4fef23e-cc45-4836-9544-70e213134bc8/1ee5717e9a1e05015756dff77eb27d554a79a6db91f2716d836df368381af9a1/vs_Enterprise.exe",
6
+
7
+ [string] $VsInstaller = "${env:System_DefaultWorkingDirectory}\vs_Enterprise.exe",
8
+
9
+ [string] $VsInstallOutputDir = "${env:System_DefaultWorkingDirectory}\vs",
10
+
11
+ [System.IO.FileInfo] $VsInstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise",
12
+
13
+ [System.IO.FileInfo] $VsInstallerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer",
14
+
15
+ [switch] $Collect = $false,
16
+
17
+ [switch] $Cleanup = $false,
18
+
19
+ [switch] $UseWebInstaller = $false
20
+ )
21
+
22
+ $Components | ForEach-Object {
23
+ $componentList += '--add', $_
24
+ }
25
+
26
+ $LocalVsInstaller = "$VsInstallerPath\vs_installershell.exe"
27
+
28
+ $UseWebInstaller = $UseWebInstaller -or -not (Test-Path -Path "$LocalVsInstaller")
29
+
30
+ if ($UseWebInstaller) {
31
+ Write-Host "Downloading web installer..."
32
+
33
+ Invoke-WebRequest -Method Get `
34
+ -Uri $InstallerUri `
35
+ -OutFile $VsInstaller
36
+
37
+ New-Item -ItemType directory -Path $VsInstallOutputDir
38
+
39
+ Write-Host "Running web installer to download requested components..."
40
+
41
+ Start-Process `
42
+ -FilePath "$VsInstaller" `
43
+ -ArgumentList ( `
44
+ '--layout', "$VsInstallOutputDir",
45
+ '--wait',
46
+ '--norestart',
47
+ '--quiet' + `
48
+ $componentList
49
+ ) `
50
+ -Wait `
51
+ -PassThru
52
+
53
+ Write-Host "Running downloaded VS installer to add requested components..."
54
+
55
+ Start-Process `
56
+ -FilePath "$VsInstallOutputDir\vs_Enterprise.exe" `
57
+ -ArgumentList (
58
+ 'modify',
59
+ '--installPath', "`"$VsInstallPath`"" ,
60
+ '--wait',
61
+ '--norestart',
62
+ '--quiet' + `
63
+ $componentList
64
+ ) `
65
+ -Wait `
66
+ -PassThru `
67
+ -OutVariable returnCode
68
+
69
+ if ($Cleanup) {
70
+ Write-Host "Cleaning up..."
71
+
72
+ Remove-Item -Path $VsInstaller
73
+ Remove-Item -Path $VsInstallOutputDir -Recurse
74
+ }
75
+
76
+ } else {
77
+ Write-Host "Running local installer to add requested components..."
78
+
79
+ Start-Process `
80
+ -FilePath "$LocalVsInstaller" `
81
+ -ArgumentList (
82
+ 'modify',
83
+ '--installPath', "`"$VsInstallPath`"" ,
84
+ '--norestart',
85
+ '--quiet' + `
86
+ $componentList
87
+ ) `
88
+ -Wait `
89
+ -OutVariable returnCode
90
+ }
91
+
92
+ if ($Collect) {
93
+ Invoke-WebRequest -Method Get `
94
+ -Uri 'https://download.microsoft.com/download/8/3/4/834E83F6-C377-4DCE-A757-69A418B6C6DF/Collect.exe' `
95
+ -OutFile ${env:System_DefaultWorkingDirectory}\Collect.exe
96
+
97
+ # Should generate ${env:Temp}\vslogs.zip
98
+ Start-Process `
99
+ -FilePath "${env:System_DefaultWorkingDirectory}\Collect.exe" `
100
+ -Wait `
101
+ -PassThru
102
+
103
+ New-Item -ItemType Directory -Force ${env:System_DefaultWorkingDirectory}\vslogs
104
+ Expand-Archive -Path ${env:TEMP}\vslogs.zip -DestinationPath ${env:System_DefaultWorkingDirectory}\vslogs\
105
+
106
+ Write-Host "VC versions after installation:"
107
+ Get-ChildItem -Name "$VsInstallPath\VC\Tools\MSVC\"
108
+ }
@@ -0,0 +1,17 @@
1
+ name: "Close stale issues and PRs"
2
+ on:
3
+ schedule:
4
+ - cron: "0 0 * * *"
5
+
6
+ jobs:
7
+ stale:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/stale@v3.0.14
11
+ with:
12
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
13
+ stale-issue-message: 'Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like _still searching for solutions_ and if you found one, please open a pull request! You have 7 days until this gets closed automatically'
14
+ stale-pr-message: 'Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically'
15
+ exempt-issue-label: 'Keep opened'
16
+ exempt-pr-label: 'Keep opened'
17
+ remove-stale-when-updated: true
package/.gitignore ADDED
@@ -0,0 +1,62 @@
1
+ # OSX
2
+ #
3
+ .DS_Store
4
+
5
+ # Xcode
6
+ #
7
+ .xcode.env
8
+ build/
9
+ *.pbxuser
10
+ !default.pbxuser
11
+ *.mode1v3
12
+ !default.mode1v3
13
+ *.mode2v3
14
+ !default.mode2v3
15
+ *.perspectivev3
16
+ !default.perspectivev3
17
+ xcuserdata
18
+ *.xccheckout
19
+ *.moved-aside
20
+ DerivedData
21
+ *.hmap
22
+ *.ipa
23
+ *.xcuserstate
24
+ project.xcworkspace
25
+ Pods/
26
+
27
+ # Android/IJ
28
+ #
29
+ .idea
30
+ *.iml
31
+ .gradle
32
+ local.properties
33
+ lib/android/src/main/gen
34
+
35
+ # node.js
36
+ #
37
+ node_modules/
38
+ npm-debug.log
39
+ yarn-error.log
40
+ package-lock.json
41
+
42
+ # Rubygem bundles
43
+ #
44
+ bundles/
45
+
46
+ # VS Code
47
+ .vscode/*
48
+ !.vscode/settings.json
49
+ !.vscode/tasks.json
50
+ !.vscode/launch.json
51
+ !.vscode/extensions.json
52
+
53
+ android/gradle
54
+ android/gradlew
55
+ android/gradlew.bat
56
+
57
+ lib/
58
+ .classpath
59
+ .project
60
+ .settings/
61
+ msbuild.binlog
62
+ example/msbuild.binlog
package/.prettierrc.js ADDED
@@ -0,0 +1,10 @@
1
+ // https://prettier.io/docs/en/options.html
2
+
3
+ module.exports = {
4
+ // Enables semicolons at the end of statements
5
+ semi: true,
6
+ // Formats strings with single quotes ('') instead of quotes ("")
7
+ singleQuote: true,
8
+ // Adds a trailing comma at the end of all lists (including function arguments)
9
+ trailingComma: 'all',
10
+ };
package/.releaserc ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "plugins": [
3
+ "@semantic-release/commit-analyzer",
4
+ "@semantic-release/release-notes-generator",
5
+ "@semantic-release/npm",
6
+ "@semantic-release/github",
7
+ [
8
+ "@semantic-release/git",
9
+ {
10
+ "assets": "package.json",
11
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
12
+ }
13
+ ]
14
+ ]
15
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "typescript.tsdk": "node_modules/typescript/lib",
3
+ "eslint.validate": [
4
+ "javascript",
5
+ "javascriptreact",
6
+ "typescript",
7
+ "typescriptreact"
8
+ ]
9
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ #Mon Sep 02 09:44:40 CEST 2024
2
+ gradle.version=8.9
File without changes
@@ -171,6 +171,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
171
171
  public RNCWebViewManager() {
172
172
  cameraPermissionOriginWhitelist = new HashSet<>();
173
173
  cameraPermissionOriginWhitelist.add("https://alchemy.veriff.com/");
174
+ cameraPermissionOriginWhitelist.add("https://magic.veriff.me/");
174
175
 
175
176
  mWebViewConfig = new WebViewConfig() {
176
177
  public void configWebView(WebView webView) {
@@ -580,6 +580,14 @@ RCTAutoInsetsProtocol>
580
580
  }
581
581
  }
582
582
  #endif
583
+
584
+ - (NSMutableDictionary<NSString *, id> *)baseEventWithScriptMessage:(WKScriptMessage *)message {
585
+ NSMutableDictionary<NSString *, id> *event = [self baseEvent];
586
+ NSString *messageOriginURL = message.frameInfo.request.URL.absoluteString ?: @"";
587
+ event[@"url"] = messageOriginURL;
588
+ return event;
589
+ }
590
+
583
591
  /**
584
592
  * This method is called whenever JavaScript running within the web view calls:
585
593
  * - window.webkit.messageHandlers[MessageHandlerName].postMessage
@@ -589,13 +597,13 @@ RCTAutoInsetsProtocol>
589
597
  {
590
598
  if ([message.name isEqualToString:HistoryShimName]) {
591
599
  if (_onLoadingFinish) {
592
- NSMutableDictionary<NSString *, id> *event = [self baseEvent];
600
+ NSMutableDictionary<NSString *, id> *event = [self baseEventWithScriptMessage:message];
593
601
  [event addEntriesFromDictionary: @{@"navigationType": message.body}];
594
602
  _onLoadingFinish(event);
595
603
  }
596
604
  } else if ([message.name isEqualToString:MessageHandlerName]) {
597
605
  if (_onMessage) {
598
- NSMutableDictionary<NSString *, id> *event = [self baseEvent];
606
+ NSMutableDictionary<NSString *, id> *event = [self baseEventWithScriptMessage:message];
599
607
  [event addEntriesFromDictionary: @{@"data": message.body}];
600
608
  _onMessage(event);
601
609
  }
@@ -0,0 +1,11 @@
1
+ module.exports = function(api) {
2
+ api && api.cache(false);
3
+ return {
4
+ env: {
5
+ test: {
6
+ presets: ['module:metro-react-native-babel-preset'],
7
+ },
8
+ },
9
+ presets: ['module:metro-react-native-babel-preset'],
10
+ };
11
+ };
package/bin/setup ADDED
@@ -0,0 +1,26 @@
1
+ #! /bin/bash
2
+
3
+ # Node installed?
4
+ if ! [ -x "$(command -v node)" ]; then
5
+ echo 'Error: node is not installed.' >&2
6
+
7
+ if ! [ -x "$(command -v brew)" ]; then
8
+ echo 'Go here to install: https://nodejs.org/en/download/'
9
+ fi
10
+
11
+ if [ -x "$(command -v brew)" ]; then
12
+ echo 'You have Homebrew installed, so run "brew install node".'
13
+ fi
14
+
15
+ exit 1
16
+ fi
17
+
18
+ # React Native installed?
19
+ if ! [ -x "$(command -v react-native)" ]; then
20
+ echo 'Error: React Native is not installed.' >&2
21
+ echo 'Go here: https://reactnative.dev/docs/getting-started.html' >&2
22
+ echo 'Use the "Building Projects With Native Code" option.'
23
+ exit 1
24
+ fi
25
+
26
+ # TODO: Automate setup on new machines
@@ -0,0 +1,102 @@
1
+ # Contributing to React Native WebView
2
+
3
+ First off, _thank you_ for considering contributing to the React Native Community. The community-supported packages are only possible because of amazing people like you.
4
+
5
+ Secondly, we'd like the contribution experience to be as good as possible. While we are a small all-volunteer team, we are happy to hear feedback about your experience, and if we can make the docs or experience better please let us know.
6
+
7
+ ## How to test changes
8
+
9
+ After you fork the repo, clone it to your machine, and make your changes, you'll want to test them in an app.
10
+
11
+ There are two methods of testing:
12
+ 1) Testing within a clone of react-native-webview
13
+ 2) Testing in a new `react-native init` project
14
+
15
+ ### Testing within react-native-webview
16
+
17
+ #### For all platforms:
18
+
19
+ ```sh
20
+ yarn install
21
+ ```
22
+
23
+ #### For Android:
24
+
25
+ ```sh
26
+ yarn android
27
+ ```
28
+
29
+ The Android example app will built, the Metro Bundler will launch, and the example app will be installed and started in the Android emulator.
30
+
31
+ #### For iOS:
32
+
33
+ ```sh
34
+ pod install --project-directory=ios
35
+ yarn ios
36
+ ```
37
+
38
+ The iOS example app will be built, the Metro bundler will launch, and the example app will be installed and started in the Simulator.
39
+
40
+ #### For macOS:
41
+
42
+ ```sh
43
+ pod install --project-directory=macos
44
+ yarn macos
45
+ ```
46
+
47
+ The macOS example app will be built, the Metro bundler will launch, and the example app will be installed and started.
48
+
49
+ #### For Windows:
50
+
51
+ ```sh
52
+ yarn windows
53
+ ```
54
+
55
+ The Windows example app will be built, the Metro bundler will launch, and the example app will be installed and started.
56
+
57
+ ### Testing in a new `react-native init` project
58
+
59
+ In a new `react-native init` project, do this:
60
+
61
+ ```
62
+ $ yarn add ../react-native-webview
63
+ $ react-native link react-native-webview
64
+ ```
65
+
66
+ You may run into a problem where the `jest-haste-map` module map says react-native was added twice:
67
+
68
+ ```
69
+ Loading dependency graph...(node:32651) UnhandledPromiseRejectionWarning: Error: jest-haste-map: Haste module naming collision:
70
+ Duplicate module name: react-native
71
+ Paths: /Users/myuser/TestApp/node_modules/react-native/package.json collides with /Users/myuser/TestApp/node_modules/react-native-webview/node_modules/react-native/package.json
72
+ ```
73
+
74
+ Just remove the second path like this:
75
+
76
+ ```
77
+ $ rm -rf ./node_modules/react-native-webview/node_modules/react-native
78
+ ```
79
+
80
+ And then re-run the packager:
81
+
82
+ ```
83
+ $ react-native start --reset-cache
84
+ ```
85
+
86
+ When you make a change, you'll probably need to unlink, remove, re-add, and re-link `react-native-webview`:
87
+
88
+ ```
89
+ $ react-native unlink react-native-webview && yarn remove react-native-webview
90
+ $ yarn add ../react-native-webview && react-native link react-native-webview
91
+ ```
92
+
93
+ ## Notes
94
+
95
+ - We use TypeScript.
96
+ - After pulling this repo and installing all dependencies, you can run tests using the command: `yarn ci`
97
+
98
+ ## Translations
99
+
100
+ This file is available at:
101
+
102
+ - [Brazilian portuguese](Contributing.portuguese.md)
@@ -0,0 +1,222 @@
1
+ While the built-in web view has a lot of features, it is not possible to handle every use-case in React Native. You can, however, extend the web view with native code without forking React Native or duplicating all the existing web view code.
2
+
3
+ Before you do this, you should be familiar with the concepts in [native UI components](https://reactnative.dev/docs/native-components-android). You should also familiarise yourself with the [native code for web views](https://github.com/react-native-webview/react-native-webview/blob/master/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java), as you will have to use this as a reference when implementing new features—although a deep understanding is not required.
4
+
5
+ ## Native Code
6
+
7
+ To get started, you'll need to create a subclass of `RNCWebViewManager`, `RNCWebView`, and `RNCWebViewClient`. In your view manager, you'll then need to override:
8
+
9
+ - `createReactWebViewInstance`
10
+ - `getName`
11
+ - `addEventEmitters`
12
+
13
+ ```java
14
+ @ReactModule(name = CustomWebViewManager.REACT_CLASS)
15
+ public class CustomWebViewManager extends RNCWebViewManager {
16
+ /* This name must match what we're referring to in JS */
17
+ protected static final String REACT_CLASS = "RCTCustomWebView";
18
+
19
+ protected static class CustomWebViewClient extends RNCWebViewClient { }
20
+
21
+ protected static class CustomWebView extends RNCWebView {
22
+ public CustomWebView(ThemedReactContext reactContext) {
23
+ super(reactContext);
24
+ }
25
+ }
26
+
27
+ @Override
28
+ protected RNCWebView createRNCWebViewInstance(ThemedReactContext reactContext) {
29
+ return new CustomWebView(reactContext);
30
+ }
31
+
32
+ @Override
33
+ public String getName() {
34
+ return REACT_CLASS;
35
+ }
36
+
37
+ @Override
38
+ protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
39
+ view.setWebViewClient(new CustomWebViewClient());
40
+ }
41
+ }
42
+ ```
43
+
44
+ You'll need to follow the usual steps to [register the module](https://reactnative.dev/docs/native-modules-android#register-the-module-android-specific).
45
+
46
+ ### Adding New Properties
47
+
48
+ To add a new property, you'll need to add it to `CustomWebView`, and then expose it in `CustomWebViewManager`.
49
+
50
+ ```java
51
+ public class CustomWebViewManager extends RNCWebViewManager {
52
+ ...
53
+
54
+ protected static class CustomWebView extends RNCWebView {
55
+ public CustomWebView(ThemedReactContext reactContext) {
56
+ super(reactContext);
57
+ }
58
+
59
+ protected @Nullable String mFinalUrl;
60
+
61
+ public void setFinalUrl(String url) {
62
+ mFinalUrl = url;
63
+ }
64
+
65
+ public String getFinalUrl() {
66
+ return mFinalUrl;
67
+ }
68
+ }
69
+
70
+ ...
71
+
72
+ @ReactProp(name = "finalUrl")
73
+ public void setFinalUrl(WebView view, String url) {
74
+ ((CustomWebView) view).setFinalUrl(url);
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### Adding New Events
80
+
81
+ For events, you'll first need to make create event subclass.
82
+
83
+ ```java
84
+ // NavigationCompletedEvent.java
85
+ public class NavigationCompletedEvent extends Event<NavigationCompletedEvent> {
86
+ private WritableMap mParams;
87
+
88
+ public NavigationCompletedEvent(int viewTag, WritableMap params) {
89
+ super(viewTag);
90
+ this.mParams = params;
91
+ }
92
+
93
+ @Override
94
+ public String getEventName() {
95
+ return "navigationCompleted";
96
+ }
97
+
98
+ @Override
99
+ public void dispatch(RCTEventEmitter rctEventEmitter) {
100
+ init(getViewTag());
101
+ rctEventEmitter.receiveEvent(getViewTag(), getEventName(), mParams);
102
+ }
103
+ }
104
+ ```
105
+
106
+ You can trigger the event in your web view client. You can hook existing handlers if your events are based on them.
107
+
108
+ You should refer to [RNCWebViewManager.java](https://github.com/react-native-webview/react-native-webview/blob/master/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java) in the react-native-webview codebase to see what handlers are available and how they are implemented. You can extend any methods here to provide extra functionality.
109
+
110
+ ```java
111
+ public class NavigationCompletedEvent extends Event<NavigationCompletedEvent> {
112
+ private WritableMap mParams;
113
+
114
+ public NavigationCompletedEvent(int viewTag, WritableMap params) {
115
+ super(viewTag);
116
+ this.mParams = params;
117
+ }
118
+
119
+ @Override
120
+ public String getEventName() {
121
+ return "navigationCompleted";
122
+ }
123
+
124
+ @Override
125
+ public void dispatch(RCTEventEmitter rctEventEmitter) {
126
+ init(getViewTag());
127
+ rctEventEmitter.receiveEvent(getViewTag(), getEventName(), mParams);
128
+ }
129
+ }
130
+
131
+ // CustomWebViewManager.java
132
+ protected static class CustomWebViewClient extends RNCWebViewClient {
133
+ @Override
134
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
135
+ boolean shouldOverride = super.shouldOverrideUrlLoading(view, url);
136
+ String finalUrl = ((CustomWebView) view).getFinalUrl();
137
+
138
+ if (!shouldOverride && url != null && finalUrl != null && new String(url).equals(finalUrl)) {
139
+ final WritableMap params = Arguments.createMap();
140
+ dispatchEvent(view, new NavigationCompletedEvent(view.getId(), params));
141
+ }
142
+
143
+ return shouldOverride;
144
+ }
145
+ }
146
+ ```
147
+
148
+ Finally, you'll need to expose the events in `CustomWebViewManager` through `getExportedCustomDirectEventTypeConstants`. Note that currently, the default implementation returns `null`, but this may change in the future.
149
+
150
+ ```java
151
+ public class CustomWebViewManager extends RNCWebViewManager {
152
+ ...
153
+
154
+ @Override
155
+ public @Nullable
156
+ Map getExportedCustomDirectEventTypeConstants() {
157
+ Map<String, Object> export = super.getExportedCustomDirectEventTypeConstants();
158
+ if (export == null) {
159
+ export = MapBuilder.newHashMap();
160
+ }
161
+ export.put("navigationCompleted", MapBuilder.of("registrationName", "onNavigationCompleted"));
162
+ return export;
163
+ }
164
+ }
165
+ ```
166
+
167
+ ## JavaScript Interface
168
+
169
+ To use your custom web view, you may want to create a class for it. Your class must return a `WebView` component with the prop `nativeConfig.component` set to your native component (see below).
170
+
171
+ To get your native component, you must use `requireNativeComponent`: the same as for regular custom components.
172
+
173
+ ```javascript
174
+ import React, { Component } from 'react';
175
+ import { requireNativeComponent } from 'react-native';
176
+ import { WebView } from 'react-native-webview';
177
+
178
+ export default class CustomWebView extends Component {
179
+ render() {
180
+ return (
181
+ <WebView {...this.props} nativeConfig={{ component: RCTCustomWebView }} />
182
+ );
183
+ }
184
+ }
185
+
186
+ const RCTCustomWebView = requireNativeComponent('RCTCustomWebView');
187
+ ```
188
+
189
+ If you want to add custom props to your native component, you can use `nativeConfig.props` on the web view.
190
+
191
+ For events, the event handler must always be set to a function. This means it isn't safe to use the event handler directly from `this.props`, as the user might not have provided one. The standard approach is to create a event handler in your class, and then invoking the event handler given in `this.props` if it exists.
192
+
193
+ If you are unsure how something should be implemented from the JS side, look at [WebView.android.tsx](https://github.com/react-native-webview/react-native-webview/blob/master/src/WebView.android.tsx) in the React Native WebView source.
194
+
195
+ ```javascript
196
+ export default class CustomWebView extends Component {
197
+ _onNavigationCompleted = (event) => {
198
+ const { onNavigationCompleted } = this.props;
199
+ onNavigationCompleted && onNavigationCompleted(event);
200
+ };
201
+
202
+ render() {
203
+ return (
204
+ <WebView
205
+ {...this.props}
206
+ nativeConfig={{
207
+ component: RCTCustomWebView,
208
+ props: {
209
+ finalUrl: this.props.finalUrl,
210
+ onNavigationCompleted: this._onNavigationCompleted,
211
+ },
212
+ }}
213
+ />
214
+ );
215
+ }
216
+ }
217
+ ```
218
+ ## Translations
219
+
220
+ This file is available at:
221
+
222
+ - [Brazilian portuguese](Custom-Android.portuguese.md)