Skip to content

Commit 19de51a

Browse files
committed
feat: Add a refresh function to the Weblink Screen
1 parent 7af6257 commit 19de51a

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/screens/common/WebLink.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { useEffect, useLayoutEffect, useMemo } from 'react'
1+
import React, { useEffect, useLayoutEffect, useMemo, useRef } from 'react'
22
import { View } from 'react-native'
3-
import { WebView } from 'react-native-webview'
3+
import { WebView, WebViewProps } from 'react-native-webview'
44

55
import { useTheme, SylCommon } from '@src/theme'
66
import { WebViewerScreenProps as ScreenProps } from '@src/navigation/routes'
@@ -11,6 +11,7 @@ import { translate } from '@src/i18n'
1111

1212
const 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) => {

src/screens/components/common/General.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
TextStyle,
1414
TouchableOpacity,
1515
ViewStyle,
16-
Pressable
16+
Pressable,
17+
StyleProp
1718
} from 'react-native'
1819
import { IState } from '@src/types'
1920
import { translate } from '@src/i18n'
@@ -82,11 +83,13 @@ const BorderLine = () => {
8283
}
8384

8485
const HeaderButton = ({
86+
containerStyle: style,
8587
source,
8688
onPress,
8789
text,
8890
textColor
8991
}: {
92+
containerStyle?: StyleProp<ViewStyle>
9093
source?: ImageSourcePropType
9194
text?: string
9295
textColor?: string
@@ -95,7 +98,7 @@ const HeaderButton = ({
9598
const { theme } = useTheme()
9699

97100
return (
98-
<Pressable onPress={onPress}>
101+
<Pressable onPress={onPress} style={style}>
99102
{source && <Image source={source} width={24} />}
100103
{text && <Text style={styles.headerText(theme, textColor)}>{text}</Text>}
101104
</Pressable>

0 commit comments

Comments
 (0)