1- import React , { useRef , MutableRefObject , ReactElement } from "react"
1+ import React , { ReactElement } from "react"
22import { StyleProp , ViewStyle , View } from "react-native"
33import { WebView } from "react-native-webview"
44import { Payload } from "@mxenabled/widget-post-message-definitions"
@@ -13,28 +13,18 @@ export type StylingProps = {
1313 webViewStyle ?: StyleProp < ViewStyle >
1414}
1515
16- type MaybeWebViewRef = MutableRefObject < WebView | null >
1716type BaseProps < Configuration > = Props < Configuration > & StylingProps
1817
1918export function useWidgetRenderer < Configuration > (
2019 props : BaseProps < Configuration > ,
2120 dispatchEvent : ( url : string , callbacks : BaseProps < Configuration > ) => Payload | undefined ,
2221) : ReactElement {
23- const [ _ref , elem ] = useWidgetRendererWithRef ( props , dispatchEvent )
24- return elem
25- }
26-
27- export function useWidgetRendererWithRef < Configuration > (
28- props : BaseProps < Configuration > ,
29- dispatchEvent : ( url : string , callbacks : BaseProps < Configuration > ) => Payload | undefined ,
30- ) : [ MaybeWebViewRef , ReactElement ] {
31- const ref = useRef < WebView > ( null )
3222 const url = useSsoUrl ( props )
3323 const fullscreenStyles = useFullscreenStyles ( )
3424 const style = props . style || fullscreenStyles
3525
3626 if ( ! url ) {
37- return [ ref , < View style = { style } /> ]
27+ return < View style = { style } />
3828 }
3929
4030 const handler = makeRequestInterceptor ( url , {
@@ -47,13 +37,11 @@ export function useWidgetRendererWithRef<Configuration>(
4737 window.MXReactNativeSDKVersion = "${ sdkVersion } ";
4838 `
4939
50- return [
51- ref ,
40+ return (
5241 < View testID = "widget_view" style = { style } >
5342 < WebView
5443 testID = "widget_webview"
5544 style = { props . webViewStyle }
56- ref = { ref }
5745 scrollEnabled = { true }
5846 source = { { uri : url } }
5947 originWhitelist = { [ "*" ] }
@@ -68,6 +56,6 @@ export function useWidgetRendererWithRef<Configuration>(
6856 onShouldStartLoadWithRequest = { handler }
6957 onError = { props . onWebViewError }
7058 />
71- </ View > ,
72- ]
59+ </ View >
60+ )
7361}
0 commit comments