diff options
author | Ansh <anshnanda10@gmail.com> | 2023-09-20 01:18:50 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-20 01:18:50 +0530 |
commit | 859588c3f63949182acf3ca800b0229dd5e1d88e (patch) | |
tree | 909b6c8ae8c6ca47b6db080d9f891dac676fd685 /src/view/com/util/forms/Button.tsx | |
parent | da8499c8810eccbb448516adedcbb19a1964c081 (diff) | |
download | voidsky-859588c3f63949182acf3ca800b0229dd5e1d88e.tar.zst |
Onboarding recommended follows (#1457)
* upgrade api package * add RecommendedFollows as a step in onboarding * add list of recommended follows from suggested actor model * remove dead code * hoist suggestedActors into onboarding model * add comments * load more suggested follows on follow * styling changes * add animation * tweak animations * adjust styling slightly * adjust styles on mobile * styling improvements for web * fix text alignment in RecommendedFollows * dedupe inserted suggestions * fix animation duration * Minor spacing tweak --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com> and Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/view/com/util/forms/Button.tsx')
-rw-r--r-- | src/view/com/util/forms/Button.tsx | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/view/com/util/forms/Button.tsx b/src/view/com/util/forms/Button.tsx index 8049d2243..076fa1baa 100644 --- a/src/view/com/util/forms/Button.tsx +++ b/src/view/com/util/forms/Button.tsx @@ -7,6 +7,8 @@ import { Pressable, ViewStyle, PressableStateCallbackType, + ActivityIndicator, + View, } from 'react-native' import {Text} from '../text/Text' import {useTheme} from 'lib/ThemeContext' @@ -48,17 +50,19 @@ export function Button({ accessibilityHint, accessibilityLabelledBy, onAccessibilityEscape, + withLoading = false, }: React.PropsWithChildren<{ type?: ButtonType label?: string style?: StyleProp<ViewStyle> labelStyle?: StyleProp<TextStyle> - onPress?: () => void + onPress?: () => void | Promise<void> testID?: string accessibilityLabel?: string accessibilityHint?: string accessibilityLabelledBy?: string onAccessibilityEscape?: () => void + withLoading?: boolean }>) { const theme = useTheme() const typeOuterStyle = choose<ViewStyle, Record<ButtonType, ViewStyle>>( @@ -138,13 +142,16 @@ export function Button({ }, ) + const [isLoading, setIsLoading] = React.useState(false) const onPressWrapped = React.useCallback( - (event: Event) => { + async (event: Event) => { event.stopPropagation() event.preventDefault() - onPress?.() + withLoading && setIsLoading(true) + await onPress?.() + withLoading && setIsLoading(false) }, - [onPress], + [onPress, withLoading], ) const getStyle = React.useCallback( @@ -160,23 +167,35 @@ export function Button({ [typeOuterStyle, style], ) + const renderChildern = React.useCallback(() => { + if (!label) { + return children + } + + return ( + <View style={styles.labelContainer}> + {label && withLoading && isLoading ? ( + <ActivityIndicator size={12} color={typeLabelStyle.color} /> + ) : null} + <Text type="button" style={[typeLabelStyle, labelStyle]}> + {label} + </Text> + </View> + ) + }, [children, label, withLoading, isLoading, typeLabelStyle, labelStyle]) + return ( <Pressable style={getStyle} onPress={onPressWrapped} + disabled={isLoading} testID={testID} accessibilityRole="button" accessibilityLabel={accessibilityLabel} accessibilityHint={accessibilityHint} accessibilityLabelledBy={accessibilityLabelledBy} onAccessibilityEscape={onAccessibilityEscape}> - {label ? ( - <Text type="button" style={[typeLabelStyle, labelStyle]}> - {label} - </Text> - ) : ( - children - )} + {renderChildern} </Pressable> ) } @@ -187,4 +206,8 @@ const styles = StyleSheet.create({ paddingVertical: 8, borderRadius: 24, }, + labelContainer: { + flexDirection: 'row', + gap: 8, + }, }) |