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

[IOAPPX-419] Adjust the size of Icon, Pictogram and some components based on the value of fontScale #348

Merged
merged 41 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
48add63
Add granular support for `allowFontScaling` in all the typographic st…
dmnplb Nov 4, 2024
93cda17
Make `Tag` and `Badge` dynamic
dmnplb Nov 5, 2024
8ee6ee2
Add dynamic size to checkbox components
dmnplb Nov 5, 2024
47c681c
Make part of the selection components completely dynamic
dmnplb Nov 5, 2024
83f4ad9
Add dynamic space margin to `ListItemSwitch`
dmnplb Nov 6, 2024
cd29611
Add dynamic margin to `ListItemNav` and `ListItemNavAlert`
dmnplb Nov 6, 2024
46fcce9
Add dynamic spacing to `ListItem…` components
dmnplb Nov 6, 2024
d8af4b5
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 6, 2024
800ad82
Update `jest` snapshots
dmnplb Nov 6, 2024
5877813
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 7, 2024
4597ef8
Add dynamic scale spacing to `Alert`
dmnplb Nov 7, 2024
2297375
Add dynamic space scaling to `FeatureInfo` and `Pictogram`
dmnplb Nov 7, 2024
173c849
Update `reanimated` to `3.15.0`
dmnplb Nov 8, 2024
329bf92
Add `allowFontScaling` optional prop to `Badge` and `Tag`
dmnplb Nov 8, 2024
59130cf
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 8, 2024
3bcab32
Update `jest` snapshot
dmnplb Nov 8, 2024
af31809
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 8, 2024
97921e9
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 11, 2024
28c332b
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 12, 2024
c662dea
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 20, 2024
40bdbf7
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 21, 2024
1e1b8c3
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 21, 2024
ac50c1d
Improve code after code review suggestion
dmnplb Nov 21, 2024
312a614
Improve code of `CheckboxLabel`
dmnplb Nov 21, 2024
1356455
Fix `tsc` error
dmnplb Nov 21, 2024
1428067
Add `fontScale` to `AndroidManifest` in the example app
dmnplb Nov 25, 2024
6a96bae
Increase value of the `maxFontSizeMultiplier`
dmnplb Nov 26, 2024
b25b641
Hide decorative icon when the text size is huge
dmnplb Nov 26, 2024
54dbacf
Update `jest` snapshots
dmnplb Nov 26, 2024
4655443
Enable scaled `Icon` in `IconButton` and `IconButtonSolid`
dmnplb Nov 26, 2024
001bd68
Enable scaled `Icon` in the `ButtonSolid`
dmnplb Nov 26, 2024
4566567
Update `jest` snapshot
dmnplb Nov 26, 2024
d69ca41
Remove unused import
dmnplb Nov 26, 2024
f2fdd10
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Nov 27, 2024
b7d3ad4
Enable scaled icon in the `ButtonLink` and `ButtonOutline`
dmnplb Nov 27, 2024
c832ed4
Add scaled margins in the `Header…` components
dmnplb Nov 27, 2024
62e7f25
Update `jest` snapshot
dmnplb Nov 27, 2024
0d58e5b
Enable scaled chevron in the `ListItem…` components
dmnplb Nov 29, 2024
d1f76c3
Merge branch 'main' into IOAPPX-419-dynamic-size-based-on-dynamic-type
dmnplb Dec 2, 2024
3912dee
Update `MainActivity.java` to prevent app crash in the example app
dmnplb Dec 5, 2024
26af72a
Align branch to `main`
dmnplb Dec 16, 2024
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
7 changes: 7 additions & 0 deletions example/src/pages/Badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,12 @@ const renderTag = () => (
<Tag text={"Looooooooong string"} variant="error" />
</View>
</ComponentViewerBox>
<ComponentViewerBox name={"Tag, font scaling not allowed"}>
<Tag
text={"Entro il 30 mag"}
variant="warning"
allowFontScaling={false}
/>
</ComponentViewerBox>
</View>
);
8 changes: 6 additions & 2 deletions jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jest.mock("react-native-reanimated", () => {
// The mock misses the `addWhitelistedUIProps` implementation
// So we override it with a no-op
// eslint-disable-next-line functional/immutable-data,@typescript-eslint/no-empty-function
Reanimated.default.addWhitelistedUIProps = () => {};
Reanimated.default.addWhitelistedUIProps = () => { };

return Reanimated;
});
Expand All @@ -46,5 +46,9 @@ global.AbortController = AbortController;
global.__reanimatedWorkletInit = jest.fn();

