Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(suite-native): use linear gradient in screen footers with buttons #16608

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions suite-native/coin-enabling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@mobily/ts-belt": "^3.13.1",
"@react-navigation/native": "6.1.18",
"@reduxjs/toolkit": "1.9.5",
"@suite-common/suite-utils": "workspace:*",
"@suite-common/wallet-config": "workspace:*",
"@suite-common/wallet-core": "workspace:*",
"@suite-native/alerts": "workspace:*",
Expand All @@ -27,7 +26,6 @@
"@suite-native/toasts": "workspace:*",
"@suite-native/tokens": "workspace:*",
"@trezor/styles": "workspace:*",
"expo-linear-gradient": "^14.0.1",
"react": "18.2.0",
"react-native": "0.76.1",
"react-native-reanimated": "^3.16.7",
Expand Down
68 changes: 13 additions & 55 deletions suite-native/coin-enabling/src/screens/CoinEnablingInitScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,30 @@
import { useDispatch, useSelector } from 'react-redux';
import Animated, { SlideInDown, SlideOutDown } from 'react-native-reanimated';
import { View } from 'react-native';

import { A } from '@mobily/ts-belt';
import { useNavigation } from '@react-navigation/native';
import { LinearGradient } from 'expo-linear-gradient';

import { Screen, useHandleHardwareBackNavigation } from '@suite-native/navigation';
import {
Screen,
ScreenFooterGradient,
useHandleHardwareBackNavigation,
} from '@suite-native/navigation';
import { Box, Button, Text, VStack } from '@suite-native/atoms';
import {
applyDiscoveryChangesThunk,
selectDeviceEnabledDiscoveryNetworkSymbols,
setIsCoinEnablingInitFinished,
} from '@suite-native/discovery';
import { Translation } from '@suite-native/intl';
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
import { analytics, EventType } from '@suite-native/analytics';
import { hexToRgba } from '@suite-common/suite-utils';

import { DiscoveryCoinsFilter } from '../components/DiscoveryCoinsFilter';

const BOTTOM_OFFSET = 12;
const BUTTON_HEIGHT = 48;

const contentStyle = prepareNativeStyle(_ => ({
paddingBottom: BOTTOM_OFFSET,
}));

const gradientBackgroundBottomStyle = prepareNativeStyle<{ showButton: boolean }>(
(utils, { showButton }) => ({
width: '100%',
height: utils.spacings.sp16,
position: 'absolute',
bottom: -BOTTOM_OFFSET,
pointerEvents: 'none',
extend: [{ condition: showButton, style: { bottom: BUTTON_HEIGHT } }],
}),
);

const buttonWrapperStyle = prepareNativeStyle(utils => ({
bottom: BOTTOM_OFFSET,
backgroundColor: utils.colors.backgroundSurfaceElevation0,
width: '100%',
}));

const buttonStyle = prepareNativeStyle(utils => ({
paddingHorizontal: utils.spacings.sp16,
}));

