Skip to content

Commit

Permalink
refactor(suite-native): replace spacing literals with corresponding c…
Browse files Browse the repository at this point in the history
…onstants
  • Loading branch information
yanascz committed Oct 3, 2024
1 parent 6727657 commit b549c1a
Show file tree
Hide file tree
Showing 52 changed files with 88 additions and 91 deletions.
3 changes: 2 additions & 1 deletion packages/theme/src/spacings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ export type Spacings = typeof spacings;
export type Spacing = keyof typeof spacings;
export type SpacingValues = Spacings[Spacing];

type NativeSpacingValue = 2 | 4 | 8 | 12 | 16 | 24 | 32 | 40 | 52 | 64;
type NativeSpacingValue = 2 | 4 | 8 | 12 | 16 | 20 | 24 | 32 | 40 | 52 | 64;

export const nativeSpacings = {
sp2: 2,
sp4: 4,
sp8: 8,
sp12: 12,
sp16: 16,
sp20: 20,
sp24: 24,
sp32: 32,
sp40: 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const accountListItemStyle = prepareNativeStyle<{
justifyContent: 'space-between',
alignItem: 'center',

paddingVertical: 12,
paddingVertical: utils.spacings.sp12,
paddingHorizontal: utils.spacings.sp16,

extend: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const selectableAssetContentStyle = prepareNativeStyle(utils => ({
alignItems: 'center',
justifyContent: 'space-between',
flex: 1,
marginLeft: utils.spacings.sp8 + utils.spacings.sp4,
marginLeft: utils.spacings.sp12,
}));

const tokensBadgeStyle = prepareNativeStyle(utils => ({
paddingBottom: utils.spacings.sp4 / 2,
paddingBottom: utils.spacings.sp2,
}));

export const SelectableNetworkItem = ({ symbol, onPress, rightIcon }: SelectableAssetItemProps) => {
Expand Down
6 changes: 3 additions & 3 deletions suite-native/atoms/src/AlertBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ const alertWrapperStyle = prepareNativeStyle<AlertWrapperStyleType>(
backgroundColor: utils.colors[backgroundColor],
paddingVertical: utils.spacings.sp8,
paddingHorizontal: utils.spacings.sp16,
gap: 12,
gap: utils.spacings.sp12,
}),
);

const textStyle = prepareNativeStyle(_ => ({
const textStyle = prepareNativeStyle(utils => ({
flex: 1,
paddingTop: 2,
paddingTop: utils.spacings.sp2,
}));

const variantToColorMap = {
Expand Down
2 changes: 1 addition & 1 deletion suite-native/atoms/src/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const badgeStyle = prepareNativeStyle<BadgeStyleProps>(
justifyContent: 'center',
backgroundColor: utils.colors[backgroundColor],
paddingHorizontal: utils.spacings.sp8 - (size === 'medium' ? 0 : 2),
paddingVertical: utils.spacings.sp8 / 4,
paddingVertical: utils.spacings.sp2,
borderRadius: utils.borders.radii.round,
extend: [
{
Expand Down
2 changes: 1 addition & 1 deletion suite-native/atoms/src/BottomSheetListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const BottomSheetListItem = ({ translationKey, ...props }: BottomSheetLis
const { applyStyle } = useNativeStyles();

return (
<HStack spacing={12} alignItems="center">
<HStack spacing="sp12" alignItems="center">
<OrderedListIcon {...props} />
<Text style={applyStyle(listItemStyle)}>
<Translation id={translationKey} />
Expand Down
6 changes: 3 additions & 3 deletions suite-native/atoms/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const sizeToDimensionsMap = {
extraSmall: {
minHeight: 36,
paddingVertical: nativeSpacings.sp8,
paddingHorizontal: 12,
paddingHorizontal: nativeSpacings.sp12,
},
small: {
minHeight: 40,
Expand All @@ -190,8 +190,8 @@ const sizeToDimensionsMap = {
},
medium: {
minHeight: 48,
paddingVertical: 12,
paddingHorizontal: 20,
paddingVertical: nativeSpacings.sp12,
paddingHorizontal: nativeSpacings.sp20,
},
large: {
minHeight: 56,
Expand Down
2 changes: 1 addition & 1 deletion suite-native/atoms/src/ScreenHeaderWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const screenHeaderWrapperStyle = prepareNativeStyle<{ insets: EdgeInsets }>(
paddingLeft: Math.max(insets.left, utils.spacings.sp16),
paddingRight: Math.max(insets.right, utils.spacings.sp16),
paddingVertical: utils.spacings.sp16,
paddingBottom: utils.spacings.sp4 * 3,
paddingBottom: utils.spacings.sp12,
}),
);

Expand Down
2 changes: 1 addition & 1 deletion suite-native/atoms/src/Select/SelectTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const selectStyle = prepareNativeStyle(utils => ({
borderRadius: utils.borders.radii.small,
borderColor: utils.colors.backgroundNeutralSubtleOnElevation1,
color: utils.colors.textSubdued,
paddingLeft: 12,
paddingLeft: utils.spacings.sp12,
paddingRight: 23.25,
height: SELECT_HEIGHT,
}));
Expand Down
4 changes: 2 additions & 2 deletions suite-native/atoms/src/SelectableItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const titleWrapperStyle = prepareNativeStyle(_ => ({
justifyContent: 'space-between',
}));

const radioWrapperStyle = prepareNativeStyle(_ => ({
const radioWrapperStyle = prepareNativeStyle(utils => ({
width: '100%',
alignItems: 'flex-end',
paddingTop: 12,
paddingTop: utils.spacings.sp12,
}));

const subtitleWrapperStyle = prepareNativeStyle(utils => ({
Expand Down
2 changes: 1 addition & 1 deletion suite-native/atoms/src/Skeleton/ListItemSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { VStack } from '../Stack';
const skeletonContainer = prepareNativeStyle(utils => ({
flexDirection: 'row',
justifyContent: 'space-between',
paddingVertical: 12,
paddingVertical: utils.spacings.sp12,
paddingHorizontal: utils.spacings.sp16,
}));

Expand Down
2 changes: 1 addition & 1 deletion suite-native/atoms/src/TextDivider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const separatorStyle = prepareNativeStyle<{ horizontalMargin?: number; color: Co
);

const separatorTitleStyle = prepareNativeStyle(utils => ({
paddingHorizontal: 12,
paddingHorizontal: utils.spacings.sp12,
paddingVertical: utils.spacings.sp4,
}));

Expand Down
21 changes: 7 additions & 14 deletions suite-native/biometrics/src/components/BiometricsIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { Platform } from 'react-native';

import { IconName, Icon } from '@suite-common/icons-deprecated';
import { Icon, IconName } from '@suite-common/icons-deprecated';
import { Box } from '@suite-native/atoms';
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';

const ICON_SIZE_DEFAULT = 64;
const ICON_WRAPPER_PADDING = 12;

const iconWrapperStyle = prepareNativeStyle(
(utils, { wrapperSize, showShadow }: { wrapperSize: number; showShadow: boolean }) => ({
padding: ICON_WRAPPER_PADDING,
(utils, { iconSize, showShadow }: { iconSize: number; showShadow: boolean }) => ({
padding: utils.spacings.sp12,
borderRadius: utils.borders.radii.round,
backgroundColor: utils.colors.backgroundSurfaceElevation2,
color: utils.colors.iconPrimaryDefault,
width: wrapperSize,
height: wrapperSize,
width: iconSize + 2 * utils.spacings.sp12,
height: iconSize + 2 * utils.spacings.sp12,

extend: {
condition: showShadow,
Expand All @@ -28,18 +25,14 @@ type BiometricsIconProps = {
showShadow?: boolean;
};

export const BiometricsIcon = ({
iconSize = ICON_SIZE_DEFAULT,
showShadow = false,
}: BiometricsIconProps) => {
export const BiometricsIcon = ({ iconSize = 64, showShadow = false }: BiometricsIconProps) => {
const { applyStyle } = useNativeStyles();
const icon: IconName = Platform.OS === 'ios' ? 'touchId' : 'fingerprint';
const iconWrapperSize = iconSize + 2 * ICON_WRAPPER_PADDING;

return (
<Box
style={applyStyle(iconWrapperStyle, {
wrapperSize: iconWrapperSize,
iconSize,
showShadow,
})}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const DiscoveryCoinsFilter = ({
const uniqueNetworkSymbols = [...new Set(availableNetworks.map(n => n.symbol))];

return (
<VStack spacing={12}>
<VStack spacing="sp12">
{uniqueNetworkSymbols.map((networkSymbol: NetworkSymbol) => (
<NetworkSymbolSwitchItem
key={networkSymbol}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const cardStyle = prepareNativeStyle<{ isEnabled: boolean }>((utils, { isEnabled
],
}));

const wrapperStyle = prepareNativeStyle(_ => ({
const wrapperStyle = prepareNativeStyle(utils => ({
paddingVertical: 6,
paddingHorizontal: 14,
gap: 12,
gap: utils.spacings.sp12,
alignItems: 'center',
flex: 1,
}));
Expand Down Expand Up @@ -128,7 +128,7 @@ export const NetworkSymbolSwitchItem = ({
</View>
<HStack
justifyContent="space-between"
spacing={12}
spacing="sp12"
flex={1}
alignItems="center"
>
Expand Down
2 changes: 1 addition & 1 deletion suite-native/connection-status/src/OfflineBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const contentStyle = prepareNativeStyle<{ topSafeAreaInset: number }>(
(utils, { topSafeAreaInset }) => ({
marginTop: topSafeAreaInset,
paddingTop: utils.spacings.sp8,
paddingBottom: 12,
paddingBottom: utils.spacings.sp12,
alignItems: 'center',
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type DeviceActionProps = {

const contentStyle = prepareNativeStyle(utils => ({
paddingHorizontal: utils.spacings.sp16,
paddingVertical: 12,
paddingVertical: utils.spacings.sp12,
alignItems: 'center',
height: 44 * ACCESSIBILITY_FONTSIZE_MULTIPLIER,
gap: utils.spacings.sp8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const DeviceManagerContent = () => {
/>

{!isPortfolioTrackerDevice && (
<VStack spacing={12} paddingTop="sp24">
<VStack spacing="sp12" paddingTop="sp24">
<WalletList onSelectDevice={handleSelectDevice} />
<Stack
orientation={
Expand Down
2 changes: 1 addition & 1 deletion suite-native/device-manager/src/components/WalletItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const WalletItem = ({ deviceState, onPress, isSelectable = true }: Wallet
{walletNameLabel}
</Text>
</HStack>
<HStack alignItems="center" spacing={12}>
<HStack alignItems="center" spacing="sp12">
<FiatAmountFormatter
value={String(fiatBalance)}
variant="hint"
Expand Down
2 changes: 1 addition & 1 deletion suite-native/device-manager/src/components/WalletList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const WalletList = ({ onSelectDevice }: WalletListProps) => {
const devices = useSelector(selectDeviceInstances);

return (
<VStack spacing={12} paddingHorizontal="sp16">
<VStack spacing="sp12" paddingHorizontal="sp16">
{devices.map(device => {
if (!device.state) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion suite-native/graph/src/components/PriceChangeIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const priceIncreaseWrapperStyle = prepareNativeStyle<{ hasPriceIncreased: boolea
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: utils.spacings.sp8,
paddingVertical: utils.spacings.sp4 / 2,
paddingVertical: utils.spacings.sp2,
borderRadius: utils.borders.radii.round,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const TooltipContainerStyle = prepareNativeStyle<{ x: number; y: number }>((_, {
}));

const TooltipCardStyle = prepareNativeStyle(utils => ({
paddingVertical: 1.5 * utils.spacings.sp8,
paddingVertical: utils.spacings.sp12,
// fade in/out animation doesn't work for elevation (shadow) on Android
elevation: 0,
}));
Expand Down
4 changes: 2 additions & 2 deletions suite-native/message-system/src/components/MessageBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ export const MessageBanner = ({ message }: MessageBannerProps) => {
style={applyStyle(messageContainerStyle, { backgroundColor })}
>
<HStack
spacing={12}
spacing="sp12"
alignItems="center"
justifyContent="space-between"
style={{ maxWidth: '100%' }}
>
<Box style={applyStyle(IconContainerStyle)}>
<Icon name={icon} color={iconColor} size="mediumLarge" />
</Box>
<VStack spacing={4} style={applyStyle(messageTextContainerStyle)}>
<VStack spacing="sp4" style={applyStyle(messageTextContainerStyle)}>
<Text color="textSubdued" variant="hint">
{messageContent}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const MessageSystemBannerRenderer = () => {

return (
<VStack
spacing={4}
spacing="sp4"
style={applyStyle(messageBannerContainerStyle, {
topSafeAreaInset: topInset,
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const indicatorContainer = prepareNativeStyle(utils => ({
maxWidth: '40%',
alignItems: 'center',
justifyContent: 'flex-start',
marginTop: utils.spacings.sp8 / 4,
marginTop: utils.spacings.sp2,
}));

const PriceChangeIndicator = ({ valuePercentageChange }: PriceChangeIndicatorProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import { ConnectDeviceScreenHeader } from '../../components/connect/ConnectDevic

const ANIMATION_HEIGHT = Dimensions.get('screen').height * 0.6;

const screenContentStyle = prepareNativeStyle(() => ({
const screenContentStyle = prepareNativeStyle(utils => ({
flex: 1,
justifyContent: 'space-between',
alignItems: 'center',
paddingTop: 40,
paddingTop: utils.spacings.sp40,
}));

const animationStyle = prepareNativeStyle(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const PassphraseEmptyWalletScreen = () => {
lineColor="borderElevation0"
textColor="textSubdued"
/>
<VStack spacing={20}>
<VStack spacing="sp20">
<VStack alignItems="center" spacing="sp4">
<Text
textAlign="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const cardTextStyle = prepareNativeStyle(_ => ({
width: '90%',
}));

const warningIconWrapperStyle = prepareNativeStyle(_ => ({
paddingTop: 2,
const warningIconWrapperStyle = prepareNativeStyle(utils => ({
paddingTop: utils.spacings.sp2,
}));

const animationWrapperStyle = prepareNativeStyle(() => ({
Expand Down Expand Up @@ -91,7 +91,7 @@ export const PassphraseFormScreen = () => {
<Animated.View style={animationStyle}>
<Box style={applyStyle(cardStyle)}>
<VStack spacing="sp16">
<VStack spacing={12}>
<VStack spacing="sp12">
<HStack>
<View style={applyStyle(warningIconWrapperStyle)}>
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const iconWrapper = prepareNativeStyle(utils => ({
borderRadius: utils.borders.radii.round,
}));

const rowContentStyle = prepareNativeStyle(_ => ({
marginLeft: 12,
const rowContentStyle = prepareNativeStyle(utils => ({
marginLeft: utils.spacings.sp12,
marginRight: 48,
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ type OnboardingScreenHeaderProps = {
activeStep: number;
};

const titleStyle = prepareNativeStyle(() => ({
const titleStyle = prepareNativeStyle(utils => ({
textAlign: 'center',
marginBottom: 12,
marginBottom: utils.spacings.sp12,
}));

const wrapperStyle = prepareNativeStyle(() => ({
paddingHorizontal: 16,
paddingTop: 32,
const wrapperStyle = prepareNativeStyle(utils => ({
paddingHorizontal: utils.spacings.sp16,
paddingTop: utils.spacings.sp32,
}));

const subtitleStyle = prepareNativeStyle(() => ({
Expand Down
Loading

0 comments on commit b549c1a

Please sign in to comment.