Skip to content

Commit

Permalink
✨ add the ability to disable/enable font scaling (disabled by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
troberts-28 committed Jan 9, 2024
1 parent 8ce2b44 commit 5b82e9f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/TimerPicker/DurationScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type LimitType = {
};

interface DurationScrollProps {
allowFontScaling?: boolean;
numberOfItems: number;
label?: string | React.ReactElement;
initialValue?: number;
Expand Down Expand Up @@ -83,6 +84,7 @@ const DurationScroll = forwardRef<DurationScrollRef, DurationScrollProps>(
disableInfiniteScroll = false,
limit,
aggressivelyGetLatestDuration,
allowFontScaling = false,
is12HourPicker,
amLabel,
pmLabel,
Expand Down Expand Up @@ -166,6 +168,7 @@ const DurationScroll = forwardRef<DurationScrollRef, DurationScrollProps>(
style={styles.pickerItemContainer}
testID="picker-item">
<Text
allowFontScaling={allowFontScaling}
style={[
styles.pickerItem,
intItem > adjustedLimited.max ||
Expand All @@ -179,7 +182,9 @@ const DurationScroll = forwardRef<DurationScrollRef, DurationScrollProps>(
<View
style={styles.pickerAmPmContainer}
pointerEvents="none">
<Text style={[styles.pickerAmPmLabel]}>
<Text
style={[styles.pickerAmPmLabel]}
allowFontScaling={allowFontScaling}>
{isAm ? amLabel : pmLabel}
</Text>
</View>
Expand All @@ -190,6 +195,7 @@ const DurationScroll = forwardRef<DurationScrollRef, DurationScrollProps>(
[
adjustedLimited.max,
adjustedLimited.min,
allowFontScaling,
amLabel,
is12HourPicker,
pmLabel,
Expand Down Expand Up @@ -364,7 +370,11 @@ const DurationScroll = forwardRef<DurationScrollRef, DurationScrollProps>(
/>
<View style={styles.pickerLabelContainer} pointerEvents="none">
{typeof label === "string" ? (
<Text style={styles.pickerLabel}>{label}</Text>
<Text
allowFontScaling={allowFontScaling}
style={styles.pickerLabel}>
{label}
</Text>
) : (
label ?? null
)}
Expand Down
5 changes: 5 additions & 0 deletions src/components/TimerPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface TimerPickerRef {
}

export interface TimerPickerProps {
allowFontScaling?: boolean;
onDurationChange?: (duration: {
hours: number;
minutes: number;
Expand Down Expand Up @@ -67,6 +68,7 @@ export interface TimerPickerProps {
const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
(
{
allowFontScaling = false,
onDurationChange,
initialHours = 0,
initialMinutes = 0,
Expand Down Expand Up @@ -167,6 +169,7 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
hourLabel ?? (!use12HourPicker ? "h" : undefined)
}
initialValue={initialHours}
allowFontScaling={allowFontScaling}
aggressivelyGetLatestDuration={
aggressivelyGetLatestDuration
}
Expand Down Expand Up @@ -195,6 +198,7 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
numberOfItems={59}
label={minuteLabel ?? "m"}
initialValue={initialMinutes}
allowFontScaling={allowFontScaling}
aggressivelyGetLatestDuration={
aggressivelyGetLatestDuration
}
Expand All @@ -221,6 +225,7 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
numberOfItems={59}
label={secondLabel ?? "s"}
initialValue={initialSeconds}
allowFontScaling={allowFontScaling}
aggressivelyGetLatestDuration={
aggressivelyGetLatestDuration
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
secondLabel,
padWithNItems = 1,
disableInfiniteScroll = false,
allowFontScaling = false,
use12HourPicker,
amLabel,
pmLabel,
Expand Down Expand Up @@ -219,6 +220,7 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
secondLabel={secondLabel}
padWithNItems={padWithNItems}
disableInfiniteScroll={disableInfiniteScroll}
allowFontScaling={allowFontScaling}
use12HourPicker={use12HourPicker}
amLabel={amLabel}
pmLabel={pmLabel}
Expand Down

0 comments on commit 5b82e9f

Please sign in to comment.