-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): new device switcher
- Loading branch information
Showing
38 changed files
with
1,116 additions
and
440 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
60 changes: 60 additions & 0 deletions
60
suite-native/device-manager/src/components/DeviceAction.tsx
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,60 @@ | ||
import { ReactNode } from 'react'; | ||
import { Pressable } from 'react-native'; | ||
|
||
import { HStack } from '@suite-native/atoms'; | ||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
|
||
type DeviceActionProps = { | ||
testID: string; | ||
onPress: () => void; | ||
children: ReactNode; | ||
flex?: number; | ||
showAsFullWidth?: boolean; | ||
}; | ||
|
||
const contentStyle = prepareNativeStyle(utils => ({ | ||
paddingHorizontal: utils.spacings.medium, | ||
paddingVertical: 12, | ||
alignItems: 'center', | ||
height: 44, | ||
gap: utils.spacings.small, | ||
backgroundColor: utils.colors.backgroundSurfaceElevation1, | ||
borderWidth: utils.borders.widths.small, | ||
borderRadius: 12, | ||
borderColor: utils.colors.borderElevation1, | ||
})); | ||
|
||
const pressableStyle = prepareNativeStyle<{ showAsFullWidth: boolean; flex: number | undefined }>( | ||
(_, { showAsFullWidth, flex }) => { | ||
return { | ||
flex, | ||
extend: { | ||
condition: showAsFullWidth, | ||
style: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
}, | ||
}, | ||
}; | ||
}, | ||
); | ||
|
||
export const DeviceAction = ({ | ||
testID, | ||
onPress, | ||
children, | ||
flex, | ||
showAsFullWidth = false, | ||
}: DeviceActionProps) => { | ||
const { applyStyle } = useNativeStyles(); | ||
|
||
return ( | ||
<Pressable | ||
onPress={onPress} | ||
testID={testID} | ||
style={applyStyle(pressableStyle, { showAsFullWidth, flex })} | ||
> | ||
<HStack style={applyStyle(contentStyle)}>{children}</HStack> | ||
</Pressable> | ||
); | ||
}; |
62 changes: 0 additions & 62 deletions
62
suite-native/device-manager/src/components/DeviceControlButtons.tsx
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
suite-native/device-manager/src/components/DeviceInfoButton.tsx
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,68 @@ | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { useNavigation } from '@react-navigation/native'; | ||
|
||
import { analytics, EventType } from '@suite-native/analytics'; | ||
import { HStack, Text } from '@suite-native/atoms'; | ||
import { selectDevice } from '@suite-common/wallet-core'; | ||
import { Translation } from '@suite-native/intl'; | ||
import { | ||
RootStackParamList, | ||
RootStackRoutes, | ||
StackToStackCompositeNavigationProps, | ||
} from '@suite-native/navigation'; | ||
import { Icon } from '@suite-common/icons'; | ||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
|
||
import { useDeviceManager } from '../hooks/useDeviceManager'; | ||
import { DeviceAction } from './DeviceAction'; | ||
|
||
type NavigationProp = StackToStackCompositeNavigationProps< | ||
RootStackParamList, | ||
RootStackRoutes.AppTabs, | ||
RootStackParamList | ||
>; | ||
|
||
type DeviceInfoButtonProps = { | ||
showAsFullWidth: boolean; | ||
}; | ||
|
||
const contentStyle = prepareNativeStyle<{ showAsFullWidth: boolean }>((_, { showAsFullWidth }) => ({ | ||
extend: { | ||
condition: showAsFullWidth, | ||
style: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
}, | ||
}, | ||
})); | ||
|
||
export const DeviceInfoButton = ({ showAsFullWidth }: DeviceInfoButtonProps) => { | ||
const { applyStyle } = useNativeStyles(); | ||
const navigation = useNavigation<NavigationProp>(); | ||
const { setIsDeviceManagerVisible } = useDeviceManager(); | ||
const selectedDevice = useSelector(selectDevice); | ||
|
||
const handleDeviceRedirect = () => { | ||
setIsDeviceManagerVisible(false); | ||
navigation.navigate(RootStackRoutes.DeviceInfo); | ||
analytics.report({ type: EventType.DeviceManagerClick, payload: { action: 'deviceInfo' } }); | ||
}; | ||
|
||
if (!selectedDevice) return null; | ||
|
||
return ( | ||
<DeviceAction | ||
testID="@device-manager/device/info" | ||
onPress={handleDeviceRedirect} | ||
showAsFullWidth={showAsFullWidth} | ||
> | ||
<HStack spacing="small" style={applyStyle(contentStyle, { showAsFullWidth })}> | ||
<Icon name="infoLight" size="mediumLarge" /> | ||
<Text variant="hint"> | ||
<Translation id="deviceManager.deviceButtons.deviceInfo" /> | ||
</Text> | ||
</HStack> | ||
</DeviceAction> | ||
); | ||
}; |
Oops, something went wrong.