[APP-729] Replace the ImageHider blurring effect with a simpler and more reliable card (#959)

* Replace the ImageHider blurring effect with a simpler and more reliable card

* A few improvements to ImageHider layout

* Simplify the ImageHider a bit more

* Small web layout tweak
This commit is contained in:
Paul Frazee 2023-07-06 20:29:52 -05:00 committed by GitHub
parent b06304a253
commit bf1785765d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,29 +2,25 @@ import React from 'react'
import {Pressable, StyleProp, StyleSheet, View, ViewStyle} from 'react-native' import {Pressable, StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {Text} from '../text/Text' import {Text} from '../text/Text'
import {BlurView} from '../BlurView'
import {ModerationBehavior, ModerationBehaviorCode} from 'lib/labeling/types' import {ModerationBehavior, ModerationBehaviorCode} from 'lib/labeling/types'
import {isAndroid} from 'platform/detection' import {isDesktopWeb} from 'platform/detection'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {FontAwesomeIconStyle} from '@fortawesome/react-native-fontawesome'
export function ImageHider({ export function ImageHider({
testID, testID,
moderation, moderation,
style, style,
containerStyle,
children, children,
}: React.PropsWithChildren<{ }: React.PropsWithChildren<{
testID?: string testID?: string
moderation: ModerationBehavior moderation: ModerationBehavior
style?: StyleProp<ViewStyle> style?: StyleProp<ViewStyle>
containerStyle?: StyleProp<ViewStyle>
}>) { }>) {
const pal = usePalette('default') const pal = usePalette('default')
const [override, setOverride] = React.useState(false) const [override, setOverride] = React.useState(false)
const onPressShow = React.useCallback(() => { const onPressToggle = React.useCallback(() => {
setOverride(true) setOverride(v => !v)
}, [setOverride])
const onPressHide = React.useCallback(() => {
setOverride(false)
}, [setOverride]) }, [setOverride])
if (moderation.behavior === ModerationBehaviorCode.Hide) { if (moderation.behavior === ModerationBehaviorCode.Hide) {
@ -40,89 +36,45 @@ export function ImageHider({
} }
return ( return (
<View style={[styles.container, containerStyle]}>
<View testID={testID} style={style}> <View testID={testID} style={style}>
{children} <View style={[styles.cover, pal.viewLight]}>
</View>
{override ? (
<Pressable <Pressable
onPress={onPressHide} onPress={onPressToggle}
style={[styles.hideBtn, pal.view]} style={[styles.toggleBtn]}
accessibilityLabel="Hide image"
accessibilityHint="Rehides the image">
<Text type="xl-bold" style={pal.link}>
Hide
</Text>
</Pressable>
) : (
<>
{isAndroid ? (
/* android has an issue that breaks the blurview */
/* see https://github.com/Kureev/react-native-blur/issues/486 */
<View style={[pal.viewLight, styles.overlay, styles.coverView]} />
) : (
<BlurView
style={[styles.overlay, styles.blurView]}
blurType="light"
blurAmount={100}
reducedTransparencyFallbackColor="white"
/>
)}
<View style={[styles.overlay, styles.info]}>
<Pressable
onPress={onPressShow}
style={[styles.showBtn, pal.view]}
accessibilityLabel="Show image" accessibilityLabel="Show image"
accessibilityHint="Shows image hidden based on your moderation settings"> accessibilityHint="">
<Text type="xl" style={pal.text}> <FontAwesomeIcon
icon={override ? 'eye' : ['far', 'eye-slash']}
size={24}
style={pal.text as FontAwesomeIconStyle}
/>
<Text type="lg" style={pal.text}>
{moderation.reason || 'Content warning'} {moderation.reason || 'Content warning'}
</Text> </Text>
<View style={styles.flex1} />
<Text type="xl-bold" style={pal.link}> <Text type="xl-bold" style={pal.link}>
Show {override ? 'Hide' : 'Show'}
</Text> </Text>
</Pressable> </Pressable>
</View> </View>
</> {override && children}
)}
</View> </View>
) )
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { cover: {
position: 'relative',
marginBottom: 10,
},
overlay: {
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
},
blurView: {
borderRadius: 8, borderRadius: 8,
marginTop: 4,
}, },
coverView: { toggleBtn: {
borderRadius: 8,
},
info: {
justifyContent: 'center',
alignItems: 'center',
},
showBtn: {
flexDirection: 'row', flexDirection: 'row',
gap: 8, gap: 8,
paddingHorizontal: 18, alignItems: 'center',
paddingVertical: 14, paddingHorizontal: isDesktopWeb ? 24 : 20,
borderRadius: 24, paddingVertical: isDesktopWeb ? 20 : 18,
}, },
hideBtn: { flex1: {
position: 'absolute', flex: 1,
left: 8,
bottom: 20,
paddingHorizontal: 8,
paddingVertical: 6,
borderRadius: 8,
}, },
}) })