Skip to content

Commit 1f9d55e

Browse files
authored
Merge pull request #1 from phantom/port-over-patches
Port over patches
2 parents 1ddfe70 + 141fb62 commit 1f9d55e

File tree

12 files changed

+536
-62
lines changed

12 files changed

+536
-62
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "master",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.changeset/many-experts-agree.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@phantom/react-native-webview': major
3+
---
4+
5+
Fork complete

.github/workflows/release.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
steps:
18+
- name: Checkout Repo
19+
uses: actions/checkout@v3
20+
21+
- name: Enable Corepack
22+
run: corepack enable
23+
24+
- name: Setup Node.js 20.x
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: 20.x
28+
29+
- name: Install Dependencies
30+
run: yarn
31+
32+
- name: Create Release Pull Request or Publish to npm
33+
id: changesets
34+
uses: changesets/action@v1
35+
with:
36+
# This expects you to have a script called release which does a build for your packages and calls changeset publish
37+
publish: yarn release
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN_PHANTOM_SECURITY_BOT }}

VERSIONING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Versioning and Publishing Packages
2+
3+
We use Changesets for versioning and GitHub Actions for publishing. The process is as follows:
4+
5+
1. After making changes, create a changeset locally:
6+
7+
```
8+
yarn changeset
9+
```
10+
11+
2. Follow the prompts to describe your changes and select the appropriate version bump.
12+
3. Commit the generated changeset file along with your code changes.
13+
14+
4. Push your changes and open a pull request:
15+
16+
```
17+
git push
18+
```
19+
20+
5. The pull request should contain your code changes and the new changeset file(s).
21+
22+
6. Once the pull request is merged to the main branch, the CI/CD pipeline (GitHub Actions) will automatically:
23+
24+
- Create a new "Version Packages" pull request that includes version bumps and changelog updates
25+
26+
7. Review the "Version Packages" pull request:
27+
28+
- Check that the version bumps and changelog entries are correct
29+
- Make any necessary adjustments
30+
- Approve the pull request
31+
32+
8. Merge the "Version Packages" pull request:
33+
34+
- This triggers the publish workflow
35+
36+
9. The publish workflow will automatically:
37+
- Publish the updated packages to our npm registry
38+
- Push the new version tags to the repository

android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ ReactNativeWebView_kotlinVersion=1.6.0
22
ReactNativeWebView_webkitVersion=1.4.0
33
ReactNativeWebView_compileSdkVersion=31
44
ReactNativeWebView_targetSdkVersion=31
5-
ReactNativeWebView_minSdkVersion=21
5+
ReactNativeWebView_minSdkVersion=24

android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ public void onPostMessage(@NonNull WebView view, @NonNull WebMessageCompat messa
274274
}
275275
}
276276
injectJavascriptObject();
277+
278+
if (WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)
279+
&& injectedJSBeforeContentLoaded != null
280+
&& !TextUtils.isEmpty(injectedJSBeforeContentLoaded)) {
281+
WebViewCompat.addDocumentStartJavaScript(
282+
webView,
283+
"(function() {\n" + injectedJSBeforeContentLoaded + ";\n})();",
284+
Set.of("*")
285+
);
286+
}
277287
}
278288

279289
private void injectJavascriptObject() {

android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -93,48 +93,8 @@ class RNCWebViewManagerImpl(private val newArch: Boolean = false) {
9393
}
9494
webView.setDownloadListener(DownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
9595
webView.setIgnoreErrFailedForThisURL(url)
96-
val module = webView.reactApplicationContext.getNativeModule(RNCWebViewModule::class.java) ?: return@DownloadListener
97-
val request: DownloadManager.Request = try {
98-
DownloadManager.Request(Uri.parse(url))
99-
} catch (e: IllegalArgumentException) {
100-
Log.w(TAG, "Unsupported URI, aborting download", e)
101-
return@DownloadListener
102-
}
103-
var fileName = URLUtil.guessFileName(url, contentDisposition, mimetype)
104-
105-
// Sanitize filename by replacing invalid characters with "_"
106-
fileName = fileName.replace(invalidCharRegex, "_")
107-
108-
val downloadMessage = "Downloading $fileName"
109-
110-
//Attempt to add cookie, if it exists
111-
var urlObj: URL? = null
112-
try {
113-
urlObj = URL(url)
114-
val baseUrl = urlObj.protocol + "://" + urlObj.host
115-
val cookie = CookieManager.getInstance().getCookie(baseUrl)
116-
request.addRequestHeader("Cookie", cookie)
117-
} catch (e: MalformedURLException) {
118-
Log.w(TAG, "Error getting cookie for DownloadManager", e)
119-
}
120-
121-
//Finish setting up request
122-
request.addRequestHeader("User-Agent", userAgent)
123-
request.setTitle(fileName)
124-
request.setDescription(downloadMessage)
125-
request.allowScanningByMediaScanner()
126-
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
127-
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
128-
module.setDownloadRequest(request)
129-
if (module.grantFileDownloaderPermissions(
130-
getDownloadingMessageOrDefault(),
131-
getLackPermissionToDownloadMessageOrDefault()
132-
)
133-
) {
134-
module.downloadFile(
135-
getDownloadingMessageOrDefault()
136-
)
137-
}
96+
android.widget.Toast.makeText(context, "File downloads are not supported", android.widget.Toast.LENGTH_SHORT).show();
97+
return@DownloadListener;
13898
})
13999
return RNCWebViewWrapper(context, webView)
140100
}

