1- import React , { useEffect , useLayoutEffect , useMemo } from 'react'
1+ import React , { useEffect , useLayoutEffect , useMemo , useRef } from 'react'
22import { View } from 'react-native'
3- import { WebView } from 'react-native-webview'
3+ import { WebView , WebViewProps } from 'react-native-webview'
44
55import { useTheme , SylCommon } from '@src/theme'
66import { WebViewerScreenProps as ScreenProps } from '@src/navigation/routes'
@@ -11,6 +11,7 @@ import { translate } from '@src/i18n'
1111
1212const WebLink = ( { route, navigation } : ScreenProps ) => {
1313 const { theme } = useTheme ( )
14+ const webViewRef = useRef ( new WebView < { current ?: any } > ( { } ) )
1415 const [ loading , setLoading ] = React . useState ( true )
1516 const url = useMemo (
1617 ( ) => ( ! route . params . url . startsWith ( 'http' ) ? `http://${ route . params . url } ` : route . params . url ) ,
@@ -26,12 +27,22 @@ const WebLink = ({ route, navigation }: ScreenProps) => {
2627 useLayoutEffect ( ( ) => {
2728 navigation . setOptions ( {
2829 headerRight : ( ) => (
29- < HeaderButton
30- source = { theme . assets . images . icons . header . link }
31- onPress = { ( ) => {
32- linking ( url )
33- } }
34- />
30+ < >
31+ < HeaderButton
32+ containerStyle = { [ { marginRight : theme . spacing . tiny } ] }
33+ source = { theme . assets . images . icons . header . refresh }
34+ onPress = { ( ) => {
35+ setLoading ( true )
36+ webViewRef . current . reload ( )
37+ } }
38+ />
39+ < HeaderButton
40+ source = { theme . assets . images . icons . header . link }
41+ onPress = { ( ) => {
42+ linking ( url )
43+ } }
44+ />
45+ </ >
3546 )
3647 } )
3748 } , [ navigation ] )
@@ -40,6 +51,7 @@ const WebLink = ({ route, navigation }: ScreenProps) => {
4051 < View style = { [ SylCommon . Layout . fill , SylCommon . View . background ( theme ) ] } >
4152 { loading && < Spinner text = { translate ( 'placeholder.loading' ) } /> }
4253 < WebView
54+ ref = { webViewRef }
4355 originWhitelist = { [ '*' ] }
4456 source = { { uri : url } }
4557 onLoad = { ( syntheticEvent ) => {
0 commit comments