Skip to content

Commit

Permalink
feat: added min/max font scale option
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed Aug 24, 2024
1 parent 83bbc4a commit 3821bda
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/enhancer-gestures/src/SettingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export class GesturesSettingsManager extends SettingsManager<InputSettings, Outp
getDefaultSettings(): InputSettings {
return {
panNavigation: "pan",
pinchCancelPan: true,
fontScalePinchEnabled: true,
fontScalePinchThrottleTime: 500,
pinchCancelPan: true,
fontScaleMaxScale: 5,
fontScaleMinScale: 0.2,
}
}
}
9 changes: 8 additions & 1 deletion packages/enhancer-gestures/src/gestures/pinch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,15 @@ export const registerPinch = ({
trailing: true,
}),
tap((event) => {
const newScale = parseFloat((lastFontScaleOnPinchStart + (event.scale - 1)).toFixed(2))

const newMinMaxedFontScale = Math.max(
Math.min(newScale, settingsManager.values.fontScaleMaxScale),
settingsManager.values.fontScaleMinScale,
)

reader.settings.update({
fontScale: parseFloat((lastFontScaleOnPinchStart + (event.scale - 1)).toFixed(2)),
fontScale: newMinMaxedFontScale,
})
}),
takeUntil(pinchEnd$),
Expand Down
5 changes: 5 additions & 0 deletions packages/enhancer-gestures/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export type GestureEvent = ObservedValueOf<GestureRecognizable["events$"]>
export type InputSettings = {
panNavigation: "pan" | "swipe" | false
fontScalePinchEnabled: boolean
fontScaleMaxScale: number
fontScaleMinScale: number
// @todo default value
// @todo font scale max / min
// @todo cancel pan if selecting
fontScalePinchThrottleTime: number
pinchCancelPan: boolean
}
Expand Down

0 comments on commit 3821bda

Please sign in to comment.