From a1725359c6ca61e30ac817a028ce3defd0e6f7d4 Mon Sep 17 00:00:00 2001 From: Heri Setiawan Date: Fri, 15 Sep 2023 18:35:47 +0700 Subject: [PATCH] Refactor constants --- src/CONST.ts | 6 ++++++ src/components/SpacerView.js | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 1ef2f3e83246..105611b7d210 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2667,6 +2667,12 @@ const CONST = { HTTPS: 'https', PUSHER: 'pusher', }, + HORIZONTAL_SPACER: { + DEFAULT_BORDER_BOTTOM_WIDTH: 1, + DEFAULT_MARGIN_VERTICAL: 8, + HIDDEN_MARGIN_VERTICAL: 0, + HIDDEN_BORDER_BOTTOM_WIDTH: 0, + }, } as const; export default CONST; diff --git a/src/components/SpacerView.js b/src/components/SpacerView.js index c4180781fa12..6cfbd1025f94 100644 --- a/src/components/SpacerView.js +++ b/src/components/SpacerView.js @@ -2,6 +2,7 @@ import React from 'react'; import Animated, {useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated'; import PropTypes from 'prop-types'; import * as StyleUtils from '../styles/StyleUtils'; +import CONST from '../CONST'; const propTypes = { /** @@ -21,19 +22,19 @@ const defaultProps = { style: [], }; -function SpacerView({shouldShow, style}) { - const marginVertical = useSharedValue(8); - const borderBottomWidth = useSharedValue(1); +function SpacerView({shouldShow = true, style = []}) { + const marginVertical = useSharedValue(CONST.HORIZONTAL_SPACER.DEFAULT_MARGIN_VERTICAL); + const borderBottomWidth = useSharedValue(CONST.HORIZONTAL_SPACER.DEFAULT_BORDER_BOTTOM_WIDTH); const animatedStyles = useAnimatedStyle(() => ({ marginVertical: marginVertical.value, borderBottomWidth: borderBottomWidth.value, })); React.useEffect(() => { - const duration = 300; + const duration = CONST.ANIMATED_TRANSITION; const values = { - marginVertical: shouldShow ? 8 : 0, - borderBottomWidth: shouldShow ? 1 : 0, + marginVertical: shouldShow ? CONST.HORIZONTAL_SPACER.DEFAULT_MARGIN_VERTICAL : CONST.HORIZONTAL_SPACER.HIDDEN_MARGIN_VERTICAL, + borderBottomWidth: shouldShow ? CONST.HORIZONTAL_SPACER.DEFAULT_BORDER_BOTTOM_WIDTH : CONST.HORIZONTAL_SPACER.HIDDEN_BORDER_BOTTOM_WIDTH, }; marginVertical.value = withTiming(values.marginVertical, {duration}); borderBottomWidth.value = withTiming(values.borderBottomWidth, {duration});