Skip to content

Commit

Permalink
fix(ios): sync keyboard color scheme when theme changed (#9184)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Dec 18, 2024
1 parent f0d99f4 commit 2ceb6e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/frontend/apps/ios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@capacitor/ios": "^6.2.0",
"@capacitor/keyboard": "^6.0.3",
"@sentry/react": "^8.44.0",
"next-themes": "^0.4.4",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-router-dom": "^6.28.0"
Expand Down
25 changes: 23 additions & 2 deletions packages/frontend/apps/ios/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ import { I18n } from '@affine/i18n';
import { App as CapacitorApp } from '@capacitor/app';
import { Browser } from '@capacitor/browser';
import { Haptics } from '@capacitor/haptics';
import { Keyboard } from '@capacitor/keyboard';
import { Keyboard, KeyboardStyle } from '@capacitor/keyboard';
import {
Framework,
FrameworkRoot,
getCurrentStore,
GlobalContextService,
LifecycleService,
} from '@toeverything/infra';
import { Suspense } from 'react';
import { useTheme } from 'next-themes';
import { Suspense, useEffect } from 'react';
import { RouterProvider } from 'react-router-dom';

import { configureFetchProvider } from './fetch';
Expand Down Expand Up @@ -171,12 +172,32 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => {
console.error(e);
});

const KeyboardThemeProvider = () => {
const { resolvedTheme } = useTheme();

useEffect(() => {
Keyboard.setStyle({
style:
resolvedTheme === 'dark'
? KeyboardStyle.Dark
: resolvedTheme === 'light'
? KeyboardStyle.Light
: KeyboardStyle.Default,
}).catch(e => {
console.error(`Failed to set keyboard style: ${e}`);
});
}, [resolvedTheme]);

return null;
};

export function App() {
return (
<Suspense>
<FrameworkRoot framework={frameworkProvider}>
<I18nProvider>
<AffineContext store={getCurrentStore()}>
<KeyboardThemeProvider />
<ModalConfigProvider>
<RouterProvider
fallbackElement={<AppFallback />}
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ __metadata:
"@types/react": "npm:^19.0.1"
"@types/react-dom": "npm:^19.0.2"
cross-env: "npm:^7.0.3"
next-themes: "npm:^0.4.4"
react: "npm:^19.0.0"
react-dom: "npm:^19.0.0"
react-router-dom: "npm:^6.28.0"
Expand Down

0 comments on commit 2ceb6e9

Please sign in to comment.