UI updates to the floating action button (#201)
* Update FAB to use a plus icon and not drop shadow * Update FAB positioning to be more consistent in different shell modes * Animate the FAB's repositioning
This commit is contained in:
+19
-22
@@ -1,15 +1,16 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {
|
import {
|
||||||
|
Animated,
|
||||||
GestureResponderEvent,
|
GestureResponderEvent,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
TouchableWithoutFeedback,
|
TouchableWithoutFeedback,
|
||||||
View,
|
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import LinearGradient from 'react-native-linear-gradient'
|
import LinearGradient from 'react-native-linear-gradient'
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {IconProp} from '@fortawesome/fontawesome-svg-core'
|
import {IconProp} from '@fortawesome/fontawesome-svg-core'
|
||||||
import {colors, gradients} from '../../lib/styles'
|
import {colors, gradients} from '../../lib/styles'
|
||||||
|
import {useAnimatedValue} from '../../lib/hooks/useAnimatedValue'
|
||||||
import {useStores} from '../../../state'
|
import {useStores} from '../../../state'
|
||||||
|
|
||||||
type OnPress = ((event: GestureResponderEvent) => void) | undefined
|
type OnPress = ((event: GestureResponderEvent) => void) | undefined
|
||||||
@@ -19,31 +20,34 @@ export const FAB = observer(
|
|||||||
icon,
|
icon,
|
||||||
onPress,
|
onPress,
|
||||||
}: {
|
}: {
|
||||||
testID: string
|
testID?: string
|
||||||
icon: IconProp
|
icon: IconProp
|
||||||
onPress: OnPress
|
onPress: OnPress
|
||||||
}) => {
|
}) => {
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
|
const interp = useAnimatedValue(0)
|
||||||
|
React.useEffect(() => {
|
||||||
|
Animated.timing(interp, {
|
||||||
|
toValue: store.shell.minimalShellMode ? 1 : 0,
|
||||||
|
duration: 100,
|
||||||
|
useNativeDriver: true,
|
||||||
|
isInteraction: false,
|
||||||
|
}).start()
|
||||||
|
}, [interp, store.shell.minimalShellMode])
|
||||||
|
const transform = {
|
||||||
|
transform: [{translateY: Animated.multiply(interp, 60)}],
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<TouchableWithoutFeedback testID={testID} onPress={onPress}>
|
<TouchableWithoutFeedback testID={testID} onPress={onPress}>
|
||||||
<View
|
<Animated.View style={[styles.outer, transform]}>
|
||||||
style={[
|
|
||||||
styles.outer,
|
|
||||||
store.shell.minimalShellMode ? styles.lower : undefined,
|
|
||||||
]}>
|
|
||||||
<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}>
|
style={styles.inner}>
|
||||||
<FontAwesomeIcon
|
<FontAwesomeIcon size={24} icon={icon} color={colors.white} />
|
||||||
size={24}
|
|
||||||
icon={icon}
|
|
||||||
color={colors.white}
|
|
||||||
style={styles.icon}
|
|
||||||
/>
|
|
||||||
</LinearGradient>
|
</LinearGradient>
|
||||||
</View>
|
</Animated.View>
|
||||||
</TouchableWithoutFeedback>
|
</TouchableWithoutFeedback>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -54,16 +58,10 @@ const styles = StyleSheet.create({
|
|||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
zIndex: 1,
|
zIndex: 1,
|
||||||
right: 22,
|
right: 22,
|
||||||
bottom: 84,
|
bottom: 94,
|
||||||
width: 60,
|
width: 60,
|
||||||
height: 60,
|
height: 60,
|
||||||
borderRadius: 30,
|
borderRadius: 30,
|
||||||
shadowColor: '#000',
|
|
||||||
shadowOpacity: 0.3,
|
|
||||||
shadowOffset: {width: 0, height: 1},
|
|
||||||
},
|
|
||||||
lower: {
|
|
||||||
bottom: 34,
|
|
||||||
},
|
},
|
||||||
inner: {
|
inner: {
|
||||||
width: 60,
|
width: 60,
|
||||||
@@ -72,5 +70,4 @@ const styles = StyleSheet.create({
|
|||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
icon: {},
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ export const Home = observer(function Home({navIdx, visible}: ScreenParams) {
|
|||||||
) : undefined}
|
) : undefined}
|
||||||
<FAB
|
<FAB
|
||||||
testID="composeFAB"
|
testID="composeFAB"
|
||||||
icon="pen-nib"
|
icon="plus"
|
||||||
onPress={() => onPressCompose(false)}
|
onPress={() => onPressCompose(false)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ export const Profile = observer(({navIdx, visible, params}: ScreenParams) => {
|
|||||||
) : (
|
) : (
|
||||||
renderHeader()
|
renderHeader()
|
||||||
)}
|
)}
|
||||||
<FAB icon="pen-nib" onPress={onPressCompose} />
|
<FAB icon="plus" onPress={onPressCompose} />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user