Skip to content

Commit 6261fd8

Browse files
authored
fix: Adds dynamic type support for iOS (#3005)
* feat: Adds dynamic type support for iOS * fix: Replace hardcoded pixel font sizes * fix: fixes eslint error
1 parent 90ca0c2 commit 6261fd8

10 files changed

Lines changed: 52 additions & 16 deletions

File tree

packages/mobile/src/MobileWebAppContainer.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { ApplicationEvent, ReactNativeToWebEvent } from '@standardnotes/snjs'
44
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
5-
import { Button, Dimensions, Keyboard, KeyboardEvent, Platform, Text, View } from 'react-native'
5+
import { AppState, Button, Dimensions, Keyboard, KeyboardEvent, Platform, Text, View } from 'react-native'
66
import VersionInfo from 'react-native-version-info'
77
import { WebView, WebViewMessageEvent } from 'react-native-webview'
88
import { OnShouldStartLoadWithRequest, WebViewNativeConfig } from 'react-native-webview/lib/WebViewTypes'
@@ -52,6 +52,18 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
5252
const useFlexLayout = Platform.OS === 'ios' || androidVersion < 35
5353
const [webViewContainerHeight, setWebViewContainerHeight] = useState(screenHeight)
5454

55+
const applyDynamicTypeFontScale = useCallback((fontScale?: number) => {
56+
if (Platform.OS !== 'ios') {
57+
return
58+
}
59+
60+
const scale = fontScale ?? Dimensions.get('window').fontScale
61+
webViewRef.current?.injectJavaScript(`
62+
document.documentElement.style.fontSize = 'calc(1rem * ${scale})';
63+
true;
64+
`)
65+
}, [])
66+
5567
useEffect(() => {
5668
const removeStateServiceListener = stateService.addEventObserver((event: ReactNativeToWebEvent) => {
5769
webViewRef.current?.postMessage(JSON.stringify({ reactNativeEvent: event, messageType: 'event' }))
@@ -150,6 +162,27 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
150162
}
151163
}, [webViewRef, stateService, device, androidBackHandlerService, colorSchemeService, insets.bottom, screenHeight])
152164

165+
useEffect(() => {
166+
if (Platform.OS !== 'ios') {
167+
return
168+
}
169+
170+
const dimensionsListener = Dimensions.addEventListener('change', ({ window }) => {
171+
applyDynamicTypeFontScale(window.fontScale)
172+
})
173+
174+
const appStateListener = AppState.addEventListener('change', (state) => {
175+
if (state === 'active') {
176+
applyDynamicTypeFontScale()
177+
}
178+
})
179+
180+
return () => {
181+
dimensionsListener.remove()
182+
appStateListener.remove()
183+
}
184+
}, [applyDynamicTypeFontScale])
185+
153186
useEffect(() => {
154187
return notifee.onForegroundEvent(({ type, detail }) => {
155188
if (type !== EventType.ACTION_PRESS) {
@@ -305,6 +338,7 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
305338
}
306339
if (message === 'appLoaded') {
307340
setDidLoadEnd(true)
341+
applyDynamicTypeFontScale()
308342
return
309343
}
310344
try {

packages/web/src/javascripts/Components/ChangeEditor/ChangeEditorMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ const ChangeEditorMenu: FunctionComponent<ChangeEditorMenuProps> = ({
301301
{menuItem.uiFeature.featureIdentifier === NativeFeatureIdentifier.TYPES.SuperEditor &&
302302
!isSelected(menuItem) &&
303303
recommendSuper && (
304-
<Pill className="px-1.5 py-0.5 text-[9px]" style="info">
304+
<Pill className="px-1.5 py-0.5 text-[0.5625rem]" style="info">
305305
Recommended
306306
</Pill>
307307
)}

packages/web/src/javascripts/Components/Preferences/Panes/WhatsNew/WhatsNew.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ const WhatsNew = ({ application }: { application: WebApplication }) => {
8080
<div className="flex items-start">
8181
<Title className="mb-3 flex">{version.version}</Title>
8282
{version.version === appVersion && (
83-
<div className="ml-2 select-none rounded bg-info px-2 py-1 text-[10px] font-bold text-info-contrast">
83+
<div className="ml-2 select-none rounded bg-info px-2 py-1 text-[0.625rem] font-bold text-info-contrast">
8484
Your Version
8585
</div>
8686
)}
8787
{isLatest && (
88-
<div className="ml-2 select-none rounded bg-success px-2 py-1 text-[10px] font-bold text-success-contrast">
88+
<div className="ml-2 select-none rounded bg-success px-2 py-1 text-[0.625rem] font-bold text-success-contrast">
8989
Latest Version
9090
</div>
9191
)}
9292
{isUnreadVersion && (
93-
<div className="ml-2 select-none rounded bg-success px-2 py-1 text-[10px] font-bold text-success-contrast">
93+
<div className="ml-2 select-none rounded bg-success px-2 py-1 text-[0.625rem] font-bold text-success-contrast">
9494
New
9595
</div>
9696
)}

packages/web/src/javascripts/Components/Preferences/PreferencesComponents/Content.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ type PillProps = Props & {
5353
export const Pill: FunctionComponent<PillProps> = ({ children, className, style }) => {
5454
const colorClass = getColorsForPrimaryVariant(style)
5555
return (
56-
<div className={classNames('ml-2 rounded px-2 py-1 text-[10px] font-bold', className, colorClass)}>{children}</div>
56+
<div className={classNames('ml-2 rounded px-2 py-1 text-[0.625rem] font-bold', className, colorClass)}>
57+
{children}
58+
</div>
5759
)
5860
}

packages/web/src/javascripts/Components/PremiumFeaturesModal/Subviews/SuccessPrompt.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const SuccessPrompt = ({
2323
className="mx-auto mb-5 flex h-24 w-24 items-center justify-center rounded-[50%] bg-contrast"
2424
aria-hidden={true}
2525
>
26-
<Icon className={'h-24 w-24 px-7 py-2 text-[50px]'} size={'custom'} type={'🎉'} />
26+
<Icon className={'h-24 w-24 px-7 py-2 text-[3.125rem]'} size={'custom'} type={'🎉'} />
2727
</div>
2828
<div className="mb-1 text-center text-lg font-bold">Your purchase was successful!</div>
2929
</div>

packages/web/src/javascripts/Components/SuperEditor/Lexical/Theme/editor.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@
3434
}
3535
}
3636
.Lexical__h1 {
37-
font-size: 26px;
37+
font-size: 1.625rem;
3838
color: var(--sn-stylekit-editor-foreground-color);
3939
font-weight: 700;
4040
margin: 0;
4141
}
4242
.Lexical__h2 {
43-
font-size: 22px;
43+
font-size: 1.375rem;
4444
color: var(--sn-stylekit-editor-foreground-color);
4545
font-weight: 700;
4646
margin: 0;
4747
}
4848
.Lexical__h3 {
49-
font-size: 19px;
49+
font-size: 1.1875rem;
5050
font-weight: 700;
5151
margin: 0;
5252
}

packages/web/src/stylesheets/_editor.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $heading-height: 75px;
7171
}
7272

7373
#save-status {
74-
font-size: calc(var(--sn-stylekit-base-font-size) - 2px);
74+
font-size: calc(var(--sn-stylekit-base-font-size) - 0.125rem);
7575
text-transform: none;
7676
font-weight: normal;
7777

packages/web/src/stylesheets/_items-column.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
cursor: default;
9090
background-color: var(--sn-stylekit-neutral-color);
9191
color: var(--sn-stylekit-neutral-contrast-color);
92-
font-size: 10px;
92+
font-size: 0.625rem;
9393
line-height: 17px;
9494
text-align: center;
9595
position: absolute;

packages/web/src/stylesheets/_main.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ body,
160160

161161
.section-title-bar {
162162
.add-button {
163-
font-size: 12px;
163+
font-size: 0.75rem;
164164
}
165165

166166
.section-title-bar-header {

packages/web/src/stylesheets/_navigation.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $content-horizontal-padding: 16px;
2323
padding-bottom: 8px;
2424
padding-left: $content-horizontal-padding;
2525
padding-right: $content-horizontal-padding;
26-
font-size: 12px;
26+
font-size: 0.75rem;
2727
}
2828

2929
.root-drop {
@@ -54,7 +54,7 @@ $content-horizontal-padding: 16px;
5454

5555
.tag,
5656
.root-drop {
57-
font-size: 14px;
57+
font-size: 0.875rem;
5858
cursor: pointer;
5959
transition: height 0.1s ease-in-out;
6060
width: 100%;
@@ -136,7 +136,7 @@ $content-horizontal-padding: 16px;
136136

137137
.meta {
138138
> .menu {
139-
font-size: 11px;
139+
font-size: 0.6875rem;
140140

141141
> .item {
142142
margin-right: 4px;

0 commit comments

Comments
 (0)