Skip to content

Commit

Permalink
Use style function for switch thumb transform style
Browse files Browse the repository at this point in the history
  • Loading branch information
huzaifa-99 committed Jul 30, 2023
1 parent 6c7b2c4 commit c85c33f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/components/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const OFFSET_X = {

function Switch(props) {
const offsetX = useRef(new Animated.Value(props.isOn ? OFFSET_X.ON : OFFSET_X.OFF));
const switchTransformStyle = {transform: [{translateX: offsetX.current}]};

useEffect(() => {
Animated.timing(offsetX.current, {
Expand All @@ -46,7 +45,7 @@ function Switch(props) {
hoverDimmingValue={1}
pressDimmingValue={0.8}
>
<Animated.View style={[styles.switchThumb, switchTransformStyle]} />
<Animated.View style={[styles.switchThumb, styles.switchThumbTransformation(offsetX.current)]} />
</PressableWithFeedback>
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,10 @@ const styles = {
backgroundColor: themeColors.appBG,
},

switchThumbTransformation: (translateX) => ({
transform: [{translateX}],
}),

radioButtonContainer: {
backgroundColor: themeColors.componentBG,
borderRadius: 10,
Expand Down

0 comments on commit c85c33f

Please sign in to comment.