jest.mock("./src/utils/accessibility", () => ({
useBoldTextEnabled: () => false
useBoldTextEnabled: () => false,
useIOFontDynamicScale: () => ({
dynamicFontScale: 1,
spacingScaleMultiplier: 1
})
}));
100 changes: 41 additions & 59 deletions src/components/alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import {
ColorValue,
GestureResponderEvent,
NativeSyntheticEvent,
PixelRatio,
Pressable,
StyleSheet,
TextLayoutEventData,
View
} from "react-native";
Expand All @@ -22,33 +20,18 @@ import { IOVisualCostants, useIOThemeContext } from "../../core";
import { IOScaleValues, IOSpringValues } from "../../core/IOAnimations";
import { IOColors, hexToRgba } from "../../core/IOColors";
import { IOAlertRadius } from "../../core/IOShapes";
import { IOAlertSpacing } from "../../core/IOSpacing";
import { IOAlertSpacing, IOSpacer } from "../../core/IOSpacing";
import { useIOFontDynamicScale } from "../../utils/accessibility";
import { WithTestID } from "../../utils/types";
import { IOIconSizeScale, IOIcons, Icon } from "../icons";
import { VSpacer } from "../spacer";
import { HStack, VStack } from "../stack";
import { Body, ButtonText } from "../typography";
import { H4 } from "../typography/H4";

const iconSize: IOIconSizeScale = 24;
LeleDallas marked this conversation as resolved.
Show resolved Hide resolved

const [spacingDefault, spacingFullWidth] = IOAlertSpacing;
LeleDallas marked this conversation as resolved.
Show resolved Hide resolved

const styles = StyleSheet.create({
container: {
flexDirection: "row",
alignItems: "flex-start",
alignContent: "center"
},
spacingDefault: {
padding: spacingDefault,
borderRadius: IOAlertRadius,
borderCurve: "continuous"
},
spacingFullWidth: {
padding: spacingFullWidth
}
});

