Skip to content

Commit

Permalink
feat(suite-native): replace illustrations and lotties with updated ones
Browse files Browse the repository at this point in the history
  • Loading branch information
yanascz committed Dec 3, 2024
1 parent fcc1e8e commit 2bddce1
Show file tree
Hide file tree
Showing 47 changed files with 838 additions and 887 deletions.
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ buck-out/
!**/suite-native/app/.env.staging

suite-native/atoms/src/Spinner/refresh-spinner-*.json
suite-native/module-authorize-device/src/assets/passphrase/confirm-on-trezor-lottie.json
suite-native/module-home/src/assets/view-only-lottie.json
suite-native/module-send/assets/send-arrows-lottie.json
suite-native/module-settings/src/assets/connect-trezor-lottie.json

# ios
**/ios/*.xcarchive
Expand Down
5 changes: 2 additions & 3 deletions suite-native/alerts/src/components/AlertSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type AlertSheetProps = {
const alertSheetContainerStyle = prepareNativeStyle(utils => ({
justifyContent: 'center',
alignItems: 'center',
paddingTop: utils.spacings.sp32,
paddingHorizontal: utils.spacings.sp24,
paddingVertical: utils.spacings.sp32,
marginBottom: utils.spacings.sp32,
Expand All @@ -35,7 +34,7 @@ const alertSheetContainerStyle = prepareNativeStyle(utils => ({

const alertSheetContentStyle = prepareNativeStyle(utils => ({
width: '100%',
gap: utils.spacings.sp24,
gap: utils.spacings.sp32,
}));

const shakeTriggerStyle = prepareNativeStyle(_ => ({
Expand Down Expand Up @@ -115,7 +114,7 @@ export const AlertSheet = ({ alert }: AlertSheetProps) => {
/>
)}
{appendix}
<VStack spacing="sp16">
<VStack spacing="sp12">
<Button
size="medium"
colorScheme={primaryButtonVariant}
Expand Down
78 changes: 78 additions & 0 deletions suite-native/atoms/src/LottieAnimation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, { useMemo } from 'react';

import Lottie, { AnimationObject } from 'lottie-react-native';

import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
import { CSSColor } from '@trezor/theme';

import { useIllustrationColors } from './useIllustrationColors';

type LottieAnimationSize = 'standard' | 'small';
type LottieAnimationProps = {
source: AnimationObject;
size?: LottieAnimationSize;
};

type LottieColor = [number, number, number, 1];
type LottieColors = {
lineColor: LottieColor;
fillColor: LottieColor;
};

const hexToLottieColor = (hex: CSSColor): LottieColor => {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);

return [r / 255, g / 255, b / 255, 1];
};

const colorizeLayer = (layer: any, { lineColor, fillColor }: LottieColors) => ({
...layer,
shapes: layer.shapes?.map((shape: any) => ({
...shape,
it: shape.it?.map((it: any) =>
it.c?.k ? { ...it, c: { ...it.c, k: it.c.k[0] === 0 ? lineColor : fillColor } } : it,
),
})),
});

const sizeToDimensionsMap = {
standard: 224,
small: 90,
} as const satisfies Record<LottieAnimationSize, number>;

const animationStyle = prepareNativeStyle<{ size: LottieAnimationSize }>((_, { size }) => ({
width: sizeToDimensionsMap[size],
height: sizeToDimensionsMap[size],
}));

export const LottieAnimation = ({ source, size = 'standard' }: LottieAnimationProps) => {
const { lineColor, fillColor } = useIllustrationColors();
const { applyStyle } = useNativeStyles();

const colorizedSource = useMemo(() => {
const colors = {
lineColor: hexToLottieColor(lineColor),
fillColor: hexToLottieColor(fillColor),
};

return {
...source,
assets: source.assets.map((asset: { layers: any[] }) => ({
...asset,
layers: asset.layers.map(l => colorizeLayer(l, colors)),
})),
layers: source.layers.map(l => colorizeLayer(l, colors)),
};
}, [source, lineColor, fillColor]);

return (
<Lottie
source={colorizedSource}
style={applyStyle(animationStyle, { size })}
autoPlay
loop
/>
);
};
2 changes: 2 additions & 0 deletions suite-native/atoms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export * from './ScreenHeaderWrapper';
export * from './ErrorMessage';
export * from './Table';
export * from './Loader';
export * from './LottieAnimation';
export * from './Toggle';
export * from './Pictogram';
export * from './TitleHeader/PictogramTitleHeader';
Expand All @@ -52,6 +53,7 @@ export * from './IconListItem';
export * from './BulletListItem';
export * from './SelectableItem';
export * from './constants';
export * from './useIllustrationColors';
export * from './utils';

export { useDebugView } from './DebugView';
9 changes: 9 additions & 0 deletions suite-native/atoms/src/useIllustrationColors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useNativeStyles } from '@trezor/styles';

export const useIllustrationColors = () => {
const { utils } = useNativeStyles();
const lineColor = utils.colors.backgroundPrimaryDefault;
const fillColor = utils.colors.backgroundSurfaceElevation0;

return { lineColor, fillColor };
};
3 changes: 2 additions & 1 deletion suite-native/biometrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"expo-local-authentication": "14.0.1",
"jotai": "1.9.1",
"react": "18.2.0",
"react-native": "0.76.1"
"react-native": "0.76.1",
"react-native-svg": "15.9.0"
}
}
Loading

0 comments on commit 2bddce1

Please sign in to comment.