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

[IOAPPFD0-192] Fix rendering issues of NumberPad and CodeInput #149

Merged
merged 3 commits into from
Nov 27, 2023
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
76 changes: 38 additions & 38 deletions example/src/pages/NumberPad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import {
IOStyles,
VSpacer,
NumberPad,
H3,
CodeInput,
ListItemSwitch,
IOColors
IOColors,
LabelSmallAlt
} from "@pagopa/io-app-design-system";
import { useNavigation } from "@react-navigation/native";
import { Screen } from "../components/Screen";

const PIN_LENGTH = 6;
/**
Expand Down Expand Up @@ -43,45 +42,46 @@ export const NumberPadScreen = () => {
}, [blueBackground, navigation]);
return (
<View
style={[
IOStyles.flex,
{ paddingVertical: IOVisualCostants.appMarginDefault },
{
backgroundColor: blueBackground
? IOColors["blueIO-500"]
: IOColors.white
}
]}
style={{
flexGrow: 1,
paddingVertical: IOVisualCostants.appMarginDefault,
backgroundColor: blueBackground
? IOColors["blueIO-500"]
: IOColors.white
}}
>
<Screen>
<ListItemSwitch
label="Attiva sfondo blu"
value={blueBackground}
onSwitchValueChange={() => setBlueBackground(v => !v)}
/>
<ListItemSwitch
label="Attiva sfondo blu"
value={blueBackground}
onSwitchValueChange={() => setBlueBackground(v => !v)}
/>
<View style={IOStyles.alignCenter}>
<H1>NumberPad + Code Input</H1>
<H5>{"Value Typed on the NumberPad component"}</H5>
<VSpacer />
<H3 color={blueBackground ? "white" : "black"}>{value}</H3>
<VSpacer />
<CodeInput
value={value}
length={PIN_LENGTH}
variant={blueBackground ? "light" : "dark"}
onValueChange={onValueChange}
onValidate={v => v === "123456"}
/>
<VSpacer size={48} />
<NumberPad
value={value}
deleteAccessibilityLabel="Delete"
onValueChange={onValueChange}
variant={blueBackground ? "dark" : "light"}
biometricType="FACE_ID"
biometricAccessibilityLabel="Face ID"
onBiometricPress={() => Alert.alert("biometric")}
/>
</Screen>

<LabelSmallAlt color={blueBackground ? "white" : "black"}>
{value}
</LabelSmallAlt>
</View>
<VSpacer />
<CodeInput
value={value}
length={PIN_LENGTH}
variant={blueBackground ? "light" : "dark"}
onValueChange={onValueChange}
onValidate={v => v === "123456"}
/>
<VSpacer size={48} />
<NumberPad
value={value}
deleteAccessibilityLabel="Delete"
onValueChange={onValueChange}
variant={blueBackground ? "dark" : "light"}
biometricType="FACE_ID"
biometricAccessibilityLabel="Face ID"
onBiometricPress={() => Alert.alert("biometric")}
/>
</View>
);
};
19 changes: 16 additions & 3 deletions src/components/codeInput/CodeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Animated, {
} from "react-native-reanimated";
import { IOColors, IOStyles } from "../../core";
import { triggerHaptic } from "../../functions";
import { HSpacer } from "../spacer";

type CodeInputProps = {
value: string;
Expand All @@ -30,7 +31,9 @@ const styles = StyleSheet.create({
dotEmpty: {
borderColor: IOColors["grey-200"]
},
wrapper: { justifyContent: "center", gap: DOT_SIZE }
wrapper: {
justifyContent: "center"
}
});

const EmptyDot = () => <View style={[styles.dotShape, styles.dotEmpty]} />;
Expand Down Expand Up @@ -111,9 +114,19 @@ export const CodeInput = ({

return (
<Animated.View style={[IOStyles.row, styles.wrapper, animatedStyle]}>
{[...Array(length)].map((_, i) => (
{[...Array(length)].map((_, i, arr) => (
<React.Fragment key={i}>
{value[i] ? <FilletDot color={fillColor} /> : <EmptyDot />}
{value[i] ? (
<>
<FilletDot color={fillColor} />
{i !== arr.length - 1 && <HSpacer size={DOT_SIZE} />}
</>
) : (
<>
<EmptyDot />
{i !== arr.length - 1 && <HSpacer size={DOT_SIZE} />}
</>
)}
</React.Fragment>
))}
</Animated.View>
Expand Down
23 changes: 2 additions & 21 deletions src/components/numberpad/NumberButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
IOColors,
IONumberPadButtonStyles,
IOScaleValues,
IOSpringValues,
useIOExperimentalDesign
IOSpringValues
} from "../../core";
import { H3 } from "../typography";

Expand Down Expand Up @@ -45,30 +44,12 @@ const colorMap: Record<NumberButtonVariantType, ColorMapVariant> = {
}
};

const legacyColorMap: Record<NumberButtonVariantType, ColorMapVariant> = {
light: {
background: "grey-50",
pressed: "grey-200",
foreground: "blue"
},
dark: {
background: "blue",
pressed: "blue-600",
foreground: "white"
}
};

export const NumberButton = ({
number,
variant,
onPress
}: NumberButtonProps) => {
const { isExperimental } = useIOExperimentalDesign();

const colors = useMemo(
() => (isExperimental ? colorMap[variant] : legacyColorMap[variant]),
[variant, isExperimental]
);
const colors = useMemo(() => colorMap[variant], [variant]);
const isPressed = useSharedValue(0);
// Scaling transformation applied when the button is pressed
const animationScaleValue = IOScaleValues?.basicButton?.pressedState;
Expand Down
7 changes: 5 additions & 2 deletions src/components/numberpad/NumberPad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ export const NumberPad = ({
}) => (
<View
style={[
IOStyles.flex,
IOStyles.rowSpaceBetween,
{ justifyContent: "space-between", alignItems: "center" }
{
justifyContent: "space-between",
alignItems: "center",
flexGrow: 1
}
]}
>
{buttons.map(elem => {
Expand Down
6 changes: 4 additions & 2 deletions src/core/IOSpacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export const IOSpacer: ReadonlyArray<IOSpacer> = [
] as const;

// Margin values used in the new `<ContentWrapper>` component
export type IOAppMargin = Extract<IOSpacingScale, 8 | 16 | 24 | 32>;
export const IOAppMargin: ReadonlyArray<IOAppMargin> = [8, 16, 24, 32] as const;
export type IOAppMargin = Extract<IOSpacingScale, 8 | 16 | 24 | 32 | 48>;
export const IOAppMargin: ReadonlyArray<IOAppMargin> = [
8, 16, 24, 32, 48
] as const;

// Values used in the `<Alert>` component
export type IOAlertSpacing = Extract<IOSpacingScale, 16 | 24>;
Expand Down