REF: useMemo

This commit is contained in:
Marcos Rodriguez Velez 2024-02-06 20:20:02 -04:00
parent 8dee082001
commit 6aed1a4e93
No known key found for this signature in database
GPG Key ID: 6030B2F48CCE86D7
2 changed files with 47 additions and 34 deletions

View File

@ -1,5 +1,6 @@
import { StyleSheet } from 'react-native';
import { useTheme } from '../../components/themes';
import { useMemo } from 'react';
export const styles = StyleSheet.create({
root: {
@ -18,12 +19,24 @@ export const styles = StyleSheet.create({
});
export const useDynamicStyles = () => {
const { colors } = useTheme();
const theme = useTheme();
return StyleSheet.create({
root: {
backgroundColor: colors.elevated,
},
// More properties
});
const stylesHook = useMemo(
() =>
StyleSheet.create({
root: {
backgroundColor: theme.colors.elevated,
// Add more dynamic styles as needed
},
container: {
// Example of another dynamic style
borderColor: theme.colors.inputBorderColor,
borderWidth: 1,
},
// You can add more dynamically themed styles here
}),
[theme],
); // Recompute styles only when theme changes
return stylesHook;
};

View File

@ -78,36 +78,36 @@ const WalletXpub: React.FC = () => {
setQRCodeSize(height > width ? width - 40 : e.nativeEvent.layout.width / 1.8);
};
const handleShareButtonPressed = () => {
Share.open({ message: xpub }).catch(error => console.log(error));
};
const handleShareButtonPressed = useCallback(() => {
Share.open({ message: xpub }).catch(console.log);
}, [xpub]);
return isLoading ? (
<View style={[styles.container, stylesHook.root]}>
<ActivityIndicator />
</View>
) : (
return (
<SafeArea style={[styles.root, stylesHook.root]} onLayout={onLayout}>
<>
<View style={styles.container}>
{wallet && (
<>
<View>
<BlueText>{wallet.typeReadable}</BlueText>
</View>
<BlueSpacing20 />
</>
)}
<QRCodeComponent value={xpub} size={qrCodeSize} />
{isLoading ? (
<ActivityIndicator />
) : (
<>
<View style={styles.container}>
{wallet && (
<>
<View>
<BlueText>{wallet.typeReadable}</BlueText>
</View>
<BlueSpacing20 />
</>
)}
<QRCodeComponent value={xpub} size={qrCodeSize} />
<BlueSpacing20 />
<BlueCopyTextToClipboard text={xPubText} />
</View>
<HandoffComponent title={loc.wallets.xpub_title} type={HandoffComponent.activityTypes.Xpub} userInfo={{ xpub: xPubText }} />
<View style={styles.share}>
<Button onPress={handleShareButtonPressed} title={loc.receive.details_share} />
</View>
</>
<BlueSpacing20 />
<BlueCopyTextToClipboard text={xPubText} />
</View>
<HandoffComponent title={loc.wallets.xpub_title} type={HandoffComponent.activityTypes.Xpub} userInfo={{ xpub: xPubText }} />
<View style={styles.share}>
<Button onPress={handleShareButtonPressed} title={loc.receive.details_share} />
</View>
</>
)}
</SafeArea>
);
};