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-426] Adjust SearchInput and TextInputBase spacing based on the fontScale value #356

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 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
b24458d
Merge branch 'IOAPPX-419-dynamic-size-based-on-dynamic-type' into IOA…
dmnplb Nov 13, 2024
822c843
Adjust `SearchInput` and `TextInputBase` spacing based on the `fontSc…
dmnplb Nov 13, 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
18 changes: 18 additions & 0 deletions example/src/pages/Badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ const renderBadge = () => (
<Badge text={"Contrast"} variant="contrast" />
</View>
</View>
<VSpacer size={16} />
<ComponentViewerBox name={"Badge, font scaling not allowed"}>
<View style={IOStyles.row}>
<Badge
allowFontScaling={false}
outline
text={"Purple"}
variant="purple"
/>
</View>
</ComponentViewerBox>
</>
);

Expand Down Expand Up @@ -139,5 +150,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
})
}));
93 changes: 41 additions & 52 deletions src/components/alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useCallback, useState } from "react";
import {
GestureResponderEvent,
NativeSyntheticEvent,
PixelRatio,
Pressable,
StyleSheet,
TextLayoutEventData,
Expand All @@ -25,10 +24,11 @@ import {
IOColorsStatusForeground
} 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 { ButtonText } from "../typography";
import { H4 } from "../typography/H4";
import { Label } from "../typography/Label";
Expand All @@ -38,16 +38,6 @@ const iconSize: IOIconSizeScale = 24;
const [spacingDefault, spacingFullWidth] = IOAlertSpacing;

const styles = StyleSheet.create({
container: {
flexDirection: "row",
alignItems: "flex-start",
alignContent: "center"
},
spacingDefault: {
padding: spacingDefault,
borderRadius: IOAlertRadius,
borderCurve: "continuous"
},
spacingFullWidth: {
padding: spacingFullWidth
}
Expand Down Expand Up @@ -123,6 +113,8 @@ export const Alert = React.forwardRef<View, AlertType>(
viewRef
): JSX.Element => {
const isPressed: SharedValue<number> = useSharedValue(0);
const { dynamicFontScale, spacingScaleMultiplier } =
useIOFontDynamicScale();

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

Expand All @@ -133,6 +125,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 @@ -166,67 +164,59 @@ export const Alert = React.forwardRef<View, AlertType>(
}, [isPressed]);

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} />
</>
)}
<Label
color={mapVariantStates[variant].foreground}
weight={"Regular"}
accessibilityRole="text"
onTextLayout={onTextLayout}
>
{content}
</Label>
{action && (
<>
<VSpacer size={8} />
)}
<Label
color={mapVariantStates[variant].foreground}
weight={"Regular"}
accessibilityRole="text"
onTextLayout={onTextLayout}
>
{content}
</Label>
{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 ? styles.spacingFullWidth : spacingDefaultVariant,
{ backgroundColor: IOColors[mapVariantStates[variant].background] }
]}
testID={testID}
Expand All @@ -253,8 +243,7 @@ export const Alert = React.forwardRef<View, AlertType>(
>
<Animated.View
style={[
styles.container,
fullWidth ? styles.spacingFullWidth : styles.spacingDefault,
fullWidth ? styles.spacingFullWidth : spacingDefaultVariant,
{ backgroundColor: IOColors[mapVariantStates[variant].background] },
// Disable pressed animation when component is full width
!fullWidth && pressedAnimationStyle
Expand Down
27 changes: 23 additions & 4 deletions src/components/badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Platform, StyleSheet, View } from "react-native";
import { Platform, StyleSheet, View, ViewStyle } from "react-native";
import {
IOBadgeHSpacing,
IOBadgeRadius,
Expand All @@ -8,12 +8,14 @@ import {
useIOExperimentalDesign,
useIOTheme
} 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 @@ -42,12 +44,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 @@ -57,9 +61,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 mapVariants: Record<
NonNullable<Badge["variant"]>,
Expand Down Expand Up @@ -147,12 +158,19 @@ export const Badge = ({ text, outline = false, variant, testID }: Badge) => {
outline ? mapOutlineVariants : mapVariants
)[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 @@ -164,6 +182,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
Loading
Loading