[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:
parent
b06304a253
commit
bf1785765d
1 changed files with 31 additions and 79 deletions
|
@ -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}>
|
<View style={[styles.cover, pal.viewLight]}>
|
||||||
{children}
|
|
||||||
</View>
|
|
||||||
{override ? (
|
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={onPressHide}
|
onPress={onPressToggle}
|
||||||
style={[styles.hideBtn, pal.view]}
|
style={[styles.toggleBtn]}
|
||||||
accessibilityLabel="Hide image"
|
accessibilityLabel="Show image"
|
||||||
accessibilityHint="Rehides the image">
|
accessibilityHint="">
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={override ? 'eye' : ['far', 'eye-slash']}
|
||||||
|
size={24}
|
||||||
|
style={pal.text as FontAwesomeIconStyle}
|
||||||
|
/>
|
||||||
|
<Text type="lg" style={pal.text}>
|
||||||
|
{moderation.reason || 'Content warning'}
|
||||||
|
</Text>
|
||||||
|
<View style={styles.flex1} />
|
||||||
<Text type="xl-bold" style={pal.link}>
|
<Text type="xl-bold" style={pal.link}>
|
||||||
Hide
|
{override ? 'Hide' : 'Show'}
|
||||||
</Text>
|
</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
) : (
|
</View>
|
||||||
<>
|
{override && children}
|
||||||
{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"
|
|
||||||
accessibilityHint="Shows image hidden based on your moderation settings">
|
|
||||||
<Text type="xl" style={pal.text}>
|
|
||||||
{moderation.reason || 'Content warning'}
|
|
||||||
</Text>
|
|
||||||
<Text type="xl-bold" style={pal.link}>
|
|
||||||
Show
|
|
||||||
</Text>
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</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,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue