Skip to content

Commit

Permalink
Refactor constants
Browse files Browse the repository at this point in the history
  • Loading branch information
zukilover committed Sep 15, 2023
1 parent b8bb920 commit a172535
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
13 changes: 7 additions & 6 deletions src/components/SpacerView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
/**
Expand All @@ -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});
Expand Down

0 comments on commit a172535

Please sign in to comment.