diff --git a/.vscode/settings.json b/.vscode/settings.json index 725c5c2aa2..9c0ee4edeb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -74,5 +74,7 @@ "i18n-ally.displayLanguage": "en", "i18n-ally.localesPaths": ["locales"], "i18n-ally.namespace": true, - "i18n-ally.pathMatcher": "{namespaces}/{locale}.json" + "i18n-ally.pathMatcher": "{namespaces}/{locale}.json", + "lldb.library": "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB", + "lldb.launch.expressions": "native" } diff --git a/apps/mobile/packages/follow-native/example/App.tsx b/apps/mobile/packages/follow-native/example/App.tsx index 67b0540b85..9cadf4c241 100644 --- a/apps/mobile/packages/follow-native/example/App.tsx +++ b/apps/mobile/packages/follow-native/example/App.tsx @@ -1,11 +1,10 @@ -import { SharedWebView, SharedWebViewModule } from "follow-native" +import { SharedWebView } from "follow-native" import { ScrollView, View } from "react-native" -SharedWebViewModule.preload("https://follow.is") export default function App() { return ( - + diff --git a/apps/mobile/packages/follow-native/ios/SharedWebView/SharedWebView.swift b/apps/mobile/packages/follow-native/ios/SharedWebView/SharedWebView.swift index 1dc9ec0725..157f2164c8 100644 --- a/apps/mobile/packages/follow-native/ios/SharedWebView/SharedWebView.swift +++ b/apps/mobile/packages/follow-native/ios/SharedWebView/SharedWebView.swift @@ -3,34 +3,6 @@ import ExpoModulesCore import SwiftUI import WebKit -class WebViewProps: ExpoSwiftUI.ViewProps { - @Field var url: String -} - -struct WebViewComponentView: ExpoSwiftUI.View { - @EnvironmentObject var props: WebViewProps - @StateObject private var webViewState = WebViewManager.state - - let webView: WKWebView = SharedWebViewModule.sharedWebView! - - var body: some View { - WebViewComponent(webView: webView) - .frame( - height: webViewState.contentHeight - ) - - .onChange(of: props.url, initial: false) { _, newValue in - if let nextUrl = URL(string: newValue) { - let request = URLRequest(url: nextUrl) - webView.load(request) - } - } - #if DEBUG - .border(.tint) - #endif - } -} - class WebViewView: ExpoView { private var cancellable: AnyCancellable? @@ -39,6 +11,12 @@ class WebViewView: ExpoView { required init(appContext: AppContext? = nil) { super.init(appContext: appContext) addSubview(rctView) + + #if DEBUG + rctView.borderStyle = .solid + rctView.borderWidth = 1 + rctView.borderColor = .tintColor + #endif rctView.addSubview(SharedWebViewModule.sharedWebView!) clipsToBounds = true @@ -71,13 +49,7 @@ class WebViewView: ExpoView { rctView.frame = rect onContentHeightChange(["height": Float(rect.height)]) -// if let superview = self.superview { -// superview.frame = rect -// -// if let superSuperview = superview.superview { -// superSuperview.frame = rect -// } -// } + } } diff --git a/apps/mobile/packages/follow-native/ios/SharedWebView/SharedWebViewModule.swift b/apps/mobile/packages/follow-native/ios/SharedWebView/SharedWebViewModule.swift index 0023cd0af2..ebacdcc806 100644 --- a/apps/mobile/packages/follow-native/ios/SharedWebView/SharedWebViewModule.swift +++ b/apps/mobile/packages/follow-native/ios/SharedWebView/SharedWebViewModule.swift @@ -24,9 +24,18 @@ public class SharedWebViewModule: Module { } View(WebViewView.self) { - Events( - "onContentHeightChange" - ) + Events("onContentHeightChange") + + Prop("url") { (_: UIView, urlString: String) in + if let webView = SharedWebViewModule.sharedWebView { + if let url = URL(string: urlString) { + if url == webView.url { + return + } + webView.load(URLRequest(url: url)) + } + } + } } } } diff --git a/apps/mobile/packages/follow-native/ios/SharedWebView/WebViewManager.swift b/apps/mobile/packages/follow-native/ios/SharedWebView/WebViewManager.swift index 8e2b2bcb54..01e65e6fec 100644 --- a/apps/mobile/packages/follow-native/ios/SharedWebView/WebViewManager.swift +++ b/apps/mobile/packages/follow-native/ios/SharedWebView/WebViewManager.swift @@ -42,7 +42,10 @@ enum WebViewManager { #if DEBUG + if #available(iOS 16.4, *) { + webView.isInspectable = true + } #endif diff --git a/apps/mobile/packages/follow-native/src/SharedWebView.tsx b/apps/mobile/packages/follow-native/src/SharedWebView.tsx index 78a737756f..1f6129d8e5 100644 --- a/apps/mobile/packages/follow-native/src/SharedWebView.tsx +++ b/apps/mobile/packages/follow-native/src/SharedWebView.tsx @@ -5,9 +5,10 @@ import { View } from "react-native" const NativeView: React.ComponentType<{ onContentHeightChange?: (e: { nativeEvent: { height: number } }) => void + url: string }> = requireNativeView("FOSharedWebView") -export default function SharedWebView() { +export default function SharedWebView({ url }: { url: string }) { const [contentHeight, setContentHeight] = useState(0) return ( @@ -16,6 +17,7 @@ export default function SharedWebView() { onContentHeightChange={(e) => { setContentHeight(e.nativeEvent.height) }} + url={url} /> )