type AlertProps = WithTestID<{
variant: "error" | "warning" | "info" | "success";
title?: string;
Expand Down Expand Up @@ -148,6 +131,8 @@ export const Alert = React.forwardRef<View, AlertType>(
): JSX.Element => {
const { themeType } = useIOThemeContext();
const isPressed: SharedValue<number> = useSharedValue(0);
const { dynamicFontScale, spacingScaleMultiplier } =
useIOFontDynamicScale();

const [isMultiline, setIsMultiline] = useState(false);

Expand All @@ -158,6 +143,12 @@ export const Alert = React.forwardRef<View, AlertType>(
[]
);

const spacingDefaultVariant = {
padding: spacingDefault,
borderRadius: IOAlertRadius * dynamicFontScale * spacingScaleMultiplier,
borderCurve: "continuous"
};

// Scaling transformation applied when the button is pressed
const animationScaleValue = IOScaleValues?.magnifiedButton?.pressedState;

Expand Down Expand Up @@ -196,67 +187,59 @@ export const Alert = React.forwardRef<View, AlertType>(
: mapVariantStatesDarkMode;

const renderMainBlock = () => (
<>
<View
style={{
marginRight: IOVisualCostants.iconMargin,
alignSelf: "flex-start"
}}
>
<Icon
name={mapVariantStates[variant].icon}
size={iconSize}
color={mapVariantStates[variant].foreground}
/>
</View>
<HStack
space={IOVisualCostants.iconMargin as IOSpacer}
allowScaleSpacing
style={{ alignItems: isMultiline ? "flex-start" : "center" }}
>
<Icon
allowFontScaling
name={mapVariantStates[variant].icon}
size={iconSize}
color={mapVariantStates[variant].foreground}
/>
{/* Sadly we don't have specific alignments style for text
in React Native, like `text-box-trim` for CSS. So we
have to put these magic numbers after manual adjustments.
Tested on both Android and iOS. */}
<View
style={[
!title &&
isMultiline && { marginTop: -5 * PixelRatio.getFontScale() },
isMultiline && { marginBottom: -3 * PixelRatio.getFontScale() },
!title && isMultiline && { marginTop: -6 * dynamicFontScale },
isMultiline && { marginBottom: -4 * dynamicFontScale },
{ flex: 1 }
]}
>
{title && (
<>
<VStack space={8} allowScaleSpacing>
{title && (
<H4 color={mapVariantStates[variant].foreground}>{title}</H4>
<VSpacer size={8} />
</>
)}
<Body
color={mapVariantStates[variant].foreground}
weight={"Regular"}
accessibilityRole="text"
onTextLayout={onTextLayout}
>
{content}
</Body>
{action && (
<>
<VSpacer size={8} />
)}
<Body
color={mapVariantStates[variant].foreground}
weight={"Regular"}
accessibilityRole="text"
onTextLayout={onTextLayout}
>
{content}
</Body>
{action && (
<ButtonText
color={mapVariantStates[variant].foreground}
numberOfLines={1}
ellipsizeMode="tail"
>
{action}
</ButtonText>
</>
)}
)}
</VStack>
</View>
</>
</HStack>
);

const StaticComponent = () => (
<View
ref={viewRef}
style={[
styles.container,
fullWidth ? styles.spacingFullWidth : styles.spacingDefault,
fullWidth ? { padding: spacingFullWidth } : spacingDefaultVariant,
{ backgroundColor: mapVariantStates[variant].background }
]}
testID={testID}
Expand All @@ -283,8 +266,7 @@ export const Alert = React.forwardRef<View, AlertType>(
>
<Animated.View
style={[
styles.container,
fullWidth ? styles.spacingFullWidth : styles.spacingDefault,
fullWidth ? { padding: spacingFullWidth } : spacingDefaultVariant,
{ backgroundColor: mapVariantStates[variant].background },
// Disable pressed animation when component is full width
!fullWidth && pressedAnimationStyle
Expand Down
33 changes: 29 additions & 4 deletions src/components/badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from "react";
import { ColorValue, Platform, StyleSheet, View } from "react-native";
import {
ColorValue,
Platform,
StyleSheet,
View,
ViewStyle
} from "react-native";
import {
hexToRgba,
IOBadgeHSpacing,
Expand All @@ -10,12 +16,14 @@ import {
useIOTheme,
useIOThemeContext
} from "../../core";
import { useIOFontDynamicScale } from "../../utils/accessibility";
import { WithTestID } from "../../utils/types";
import { IOText } from "../typography";

export type Badge = WithTestID<{
outline?: boolean;
text: string;
allowFontScaling?: boolean;
variant:
| "default"
| "info"
Expand Down Expand Up @@ -44,12 +52,14 @@ const styles = StyleSheet.create({
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
borderCurve: "continuous",
...Platform.select({
android: {
textAlignVertical: "center"
}
}),
borderCurve: "continuous",
})
},
badgeStaticStyle: {
borderRadius: IOBadgeRadius,
paddingHorizontal: IOBadgeHSpacing,
paddingVertical: IOBadgeVSpacing
Expand All @@ -59,9 +69,16 @@ const styles = StyleSheet.create({
/**
* Official badge component
*/
export const Badge = ({ text, outline = false, variant, testID }: Badge) => {
export const Badge = ({
text,
outline = false,
allowFontScaling = true,
variant,
testID
}: Badge) => {
const { isExperimental } = useIOExperimentalDesign();
const theme = useIOTheme();
const { dynamicFontScale } = useIOFontDynamicScale();
const { themeType } = useIOThemeContext();

const bgOpacityDarkMode = 0.2;
Expand Down Expand Up @@ -237,12 +254,19 @@ export const Badge = ({ text, outline = false, variant, testID }: Badge) => {

const { background, foreground } = variantMap[variant];

const dynamicStyle: ViewStyle = {
borderRadius: IOBadgeRadius * dynamicFontScale,
paddingHorizontal: IOBadgeHSpacing * dynamicFontScale,
paddingVertical: IOBadgeVSpacing * dynamicFontScale
};

return (
<View
accessible={true}
testID={testID}
style={[
styles.badge,
allowFontScaling ? dynamicStyle : styles.badgeStaticStyle,
outline
? {
borderWidth: 1,
Expand All @@ -254,6 +278,7 @@ export const Badge = ({ text, outline = false, variant, testID }: Badge) => {
]}
>
<IOText
allowFontScaling={allowFontScaling}
font={isExperimental ? "Titillio" : "TitilliumSansPro"}
weight={"Semibold"}
size={12}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ exports[`Test Badge Components - Experimental Enabled Badge Snapshot 1`] = `
{
"alignItems": "center",
"borderCurve": "continuous",
"borderRadius": 24,
"flexDirection": "row",
"justifyContent": "center",
},
{
"borderRadius": 24,
"paddingHorizontal": 8,
"paddingVertical": 4,
},
Expand Down Expand Up @@ -58,9 +60,11 @@ exports[`Test Badge Components Badge Snapshot 1`] = `
{
"alignItems": "center",
"borderCurve": "continuous",
"borderRadius": 24,
"flexDirection": "row",
"justifyContent": "center",
},
{
"borderRadius": 24,
"paddingHorizontal": 8,
"paddingVertical": 4,
},
Expand All @@ -71,7 +75,7 @@ exports[`Test Badge Components Badge Snapshot 1`] = `
}
>
<Text
allowFontScaling={false}
allowFontScaling={true}
ellipsizeMode="tail"
maxFontSizeMultiplier={1.25}
numberOfLines={1}
Expand Down
6 changes: 2 additions & 4 deletions src/components/banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ export const Banner = ({
>
{title && (
<>
{/* Once we get 'gap' property, we can get rid of
these <VSpacer> components */}
<H6 color={colorTitle}>{title}</H6>
<VSpacer size={4} />
</>
Expand All @@ -249,7 +247,7 @@ export const Banner = ({
)}
{action && (
/* Disable pointer events to avoid
pressed state on the button */
pressed state on the button */
<View
pointerEvents="none"
accessibilityElementsHidden
Expand All @@ -258,7 +256,7 @@ export const Banner = ({
<VSpacer size={4} />
<IOText
font={isExperimental ? "Titillio" : "TitilliumSansPro"}
weight={isExperimental ? "Regular" : "Bold"}
weight={"Semibold"}
color={colorMainButton}
size={buttonTextFontSize}
numberOfLines={1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ exports[`Test Banner Components - Experimental Enabled Banner Snapshot 1`] = `
"fontFamily": "Titillio",
"fontSize": 16,
"fontStyle": "normal",
"fontWeight": "400",
"fontWeight": "600",
"lineHeight": undefined,
},
]
Expand Down Expand Up @@ -397,7 +397,7 @@ exports[`Test Banner Components Banner Snapshot 1`] = `
"fontFamily": "Titillium Sans Pro",
"fontSize": 16,
"fontStyle": "normal",
"fontWeight": "700",
"fontWeight": "600",
"lineHeight": undefined,
},
]
Expand Down
Loading
Loading