Skip to content

Commit

Permalink
Merge branch 'main' into content-inset
Browse files Browse the repository at this point in the history
  • Loading branch information
pklatka committed Apr 24, 2024
2 parents c9c55a7 + fe34a1a commit 66b3df4
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class RNVisitableView(context: Context) : LinearLayout(context), SessionSubscrib

lateinit var sessionHandle: String
var applicationNameForUserAgent: String? = null
set(value) {
field = value
updateWebViewConfiguration()
}
var scrollEnabled: Boolean = true
set(value) {
field = value
Expand All @@ -70,7 +66,7 @@ class RNVisitableView(context: Context) : LinearLayout(context), SessionSubscrib
return null
}

_session = RNSessionManager.findOrCreateSession(reactContext, sessionHandle)
_session = RNSessionManager.findOrCreateSession(reactContext, sessionHandle, applicationNameForUserAgent)
return _session
}

Expand Down Expand Up @@ -108,16 +104,8 @@ class RNVisitableView(context: Context) : LinearLayout(context), SessionSubscrib

private fun updateWebViewConfiguration() {
if (webView == null) return
setUserAgentString(webView!!, applicationNameForUserAgent)
setOnTouchListener(webView!!, scrollEnabled)
}

private fun setUserAgentString(webView: TurboWebView, applicationNameForUserAgent: String?) {
var userAgentString = WebSettings.getDefaultUserAgent(webView.context)
if (applicationNameForUserAgent != null) {
userAgentString = "$userAgentString $applicationNameForUserAgent"
}
webView.settings.userAgentString = userAgentString
setOnTouchListener(webView!!, scrollEnabled)
}

private fun setOnTouchListener(webView: TurboWebView, scrollEnabled: Boolean) {
Expand Down Expand Up @@ -217,7 +205,6 @@ class RNVisitableView(context: Context) : LinearLayout(context), SessionSubscrib
requestLayout()

turboView.attachWebView(webView!!) { attachedToNewDestination ->
updateWebViewConfiguration()
onReady(attachedToNewDestination)
}
}
Expand Down Expand Up @@ -351,6 +338,7 @@ class RNVisitableView(context: Context) : LinearLayout(context), SessionSubscrib
putString("title", webView!!.title)
putString("url", webView!!.url)
})
updateWebViewConfiguration()
removeTransitionalViews()
}

Expand Down
7 changes: 7 additions & 0 deletions packages/turbo/ios/RNVisitableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ extension RNVisitableView: RNVisitableViewControllerDelegate {
configureWebView()
session?.visitableViewDidAppear(view: self)
}

func visitableWillDisappear(visitable: Visitable) {
// Ensure that all completion handlers have been called.
// Otherwise, an NSInternalInconsistencyException might occur.
sendAlertResult()
sendConfirmResult(result: "")
}

func visitableDidDisappear(visitable: Visitable) {
// No-op
Expand Down
7 changes: 7 additions & 0 deletions packages/turbo/ios/RNVisitableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public protocol RNVisitableViewControllerDelegate {
func visitableDidAppear(visitable: Visitable)

func visitableDidRender(visitable: Visitable)

func visitableWillDisappear(visitable: Visitable)

func visitableDidDisappear(visitable: Visitable)

Expand Down Expand Up @@ -56,6 +58,11 @@ class RNVisitableViewController: UIViewController, Visitable {
delegate?.visitableDidAppear(visitable: self)
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
delegate?.visitableWillDisappear(visitable: self)
}

override func viewDidDisappear(_ animated: Bool) {
delegate?.visitableDidDisappear(visitable: self)
}
Expand Down
13 changes: 13 additions & 0 deletions packages/turbo/patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Patches for `turbo-ios` and `turbo-android` libraries

This directory contains patches for the `turbo-ios` and `turbo-android` libraries. The patches are applied during the build process. Unfortunately, this process is necessary to make the libraries work correctly with `react-native-turbo`.

## Changes

### `turbo-ios`

The patch removes the `NSLayoutConstraint` set in `VisitableView.installRefreshControl` method. This is necessary to make `contentInset` work properly with `UIRefreshControl`.

### `turbo-android`

The patch makes the necessary interfaces, classes and methods public so that they can be accessed from the `react-native-turbo` native land.
File renamed without changes.
21 changes: 21 additions & 0 deletions packages/turbo/patches/turbo-ios.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/Source/Visitable/VisitableView.swift b/Source/Visitable/VisitableView.swift
index 12452b5..e9c37b8 100644
--- a/Source/Visitable/VisitableView.swift
+++ b/Source/Visitable/VisitableView.swift
@@ -69,16 +69,6 @@ open class VisitableView: UIView {

#if !targetEnvironment(macCatalyst)
scrollView.addSubview(refreshControl)
-
- /// Infer refresh control's default height from its frame, if given.
- /// Otherwise fallback to 60 (the default height).
- let refreshControlHeight = refreshControl.frame.height > 0 ? refreshControl.frame.height : 60
-
- NSLayoutConstraint.activate([
- refreshControl.centerXAnchor.constraint(equalTo: centerXAnchor),
- refreshControl.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
- refreshControl.heightAnchor.constraint(equalToConstant: refreshControlHeight)
- ])
#endif
}

2 changes: 1 addition & 1 deletion packages/turbo/scripts/build-turbo-android.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TURBO_ANDROID_REPO_PATH="https://github.com/hotwired/turbo-android.git"
TURBO_ANDROID_MAIN_SOURCE_DIR="./turbo/src/main/*"
TURBO_ANDROID_VERSION=$1
PATCH_FILE=$(realpath ./patches/turbo-android-react-native-support.patch)
PATCH_FILE=$(realpath ./patches/turbo-android.patch)
TURBO_ANDROID_DIR=$(realpath ./android)
DEPENDENCIES_GRADLE_FILE="turbo-android-dependencies.gradle"
DEPENDENCY_REGEX="[a-zA-Z0-9.\-]+:[a-zA-Z0-9.\-]+:[0-9a-zA-Z.\-]+"
Expand Down
6 changes: 5 additions & 1 deletion packages/turbo/scripts/build-turbo-ios.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TURBO_IOS_REPO_PATH="https://github.com/hotwired/turbo-ios.git"
TURBO_IOS_VERSION=$1
PATCH_FILE=$(realpath ./patches/turbo-ios.patch)

# First argument is the version tag
if [ -z "$TURBO_IOS_VERSION" ]
Expand All @@ -17,8 +18,11 @@ mkdir vendor
cd vendor
git clone --branch $TURBO_IOS_VERSION --depth 1 $TURBO_IOS_REPO_PATH

# Keep the Source folder and remove the rest
# Apply patch
cd turbo-ios
git apply $PATCH_FILE

# Keep the Source folder and remove the rest
for file in *; do
if [ "$file" != "Source" ]; then
rm -rf $file
Expand Down

0 comments on commit 66b3df4

Please sign in to comment.