Skip to content

Commit 14f37a0

Browse files
committed
feat(ui): add smooth circular animation for theme switching
1 parent 4af3b71 commit 14f37a0

4 files changed

Lines changed: 43 additions & 11 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
"react-native-svg-transformer": "1.5.3",
146146
"react-native-system-navigation-bar": "2.8.0",
147147
"react-native-tcp-socket": "6.2.0",
148+
"react-native-theme-switch-animation": "0.8.0",
148149
"react-native-tor": "https://github.com/ZeusLN/react-native-tor.git#v0.1.9-zeus",
149150
"react-native-udp": "4.1.7",
150151
"react-native-v8": "0.61.5-patch.4",

stores/SettingsStore.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,18 @@ export default class SettingsStore {
15561556
// Favorite currencies
15571557
@observable public favoriteCurrencies: string[] = [];
15581558

1559+
/**
1560+
* Synchronously applies a new theme value in-memory so the UI re-renders
1561+
* before the async storage write completes. This lets animation libraries
1562+
* capture a before/after screenshot pair in the same JS frame.
1563+
*/
1564+
@action public setThemeImmediate = (theme: string) => {
1565+
this.settings = {
1566+
...this.settings,
1567+
display: { ...this.settings.display, theme }
1568+
};
1569+
};
1570+
15591571
@action
15601572
public loadFavoriteCurrencies = async () => {
15611573
try {

views/Settings/Display.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { inject, observer } from 'mobx-react';
44
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
55
import SystemNavigationBar from 'react-native-system-navigation-bar';
66

7+
import switchTheme from 'react-native-theme-switch-animation';
8+
79
import SettingsStore, {
810
DEFAULT_VIEW_KEYS,
911
THEME_KEYS
@@ -122,23 +124,35 @@ export default class Display extends React.Component<
122124
title={localeString('views.Settings.Theme.title')}
123125
selectedValue={theme}
124126
disabled={SettingsStore.settingsUpdateInProgress}
125-
onValueChange={async (value: string) => {
126-
this.setState({
127-
theme: value
127+
onValueChange={(value: string) => {
128+
this.setState({ theme: value });
129+
switchTheme({
130+
switchThemeFunction: () => {
131+
SettingsStore.setThemeImmediate(value);
132+
},
133+
animationConfig: {
134+
type: 'circular',
135+
duration: 600,
136+
startingPoint: {
137+
cxRatio: 0.5,
138+
cyRatio: 0.5
139+
}
140+
}
128141
});
129-
await updateSettings({
142+
updateSettings({
130143
display: {
131144
...settings.display,
132145
theme: value
133146
}
147+
}).then(() => {
148+
SystemNavigationBar.setNavigationColor(
149+
themeColor('background'),
150+
isLightTheme() ? 'dark' : 'light'
151+
);
152+
SystemNavigationBar.setNavigationBarDividerColor(
153+
themeColor('secondary')
154+
);
134155
});
135-
SystemNavigationBar.setNavigationColor(
136-
themeColor('background'),
137-
isLightTheme() ? 'dark' : 'light'
138-
);
139-
SystemNavigationBar.setNavigationBarDividerColor(
140-
themeColor('secondary')
141-
);
142156
}}
143157
values={THEME_KEYS}
144158
/>

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8709,6 +8709,11 @@ react-native-tcp-socket@6.2.0:
87098709
buffer "^5.4.3"
87108710
eventemitter3 "^4.0.7"
87118711

8712+
react-native-theme-switch-animation@0.8.0:
8713+
version "0.8.0"
8714+
resolved "https://registry.yarnpkg.com/react-native-theme-switch-animation/-/react-native-theme-switch-animation-0.8.0.tgz#d9f69d5e41a00697d368897216d318d9430aff0d"
8715+
integrity sha512-z4f3QGSuUP4tagycls2mekng/7uxAbr75Gn0GGm7JRkrviyao++V2CtJ8VUDx+hSOsgfjEhD9D5JubsGbbHB5w==
8716+
87128717
"react-native-tor@https://github.com/ZeusLN/react-native-tor.git#v0.1.9-zeus":
87138718
version "0.1.9-zeus"
87148719
resolved "https://github.com/ZeusLN/react-native-tor.git#4279f398c0834a3792d317cb8b75d81f36f0ca81"

0 commit comments

Comments
 (0)