apple/RNCWebViewImpl.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ - (void)setInjectedJavaScriptObject:(NSString *)source
17131713
/* TODO: For a separate (minor) PR: use logic like this (as react-native-wkwebview does) so that messaging can be used in all frames if desired.
17141714
* I am keeping it as YES for consistency with previous behaviour. */
17151715
// forMainFrameOnly:_messagingEnabledForMainFrameOnly
1716-
forMainFrameOnly:YES
1716+
forMainFrameOnly:NO
17171717
];
17181718
}
17191719

@@ -1764,7 +1764,7 @@ - (void)setMessagingEnabled:(BOOL)messagingEnabled {
17641764
/* TODO: For a separate (minor) PR: use logic like this (as react-native-wkwebview does) so that messaging can be used in all frames if desired.
17651765
* I am keeping it as YES for consistency with previous behaviour. */
17661766
// forMainFrameOnly:_messagingEnabledForMainFrameOnly
1767-
forMainFrameOnly:YES
1767+
forMainFrameOnly:NO
17681768
] :
17691769
nil;
17701770

@@ -1837,7 +1837,7 @@ - (void)resetupScripts:(WKWebViewConfiguration *)wkWebViewConfig {
18371837
" })\n"
18381838
"})(window.history)\n", HistoryShimName
18391839
];
1840-
WKUserScript *userScript = [[WKUserScript alloc] initWithSource:html5HistoryAPIShimSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
1840+
WKUserScript *userScript = [[WKUserScript alloc] initWithSource:html5HistoryAPIShimSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
18411841
[wkWebViewConfig.userContentController addUserScript:userScript];
18421842

18431843
if(_sharedCookiesEnabled) {
@@ -1895,7 +1895,7 @@ - (void)resetupScripts:(WKWebViewConfiguration *)wkWebViewConfig {
18951895

18961896
WKUserScript* cookieInScript = [[WKUserScript alloc] initWithSource:script
18971897
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
1898-
forMainFrameOnly:YES];
1898+
forMainFrameOnly:NO];
18991899
[wkWebViewConfig.userContentController addUserScript:cookieInScript];
19001900
}
19011901
}

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
{
2-
"name": "react-native-webview",
3-
"description": "React Native WebView component for iOS, Android, macOS, and Windows",
2+
"name": "@phantom/react-native-webview",
3+
"description": "Phantom's fork of react-native-webview, based off of [email protected]",
44
"main": "index.js",
55
"main-internal": "src/index.ts",
66
"react-native": "src/index.ts",
77
"typings": "index.d.ts",
88
"author": "Jamon Holmgren <[email protected]>",
99
"contributors": [
10-
"Thibault Malbranche <[email protected]>"
10+
"Thibault Malbranche <[email protected]>",
11+
"Jakub Adamczyk <[email protected]>",
12+
"Napas Udomsak <[email protected]>"
1113
],
1214
"license": "MIT",
13-
"version": "13.13.5",
14-
"homepage": "https://github.com/react-native-webview/react-native-webview#readme",
15+
"version": "0.0.1",
16+
"homepage": "https://github.com/phantom/react-native-webview#readme",
1517
"scripts": {
18+
"release": "yarn changeset publish",
1619
"android": "react-native run-android",
1720
"ios": "react-native run-ios",
1821
"macos": "react-native run-macos --scheme WebviewExample --project-path example/macos",
@@ -45,6 +48,7 @@
4548
"@babel/core": "^7.20.0",
4649
"@babel/runtime": "^7.20.0",
4750
"@callstack/react-native-visionos": "0.73.8",
51+
"@changesets/cli": "^2.29.2",
4852
"@react-native/babel-preset": "0.73.21",
4953
"@react-native/eslint-config": "0.73.2",
5054
"@react-native/metro-config": "0.73.5",

0 commit comments

Comments
 (0)