tooot/src/screens/Shared/Webview.tsx

106 lines
3.1 KiB
TypeScript
Raw Normal View History

2020-11-30 00:24:53 +01:00
import { useNavigation } from '@react-navigation/native'
import React, { useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
2020-12-01 00:44:28 +01:00
import { ActionSheetIOS } from 'react-native'
2020-11-30 00:24:53 +01:00
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
2020-10-26 00:27:53 +01:00
import { WebView } from 'react-native-webview'
2020-12-13 14:04:25 +01:00
import BottomSheet from '@components/BottomSheet'
2020-10-26 00:27:53 +01:00
2020-12-13 14:04:25 +01:00
import { HeaderLeft, HeaderRight } from '@components/Header'
import { MenuContainer, MenuRow } from '@components/Menu'
2020-11-30 00:24:53 +01:00
const Stack = createNativeStackNavigator()
2020-10-26 00:27:53 +01:00
2020-10-31 21:04:46 +01:00
export interface Props {
route: {
params: {
uri: string
}
}
}
2020-11-21 13:19:05 +01:00
const ScreenSharedWebview: React.FC<Props> = ({
2020-10-26 00:27:53 +01:00
route: {
params: { uri }
}
2020-10-31 21:04:46 +01:00
}) => {
2020-11-30 00:24:53 +01:00
const navigation = useNavigation()
const { t } = useTranslation('sharedWebview')
const [title, setTitle] = useState<string>(t('heading.loading'))
2020-12-01 00:44:28 +01:00
const [bottomSheet, showBottomSheet] = useState(false)
2020-11-30 00:24:53 +01:00
const webview = useRef<WebView>(null)
return (
<Stack.Navigator>
<Stack.Screen
name='Screen-Shared-Webview-Root'
options={{
title,
headerLeft: () => (
<HeaderLeft
icon='chevron-down'
onPress={() => navigation.goBack()}
/>
),
headerRight: () => (
<HeaderRight
2020-12-01 00:44:28 +01:00
icon='more-horizontal'
onPress={() => showBottomSheet(true)}
2020-11-30 00:24:53 +01:00
/>
)
}}
>
{() => (
2020-12-01 00:44:28 +01:00
<>
<WebView
ref={webview}
source={{ uri }}
decelerationRate='normal'
onLoad={({ nativeEvent }) => setTitle(nativeEvent.title)}
onError={() => setTitle(t('heading.error'))}
/>
<BottomSheet
visible={bottomSheet}
handleDismiss={() => showBottomSheet(false)}
>
2020-12-03 01:28:56 +01:00
<MenuContainer>
<MenuRow
onPress={() => {
ActionSheetIOS.showShareActionSheetWithOptions(
{
url: uri,
excludedActivityTypes: [
'com.apple.UIKit.activity.Mail',
'com.apple.UIKit.activity.Print',
'com.apple.UIKit.activity.SaveToCameraRoll',
'com.apple.UIKit.activity.OpenInIBooks'
]
},
() => {},
() => {
showBottomSheet(false)
}
)
}}
iconFront='share'
title={'分享链接'}
/>
<MenuRow
onPress={() => {
showBottomSheet(false)
webview.current?.reload()
}}
iconFront='refresh-cw'
title='刷新'
/>
</MenuContainer>
2020-12-01 00:44:28 +01:00
</BottomSheet>
</>
2020-11-30 00:24:53 +01:00
)}
</Stack.Screen>
</Stack.Navigator>
)
2020-10-26 00:27:53 +01:00
}
2020-11-21 13:19:05 +01:00
export default ScreenSharedWebview