-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web3hub): add app screen webview [LIVE-13179]
Also add real fetch calls to new manifest-api v2 preview Update tests for app screen with mocks
- Loading branch information
Showing
26 changed files
with
830 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"live-mobile": minor | ||
--- | ||
|
||
feat(web3hub): add app screen webview | ||
|
||
Also add real fetch calls to new manifest-api v2 preview | ||
Update tests for app screen with mocks |
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
122 changes: 122 additions & 0 deletions
122
apps/ledger-live-mobile/src/newArch/features/Web3Hub/components/AppIcon/index.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,122 @@ | ||
import React, { memo, useState, useCallback, useEffect } from "react"; | ||
import { Image, View, StyleSheet } from "react-native"; | ||
import { Text } from "@ledgerhq/native-ui"; | ||
import { DefaultTheme, useTheme } from "styled-components/native"; | ||
import { Theme } from "~/colors"; | ||
|
||
type Props = { | ||
name?: string | null; | ||
icon?: string | null; | ||
size?: number; | ||
isDisabled?: boolean; | ||
}; | ||
|
||
const AppIcon = ({ size = 48, name, icon, isDisabled }: Props) => { | ||
const { colors } = useTheme() as DefaultTheme & Theme; | ||
const [imageLoaded, setImageLoaded] = useState(true); | ||
const handleImageLoad = useCallback(() => setImageLoaded(true), []); | ||
const handleImageError = useCallback(() => setImageLoaded(false), []); | ||
const firstLetter = typeof name === "string" && name[0] ? name[0].toUpperCase() : ""; | ||
|
||
// Reset state if icon changed with recycled view | ||
useEffect(() => { | ||
setImageLoaded(true); | ||
}, [icon]); | ||
|
||
return ( | ||
<View | ||
style={[ | ||
styles.container, | ||
{ | ||
width: size, | ||
height: size, | ||
borderColor: colors.neutral.c30, | ||
backgroundColor: "transparent", | ||
}, | ||
]} | ||
> | ||
{!imageLoaded && firstLetter ? ( | ||
<Text | ||
fontWeight="semiBold" | ||
variant="h2" | ||
style={{ | ||
lineHeight: size, | ||
}} | ||
> | ||
{firstLetter} | ||
</Text> | ||
) : icon ? ( | ||
<> | ||
<Image | ||
source={{ | ||
uri: icon, | ||
}} | ||
style={[ | ||
styles.image, | ||
...(isDisabled ? [styles.disabledTopLayer] : []), | ||
{ | ||
width: size, | ||
height: size, | ||
}, | ||
]} | ||
fadeDuration={200} | ||
onLoad={handleImageLoad} | ||
onError={handleImageError} | ||
/> | ||
{isDisabled ? ( | ||
<Image | ||
source={{ | ||
uri: icon, | ||
}} | ||
style={[ | ||
styles.image, | ||
styles.disabledBottomLayer, | ||
{ | ||
width: size, | ||
height: size, | ||
tintColor: colors.fog, | ||
}, | ||
]} | ||
fadeDuration={200} | ||
/> | ||
) : null} | ||
</> | ||
) : ( | ||
<Text | ||
fontWeight="semiBold" | ||
variant="h2" | ||
style={{ | ||
lineHeight: size, | ||
}} | ||
> | ||
{firstLetter} | ||
</Text> | ||
)} | ||
</View> | ||
); | ||
}; | ||
|
||
export default memo(AppIcon); | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
alignItems: "center", | ||
justifyContent: "center", | ||
borderRadius: 8, | ||
borderWidth: 1, | ||
position: "relative", | ||
}, | ||
image: { | ||
borderRadius: 8, | ||
overflow: "hidden", | ||
}, | ||
disabledTopLayer: { | ||
position: "absolute", | ||
opacity: 0.3, | ||
zIndex: 1, | ||
}, | ||
disabledBottomLayer: { | ||
position: "absolute", | ||
zIndex: 0, | ||
}, | ||
}); |
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.