Skip to content

Commit

Permalink
reafactor: Continue to simplify layout logic and shared values (#1307)
Browse files Browse the repository at this point in the history
  • Loading branch information
NigelBreslaw authored Apr 17, 2024
1 parent cef6559 commit e7d59c9
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 103 deletions.
36 changes: 11 additions & 25 deletions native/app/inventory/ArtifactCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ const styles = StyleSheet.create({
justifyContent: "center",
alignItems: "center",
},
gesture: {
width: ITEM_SIZE,
height: ITEM_SIZE,
position: "absolute",
},
primaryStat: {
paddingLeft: 2,
paddingRight: 2,
Expand Down Expand Up @@ -61,12 +56,6 @@ const styles = StyleSheet.create({
left: -0.5,
pointerEvents: "none",
},
innerFrameOverlaySize: {
width: 65,
height: 65,
position: "absolute",
pointerEvents: "none",
},
});

type DestinyCellProps = {
Expand All @@ -85,22 +74,19 @@ const DestinyCell = (props: DestinyCellProps) => {
return (
<View style={styles.container}>
<TouchableOpacity onPress={handlePress}>
<View style={styles.frameSize}>
<View style={styles.icon}>
<View style={styles.innerFrameSize}>
<Image
source={{ uri: props.data.icon }}
cachePolicy="memory-disk"
style={styles.innerFrameSize}
recyclingKey={props.data.icon}
/>
</View>
</View>

<View style={styles.primaryStat}>
<Text style={styles.primaryStatText}>{`+${props.data.primaryStat}`}</Text>
<View style={styles.icon}>
<View style={styles.innerFrameSize}>
<Image
source={{ uri: props.data.icon }}
cachePolicy="memory-disk"
style={styles.innerFrameSize}
recyclingKey={props.data.icon}
/>
</View>
</View>
<View style={styles.primaryStat}>
<Text style={styles.primaryStatText}>{`+${props.data.primaryStat}`}</Text>
</View>
</TouchableOpacity>
</View>
);
Expand Down
1 change: 1 addition & 0 deletions native/app/inventory/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export type DestinyItemIdentifier = {

export const ITEM_SIZE = 90;
export const ICON_SIZE = 72;
export const INNER_FRAME_SIZE = Math.ceil(ICON_SIZE * 0.95);
export const ICON_MARGIN = (ITEM_SIZE - ICON_SIZE) / 2;
export const DEFAULT_MARGIN = 6;
export const VISUAL_MARGIN = DEFAULT_MARGIN + ICON_MARGIN;
Expand Down
96 changes: 50 additions & 46 deletions native/app/inventory/DestinyCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { CRAFTED_OVERLAY, ITEM_SIZE, type DestinyIconData } from "@/app/inventory/Common.ts";
import {
CRAFTED_OVERLAY,
ICON_SIZE,
INNER_FRAME_SIZE,
ITEM_SIZE,
type DestinyIconData,
} from "@/app/inventory/Common.ts";
import { useGGStore } from "@/app/store/GGStore.ts";
import { Image } from "expo-image";
import React, { useCallback } from "react";
Expand Down Expand Up @@ -66,7 +72,7 @@ const styles = StyleSheet.create({
backgroundColor: DEFAULT_OVERLAP_COLOR,
zIndex: 100,
position: "absolute",
bottom: -6,
bottom: -7,
right: -8,
justifyContent: "center",
alignItems: "center",
Expand All @@ -80,34 +86,34 @@ const styles = StyleSheet.create({
pointerEvents: "none",
},
icon: {
width: 72,
height: 72,
width: ICON_SIZE,
height: ICON_SIZE,
borderRadius: 12,
overflow: "hidden",
borderWidth: 2,
pointerEvents: "none",
},
frameSize: {
width: 72,
height: 72,
width: ICON_SIZE,
height: ICON_SIZE,
},
innerFrameSize: {
width: 69,
height: 69,
width: INNER_FRAME_SIZE,
height: INNER_FRAME_SIZE,
position: "absolute",
top: -0.5,
left: -0.5,
pointerEvents: "none",
},
innerFrameOverlaySize: {
width: 69,
height: 69,
width: INNER_FRAME_SIZE,
height: INNER_FRAME_SIZE,
position: "absolute",
pointerEvents: "none",
},
crafted: {
width: 69,
height: 69,
width: INNER_FRAME_SIZE,
height: INNER_FRAME_SIZE,
position: "absolute",
pointerEvents: "none",
},
Expand Down Expand Up @@ -145,44 +151,42 @@ const DestinyCell = (props: DestinyCellProps) => {
return (
<View style={styles.container}>
<TouchableOpacity onPress={handlePress}>
<View style={styles.frameSize}>
<View style={[styles.icon, { borderColor: props.data.borderColor }]}>
<View style={styles.innerFrameSize}>
<Image
source={{ uri: props.data.icon }}
cachePolicy="memory-disk"
style={styles.innerFrameSize}
recyclingKey={props.data.icon}
/>
<View style={[styles.icon, { borderColor: props.data.borderColor }]}>
<View style={styles.innerFrameSize}>
<Image
source={{ uri: props.data.icon }}
cachePolicy="memory-disk"
style={styles.innerFrameSize}
recyclingKey={props.data.icon}
/>

<Image
source={{ uri: props.data.calculatedWaterMark }}
cachePolicy="memory-disk"
style={styles.innerFrameOverlaySize}
recyclingKey={props.data.calculatedWaterMark}
/>
<Image
source={{ uri: props.data.calculatedWaterMark }}
cachePolicy="memory-disk"
style={styles.innerFrameOverlaySize}
recyclingKey={props.data.calculatedWaterMark}
/>

{props.data.crafted && <Image source={CRAFTED_OVERLAY} cachePolicy="memory" style={styles.crafted} />}
</View>
{props.data.crafted && <Image source={CRAFTED_OVERLAY} cachePolicy="memory" style={styles.crafted} />}
</View>
{props.data.primaryStat > 0 && (
<View style={styles.primaryStat}>
<Text style={styles.primaryStatText}>{props.data.primaryStat}</Text>
</View>
)}
{props.data.damageTypeIconUri && (
<View style={styles.miniIconBurn}>
<Image style={styles.miniIconBurnSize} source={props.data.damageTypeIconUri} cachePolicy="memory" />
</View>
)}
{props.data.quantity > 1 && (
<View style={props.data.stackSizeMaxed ? styles.quantityMaxed : styles.quantity}>
<Text style={props.data.stackSizeMaxed ? styles.quantityLevelTextMaxed : styles.quantityLevelText}>
{props.data.quantity}
</Text>
</View>
)}
</View>
{props.data.primaryStat > 0 && (
<View style={styles.primaryStat}>
<Text style={styles.primaryStatText}>{props.data.primaryStat}</Text>
</View>
)}
{props.data.damageTypeIconUri && (
<View style={styles.miniIconBurn}>
<Image style={styles.miniIconBurnSize} source={props.data.damageTypeIconUri} cachePolicy="memory" />
</View>
)}
{props.data.quantity > 1 && (
<View style={props.data.stackSizeMaxed ? styles.quantityMaxed : styles.quantity}>
<Text style={props.data.stackSizeMaxed ? styles.quantityLevelTextMaxed : styles.quantityLevelText}>
{props.data.quantity}
</Text>
</View>
)}
</TouchableOpacity>
</View>
);
Expand Down
38 changes: 23 additions & 15 deletions native/app/inventory/EmptyCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ITEM_SIZE } from "@/app/inventory/Common.ts";
import { ICON_SIZE, ITEM_SIZE } from "@/app/inventory/Common.ts";
import React from "react";
import { StyleSheet, View } from "react-native";

Expand All @@ -8,9 +8,15 @@ const BORDER_SIZE = 15;
const BORDER_WIDTH = 1;

const styles = StyleSheet.create({
square: {
box: {
width: ITEM_SIZE,
height: ITEM_SIZE,
justifyContent: "center",
alignItems: "center",
},
square: {
width: ICON_SIZE,
height: ICON_SIZE,
position: "relative",
},
corner: {
Expand All @@ -20,29 +26,29 @@ const styles = StyleSheet.create({
borderColor: BORDER_COLOR,
},
topLeft: {
top: 11,
left: 11,
top: 0,
left: 0,
borderTopWidth: BORDER_WIDTH,
borderLeftWidth: BORDER_WIDTH,
borderTopLeftRadius: BORDER_RADIUS,
},
topRight: {
top: 11,
right: 11,
top: 0,
right: 0,
borderTopWidth: BORDER_WIDTH,
borderRightWidth: BORDER_WIDTH,
borderTopRightRadius: BORDER_RADIUS,
},
bottomLeft: {
bottom: 11,
left: 11,
bottom: 0,
left: 0,
borderBottomWidth: BORDER_WIDTH,
borderLeftWidth: BORDER_WIDTH,
borderBottomLeftRadius: BORDER_RADIUS,
},
bottomRight: {
bottom: 11,
right: 11,
bottom: 0,
right: 0,
borderBottomWidth: BORDER_WIDTH,
borderRightWidth: BORDER_WIDTH,
borderBottomRightRadius: BORDER_RADIUS,
Expand All @@ -56,11 +62,13 @@ const bottomRight = StyleSheet.flatten([styles.bottomRight, styles.corner]);

function EmptyCell() {
return (
<View style={styles.square}>
<View style={topLeft} />
<View style={topRight} />
<View style={bottomLeft} />
<View style={bottomRight} />
<View style={styles.box}>
<View style={styles.square}>
<View style={topLeft} />
<View style={topRight} />
<View style={bottomLeft} />
<View style={bottomRight} />
</View>
</View>
);
}
Expand Down
10 changes: 5 additions & 5 deletions native/app/inventory/EngramCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EMPTY_ENGRAM, ITEM_SIZE, type DestinyIconData } from "@/app/inventory/Common.ts";
import { EMPTY_ENGRAM, ICON_SIZE, INNER_FRAME_SIZE, type DestinyIconData } from "@/app/inventory/Common.ts";
import { useGGStore } from "@/app/store/GGStore.ts";
import { Image } from "expo-image";
import React, { useCallback } from "react";
Expand All @@ -8,8 +8,8 @@ const DEFAULT_BORDER_COLOR = "#303036";

const styles = StyleSheet.create({
container: {
width: ITEM_SIZE,
height: ITEM_SIZE,
width: ICON_SIZE,
height: ICON_SIZE,
justifyContent: "center",
alignItems: "center",
},
Expand All @@ -22,8 +22,8 @@ const styles = StyleSheet.create({
pointerEvents: "none",
},
frameSize: {
width: 68,
height: 68,
width: INNER_FRAME_SIZE,
height: INNER_FRAME_SIZE,
},
primaryStat: {
width: 36,
Expand Down
15 changes: 4 additions & 11 deletions native/app/inventory/EngramsUI.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
DEFAULT_MARGIN,
DestinyIconDataEmpty,
ENGRAMS_SECTION_SIZE,
ITEM_SIZE,
Expand All @@ -24,6 +23,8 @@ const styles = StyleSheet.create({
box: {
width: "20%",
height: ITEM_SIZE * 0.9,
justifyContent: "center",
alignItems: "center",
},
});

Expand All @@ -36,7 +37,7 @@ function EngramsUI(props: EngramsProps) {
const rootStyle = {
width: inventorySectionWidth,
height: ENGRAMS_SECTION_SIZE,
paddingLeft: DEFAULT_MARGIN,
paddingLeft: VISUAL_MARGIN,
paddingRight: VISUAL_MARGIN,
};

Expand All @@ -45,18 +46,10 @@ function EngramsUI(props: EngramsProps) {
<View style={styles.container}>
{array10.map((_v, index) => {
const item = props.data[index];
if (item) {
return (
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
<View key={index} style={styles.box}>
<EngramCell data={item} />
</View>
);
}
return (
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
<View key={index} style={styles.box}>
<EngramCell data={DestinyIconDataEmpty} />
<EngramCell data={item ?? DestinyIconDataEmpty} />
</View>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion native/app/inventory/SeparatorUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const styles = StyleSheet.create({
bar: {
width: "auto",
height: 1,
backgroundColor: "#D1D1D1",
backgroundColor: "#818181",
},
label: {
color: "#D1D1D1",
Expand Down

0 comments on commit e7d59c9

Please sign in to comment.