Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/many-experts-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@phantom/react-native-webview': major
---

Fork complete
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release

on:
push:
branches:
- master

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Enable Corepack
run: corepack enable

- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install Dependencies
run: yarn

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN_PHANTOM_SECURITY_BOT }}
38 changes: 38 additions & 0 deletions VERSIONING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Versioning and Publishing Packages

We use Changesets for versioning and GitHub Actions for publishing. The process is as follows:

1. After making changes, create a changeset locally:

```
yarn changeset
```

2. Follow the prompts to describe your changes and select the appropriate version bump.
3. Commit the generated changeset file along with your code changes.

4. Push your changes and open a pull request:

```
git push
```

5. The pull request should contain your code changes and the new changeset file(s).

6. Once the pull request is merged to the main branch, the CI/CD pipeline (GitHub Actions) will automatically:

- Create a new "Version Packages" pull request that includes version bumps and changelog updates

7. Review the "Version Packages" pull request:

- Check that the version bumps and changelog entries are correct
- Make any necessary adjustments
- Approve the pull request

8. Merge the "Version Packages" pull request:

- This triggers the publish workflow

9. The publish workflow will automatically:
- Publish the updated packages to our npm registry
- Push the new version tags to the repository
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ ReactNativeWebView_kotlinVersion=1.6.0
ReactNativeWebView_webkitVersion=1.4.0
ReactNativeWebView_compileSdkVersion=31
ReactNativeWebView_targetSdkVersion=31
ReactNativeWebView_minSdkVersion=21
ReactNativeWebView_minSdkVersion=24
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ public void onPostMessage(@NonNull WebView view, @NonNull WebMessageCompat messa
}
}
injectJavascriptObject();

if (WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)
&& injectedJSBeforeContentLoaded != null
&& !TextUtils.isEmpty(injectedJSBeforeContentLoaded)) {
WebViewCompat.addDocumentStartJavaScript(
webView,
"(function() {\n" + injectedJSBeforeContentLoaded + ";\n})();",
Set.of("*")
);
}
}

private void injectJavascriptObject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,48 +93,8 @@ class RNCWebViewManagerImpl(private val newArch: Boolean = false) {
}
webView.setDownloadListener(DownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
webView.setIgnoreErrFailedForThisURL(url)
val module = webView.reactApplicationContext.getNativeModule(RNCWebViewModule::class.java) ?: return@DownloadListener
val request: DownloadManager.Request = try {
DownloadManager.Request(Uri.parse(url))
} catch (e: IllegalArgumentException) {
Log.w(TAG, "Unsupported URI, aborting download", e)
return@DownloadListener
}
var fileName = URLUtil.guessFileName(url, contentDisposition, mimetype)

// Sanitize filename by replacing invalid characters with "_"
fileName = fileName.replace(invalidCharRegex, "_")

val downloadMessage = "Downloading $fileName"

//Attempt to add cookie, if it exists
var urlObj: URL? = null
try {
urlObj = URL(url)
val baseUrl = urlObj.protocol + "://" + urlObj.host
val cookie = CookieManager.getInstance().getCookie(baseUrl)
request.addRequestHeader("Cookie", cookie)
} catch (e: MalformedURLException) {
Log.w(TAG, "Error getting cookie for DownloadManager", e)
}

//Finish setting up request
request.addRequestHeader("User-Agent", userAgent)
request.setTitle(fileName)
request.setDescription(downloadMessage)
request.allowScanningByMediaScanner()
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
module.setDownloadRequest(request)
if (module.grantFileDownloaderPermissions(
getDownloadingMessageOrDefault(),
getLackPermissionToDownloadMessageOrDefault()
)
) {
module.downloadFile(
getDownloadingMessageOrDefault()
)
}
android.widget.Toast.makeText(context, "File downloads are not supported", android.widget.Toast.LENGTH_SHORT).show();
return@DownloadListener;
})
return RNCWebViewWrapper(context, webView)
}
Expand Down
8 changes: 4 additions & 4 deletions apple/RNCWebViewImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ - (void)setInjectedJavaScriptObject:(NSString *)source
/* 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.
* I am keeping it as YES for consistency with previous behaviour. */
// forMainFrameOnly:_messagingEnabledForMainFrameOnly
forMainFrameOnly:YES
forMainFrameOnly:NO
];
}

Expand Down Expand Up @@ -1764,7 +1764,7 @@ - (void)setMessagingEnabled:(BOOL)messagingEnabled {
/* 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.
* I am keeping it as YES for consistency with previous behaviour. */
// forMainFrameOnly:_messagingEnabledForMainFrameOnly
forMainFrameOnly:YES
forMainFrameOnly:NO
] :
nil;

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

if(_sharedCookiesEnabled) {
Expand Down Expand Up @@ -1895,7 +1895,7 @@ - (void)resetupScripts:(WKWebViewConfiguration *)wkWebViewConfig {

WKUserScript* cookieInScript = [[WKUserScript alloc] initWithSource:script
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
forMainFrameOnly:YES];
forMainFrameOnly:NO];
[wkWebViewConfig.userContentController addUserScript:cookieInScript];
}
}
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "react-native-webview",
"description": "React Native WebView component for iOS, Android, macOS, and Windows",
"name": "@phantom/react-native-webview",
"description": "Phantom's fork of react-native-webview, based off of react-native-webview@13.13.5",
"main": "index.js",
"main-internal": "src/index.ts",
"react-native": "src/index.ts",
"typings": "index.d.ts",
"author": "Jamon Holmgren <jamon@infinite.red>",
"contributors": [
"Thibault Malbranche <malbranche.thibault@gmail.com>"
"Thibault Malbranche <malbranche.thibault@gmail.com>",
"Jakub Adamczyk <jakub.adamczyk@phantom.com>",
"Napas Udomsak <napas@phantom.com>"
],
"license": "MIT",
"version": "13.13.5",
"homepage": "https://github.com/react-native-webview/react-native-webview#readme",
"version": "0.0.1",
"homepage": "https://github.com/phantom/react-native-webview#readme",
"scripts": {
"release": "yarn changeset publish",
"android": "react-native run-android",
"ios": "react-native run-ios",
"macos": "react-native run-macos --scheme WebviewExample --project-path example/macos",
Expand Down Expand Up @@ -45,6 +48,7 @@
"@babel/core": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@callstack/react-native-visionos": "0.73.8",
"@changesets/cli": "^2.29.2",
"@react-native/babel-preset": "0.73.21",
"@react-native/eslint-config": "0.73.2",
"@react-native/metro-config": "0.73.5",
Expand Down
4 changes: 2 additions & 2 deletions react-native-webview.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ios_platform = new_arch_enabled ? '11.0' : '9.0'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
s.name = package['name']
s.name = 'react-native-webview'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
Expand All @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.homepage = package['homepage']
s.platforms = { :ios => ios_platform, :osx => "10.13", :visionos => "1.0" }

s.source = { :git => "https://github.com/react-native-webview/react-native-webview.git", :tag => "v#{s.version}" }
s.source = { :git => "https://github.com/phantom/react-native-webview.git", :tag => "v#{s.version}" }

s.source_files = "apple/**/*.{h,m,mm,swift}"

Expand Down
Loading
Loading