export const CoinEnablingInitScreen = () => {
const dispatch = useDispatch();
const navigation = useNavigation();
useHandleHardwareBackNavigation();

const { applyStyle, utils } = useNativeStyles();
const enabledNetworkSymbols = useSelector(selectDeviceEnabledDiscoveryNetworkSymbols);

const handleSave = () => {
Expand All @@ -69,9 +40,6 @@ export const CoinEnablingInitScreen = () => {
}
};

// 'transparent' color is not working in context of LinearGradient on iOS. RGBA has to be used instead.
const transparentColor = hexToRgba(utils.colors.backgroundSurfaceElevation0, 0.01);

const canBeSaved = A.isNotEmpty(enabledNetworkSymbols);

return (
Expand All @@ -87,29 +55,19 @@ export const CoinEnablingInitScreen = () => {
</VStack>
}
footer={
<View style={applyStyle(buttonWrapperStyle)}>
<LinearGradient
dither={false}
colors={[transparentColor, utils.colors.backgroundSurfaceElevation0]}
style={applyStyle(gradientBackgroundBottomStyle, {
showButton: canBeSaved,
})}
/>
{canBeSaved && (
<Animated.View
entering={SlideInDown}
exiting={SlideOutDown}
style={applyStyle(buttonStyle)}
>
canBeSaved && (
<Animated.View entering={SlideInDown} exiting={SlideOutDown}>
<ScreenFooterGradient />
<Box marginHorizontal="sp16">
<Button onPress={handleSave} testID="@coin-enabling/button-save">
<Translation id="moduleSettings.coinEnabling.initialSetup.button" />
</Button>
</Animated.View>
)}
</View>
</Box>
</Animated.View>
)
}
>
<Box style={applyStyle(contentStyle)}>
<Box>
<DiscoveryCoinsFilter allowDeselectLastCoin={true} allowChangeAnalytics={false} />
</Box>
</Screen>
Expand Down
3 changes: 0 additions & 3 deletions suite-native/coin-enabling/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": { "outDir": "libDev" },
"references": [
{
"path": "../../suite-common/suite-utils"
},
{
"path": "../../suite-common/wallet-config"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode } from 'react';
import { KeyboardAvoidingView, Platform } from 'react-native';

import { Box, PictogramTitleHeader, VStack } from '@suite-native/atoms';
import { Screen } from '@suite-native/navigation';
import { Screen, ScreenFooterGradient } from '@suite-native/navigation';

import { AccountImportScreenHeader } from './AccountImportScreenHeader';

Expand All @@ -25,7 +25,8 @@ export const AccountImportSummaryScreen = ({
header={<AccountImportScreenHeader />}
footer={
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
<Box margin="sp16">{footer}</Box>
<ScreenFooterGradient />
<Box marginHorizontal="sp16">{footer}</Box>
</KeyboardAvoidingView>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { FirmwareUpdateVersionCard } from './FirmwareVersionCard';

const firmwareUpdateButtonStyle = prepareNativeStyle(utils => ({
marginHorizontal: utils.spacings.sp16,
marginBottom: utils.spacings.sp16,
}));

type NavigationProp = StackNavigationProps<
Expand Down
35 changes: 14 additions & 21 deletions suite-native/module-send/src/screens/SendOutputsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
updateFeeInfoThunk,
} from '@suite-common/wallet-core';
import {
ScreenFooterGradient,
SendStackParamList,
SendStackRoutes,
StackNavigationProps,
Expand All @@ -30,7 +31,6 @@ import { getNetwork } from '@suite-common/wallet-config';
import { Box, Button } from '@suite-native/atoms';
import { Translation } from '@suite-native/intl';
import { useDebounce } from '@trezor/react-utils';
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
import { useForm, Form } from '@suite-native/forms';
import { selectIsAmountInSats, SettingsSliceRootState } from '@suite-native/settings';
import { TokenAddress } from '@suite-common/wallet-types';
Expand All @@ -46,11 +46,6 @@ import { FeeLevelsMaxAmount } from '../types';
import { storeFeeLevels } from '../sendFormSlice';
import { useSubscribeForSolanaBlockUpdates } from '../hooks/useSubscribeForSolanaBlockUpdates';

const buttonWrapperStyle = prepareNativeStyle(utils => ({
width: '100%',
padding: utils.spacings.sp16,
}));

const getDefaultValues = ({
tokenContract,
}: {
Expand All @@ -72,7 +67,6 @@ export const SendOutputsScreen = ({
}: StackProps<SendStackParamList, SendStackRoutes.SendOutputs>) => {
const { accountKey, tokenContract } = params;
const dispatch = useDispatch();
const { applyStyle } = useNativeStyles();
const debounce = useDebounce();
const navigation =
useNavigation<StackNavigationProps<SendStackParamList, SendStackRoutes.SendOutputs>>();
Expand Down Expand Up @@ -275,20 +269,19 @@ export const SendOutputsScreen = ({
}
footer={
isValid && (
<Animated.View
entering={SlideInDown}
exiting={SlideOutDown}
style={applyStyle(buttonWrapperStyle)}
>
<Button
accessibilityRole="button"
accessibilityLabel="validate send form"
testID="@send/form-submit-button"
onPress={handleNavigateToReviewScreen}
isDisabled={isSubmitting}
>
<Translation id="generic.buttons.continue" />
</Button>
<Animated.View entering={SlideInDown} exiting={SlideOutDown}>
<ScreenFooterGradient />
<Box marginHorizontal="sp16">
<Button
accessibilityRole="button"
accessibilityLabel="validate send form"
testID="@send/form-submit-button"
onPress={handleNavigateToReviewScreen}
isDisabled={isSubmitting}
>
<Translation id="generic.buttons.continue" />
</Button>
</Box>
</Animated.View>
)
}
Expand Down
1 change: 1 addition & 0 deletions suite-native/navigation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@trezor/connect": "workspace:*",
"@trezor/styles": "workspace:*",
"@trezor/theme": "workspace:*",
"expo-linear-gradient": "14.0.1",
"expo-linking": "^7.0.2",
"expo-navigation-bar": "^4.0.2",
"expo-system-ui": "^4.0.2",
Expand Down
28 changes: 28 additions & 0 deletions suite-native/navigation/src/components/ScreenFooterGradient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { LinearGradient } from 'expo-linear-gradient';

import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
import { hexToRgba } from '@suite-common/suite-utils';

const screenFooterGradientStyle = prepareNativeStyle(utils => ({
width: '100%',
height: utils.spacings.sp16,
top: -utils.spacings.sp16,
marginBottom: -utils.spacings.sp16,
pointerEvents: 'none',
}));

export const ScreenFooterGradient = () => {
const { applyStyle, utils } = useNativeStyles();

// 'transparent' color does not work in context of LinearGradient on iOS, RGBA has to be used instead.
const backgroundColor = utils.colors.backgroundSurfaceElevation0;
const transparentColor = hexToRgba(backgroundColor, 0.01);

return (
<LinearGradient
dither={false}
colors={[transparentColor, backgroundColor]}
style={applyStyle(screenFooterGradientStyle)}
/>
);
};
1 change: 1 addition & 0 deletions suite-native/navigation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './useScrollDivider';
export * from './components/TabBar';
export * from './components/Screen';
export * from './components/ScreenHeader';
export * from './components/ScreenFooterGradient';
export * from './components/NavigationContainerWithAnalytics';
export * from './components/GoBackIcon';
export * from './components/ScrollViewContext';
5 changes: 2 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10172,7 +10172,6 @@ __metadata:
"@mobily/ts-belt": "npm:^3.13.1"
"@react-navigation/native": "npm:6.1.18"
"@reduxjs/toolkit": "npm:1.9.5"
"@suite-common/suite-utils": "workspace:*"
"@suite-common/wallet-config": "workspace:*"
"@suite-common/wallet-core": "workspace:*"
"@suite-native/alerts": "workspace:*"
Expand All @@ -10186,7 +10185,6 @@ __metadata:
"@suite-native/toasts": "workspace:*"
"@suite-native/tokens": "workspace:*"
"@trezor/styles": "workspace:*"
expo-linear-gradient: "npm:^14.0.1"
react: "npm:18.2.0"
react-native: "npm:0.76.1"
react-native-reanimated: "npm:^3.16.7"
Expand Down Expand Up @@ -10967,6 +10965,7 @@ __metadata:
"@trezor/connect": "workspace:*"
"@trezor/styles": "workspace:*"
"@trezor/theme": "workspace:*"
expo-linear-gradient: "npm:14.0.1"
expo-linking: "npm:^7.0.2"
expo-navigation-bar: "npm:^4.0.2"
expo-system-ui: "npm:^4.0.2"
Expand Down Expand Up @@ -23121,7 +23120,7 @@ __metadata:
languageName: node
linkType: hard

"expo-linear-gradient@npm:^14.0.1":
"expo-linear-gradient@npm:14.0.1, expo-linear-gradient@npm:^14.0.1":
version: 14.0.1
resolution: "expo-linear-gradient@npm:14.0.1"
peerDependencies:
Expand Down
Loading