-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:rainbow-me/rainbow into brody/de…
…eplink-add * 'develop' of github.com:rainbow-me/rainbow: Cover a few more edge cases with showing the swap warnings (#5648) refetch quote if a user selects a new assset to sell with a buy asset already selected (#5643) Fix random quote edge cases (#5644) use dapp metadata where possible (#5629) Output chain selection context menu (#5630) chore: use native currency balances (#5631) browser: android fixes (#5642) Review Sheet (#5632)
- Loading branch information
Showing
49 changed files
with
1,497 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import React from 'react'; | ||
|
||
import { AnimatedText, Box, Inline, globalColors, useColorMode, useForegroundColor } from '@/design-system'; | ||
import Animated, { DerivedValue, useAnimatedStyle, useDerivedValue, withSpring, withTiming } from 'react-native-reanimated'; | ||
import { fadeConfig, springConfig } from '../constants'; | ||
import { opacityWorklet } from '@/__swaps__/utils/swaps'; | ||
import { GestureHandlerButtonProps, GestureHandlerV1Button } from './GestureHandlerV1Button'; | ||
import { StyleSheet } from 'react-native'; | ||
|
||
type AnimatedSwitchProps = { | ||
onToggle: () => void; | ||
value: DerivedValue<boolean>; | ||
activeLabel?: string; | ||
inactiveLabel?: string; | ||
} & Omit<GestureHandlerButtonProps, 'children'>; | ||
|
||
export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, ...props }: AnimatedSwitchProps) { | ||
const { isDarkMode } = useColorMode(); | ||
|
||
const inactiveBg = useForegroundColor('fillSecondary'); | ||
const activeBg = useForegroundColor('green'); | ||
const border = useForegroundColor('separatorSecondary'); | ||
|
||
const containerStyles = useAnimatedStyle(() => { | ||
return { | ||
backgroundColor: !value.value | ||
? withTiming(opacityWorklet(inactiveBg, 0.12), fadeConfig) | ||
: withTiming(opacityWorklet(activeBg, 0.64), fadeConfig), | ||
borderColor: opacityWorklet(border, 0.06), | ||
}; | ||
}); | ||
|
||
const circleStyles = useAnimatedStyle(() => { | ||
return { | ||
transform: [ | ||
{ | ||
translateX: withSpring(value.value ? 11 : 1, springConfig), | ||
}, | ||
], | ||
}; | ||
}); | ||
|
||
const labelItem = useDerivedValue(() => { | ||
if (!activeLabel && !inactiveLabel) { | ||
return; | ||
} | ||
|
||
if (value.value) { | ||
return activeLabel; | ||
} | ||
|
||
return inactiveLabel; | ||
}); | ||
|
||
if (labelItem.value) { | ||
return ( | ||
<Inline alignVertical="center" horizontalSpace="6px"> | ||
<AnimatedText align="right" color={isDarkMode ? 'labelSecondary' : 'label'} size="15pt" weight="heavy" text={labelItem} /> | ||
{/* TODO: Small switch, so let's move this out to be the whole row */} | ||
<GestureHandlerV1Button onPressWorklet={onToggle} style={[styles.containerStyles, containerStyles]} {...props}> | ||
<Box style={[styles.circleStyles, circleStyles]} as={Animated.View} /> | ||
</GestureHandlerV1Button> | ||
</Inline> | ||
); | ||
} | ||
|
||
return ( | ||
<GestureHandlerV1Button onPressWorklet={onToggle} style={[styles.containerStyles, containerStyles]} {...props}> | ||
<Box style={[styles.circleStyles, circleStyles]} as={Animated.View} /> | ||
</GestureHandlerV1Button> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
containerStyles: { | ||
position: 'relative', | ||
borderWidth: 1, | ||
borderRadius: 100, | ||
width: 26, | ||
height: 16, | ||
}, | ||
circleStyles: { | ||
top: 1, | ||
backgroundColor: globalColors.white100, | ||
borderRadius: 100, | ||
width: 12, | ||
height: 12, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.