refactor FAB
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React, {ComponentProps} from 'react'
|
import React, {ComponentProps} from 'react'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {StyleSheet, TouchableWithoutFeedback} from 'react-native'
|
import {TouchableWithoutFeedback} from 'react-native'
|
||||||
import LinearGradient from 'react-native-linear-gradient'
|
import LinearGradient from 'react-native-linear-gradient'
|
||||||
import {gradients} from 'lib/styles'
|
import {gradients} from 'lib/styles'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
@@ -8,6 +8,7 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
|||||||
import {clamp} from 'lib/numbers'
|
import {clamp} from 'lib/numbers'
|
||||||
import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode'
|
import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode'
|
||||||
import Animated from 'react-native-reanimated'
|
import Animated from 'react-native-reanimated'
|
||||||
|
import {useStyles} from 'view/nova'
|
||||||
|
|
||||||
export interface FABProps
|
export interface FABProps
|
||||||
extends ComponentProps<typeof TouchableWithoutFeedback> {
|
extends ComponentProps<typeof TouchableWithoutFeedback> {
|
||||||
@@ -21,59 +22,51 @@ export const FABInner = observer(function FABInnerImpl({
|
|||||||
...props
|
...props
|
||||||
}: FABProps) {
|
}: FABProps) {
|
||||||
const insets = useSafeAreaInsets()
|
const insets = useSafeAreaInsets()
|
||||||
const {isMobile, isTablet} = useWebMediaQueries()
|
const {isMobile} = useWebMediaQueries()
|
||||||
const {fabMinimalShellTransform} = useMinimalShellMode()
|
const {fabMinimalShellTransform} = useMinimalShellMode()
|
||||||
|
const styles = useStyles({
|
||||||
const size = React.useMemo(() => {
|
outer: {
|
||||||
return isTablet ? styles.sizeLarge : styles.sizeRegular
|
position: 'absolute',
|
||||||
}, [isTablet])
|
z: 1,
|
||||||
const tabletSpacing = React.useMemo(() => {
|
right: 24,
|
||||||
return isTablet
|
bottom: clamp(insets.bottom, 15, 60) + 15,
|
||||||
? {right: 50, bottom: 50}
|
gtMobile: {
|
||||||
: {
|
right: 50,
|
||||||
right: 24,
|
bottom: 50,
|
||||||
bottom: clamp(insets.bottom, 15, 60) + 15,
|
},
|
||||||
}
|
},
|
||||||
}, [insets.bottom, isTablet])
|
sizing: {
|
||||||
|
w: 60,
|
||||||
|
h: 60,
|
||||||
|
radius: 30,
|
||||||
|
gtMobile: {
|
||||||
|
w: 70,
|
||||||
|
h: 70,
|
||||||
|
radius: 35,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
inner: {
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableWithoutFeedback testID={testID} {...props}>
|
<TouchableWithoutFeedback testID={testID} {...props}>
|
||||||
<Animated.View
|
<Animated.View
|
||||||
style={[
|
style={[
|
||||||
styles.outer,
|
styles.outer,
|
||||||
size,
|
styles.sizing,
|
||||||
tabletSpacing,
|
|
||||||
isMobile && fabMinimalShellTransform,
|
isMobile && fabMinimalShellTransform,
|
||||||
]}>
|
]}>
|
||||||
<LinearGradient
|
<LinearGradient
|
||||||
colors={[gradients.blueLight.start, gradients.blueLight.end]}
|
colors={[gradients.blueLight.start, gradients.blueLight.end]}
|
||||||
start={{x: 0, y: 0}}
|
start={{x: 0, y: 0}}
|
||||||
end={{x: 1, y: 1}}
|
end={{x: 1, y: 1}}
|
||||||
style={[styles.inner, size]}>
|
style={[styles.inner, styles.sizing]}>
|
||||||
{icon}
|
{icon}
|
||||||
</LinearGradient>
|
</LinearGradient>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
</TouchableWithoutFeedback>
|
</TouchableWithoutFeedback>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
sizeRegular: {
|
|
||||||
width: 60,
|
|
||||||
height: 60,
|
|
||||||
borderRadius: 30,
|
|
||||||
},
|
|
||||||
sizeLarge: {
|
|
||||||
width: 70,
|
|
||||||
height: 70,
|
|
||||||
borderRadius: 35,
|
|
||||||
},
|
|
||||||
outer: {
|
|
||||||
position: 'absolute',
|
|
||||||
zIndex: 1,
|
|
||||||
},
|
|
||||||
inner: {
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user