Skip to content

Commit

Permalink
refactor: update appearance subscription (#2586)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak authored Oct 25, 2021
1 parent 91e669c commit 58851e3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,20 @@ const Provider = ({ ...props }: Props) => {
}, [props.theme]);

React.useEffect(() => {
if (!props.theme) Appearance?.addChangeListener(handleAppearanceChange);
let appearanceSubscription: NativeEventSubscription | undefined;
if (!props.theme) {
appearanceSubscription = Appearance?.addChangeListener(
handleAppearanceChange
) as NativeEventSubscription | undefined;
}
return () => {
if (!props.theme)
Appearance?.removeChangeListener(handleAppearanceChange);
if (!props.theme) {
if (appearanceSubscription) {
appearanceSubscription.remove();
} else {
Appearance?.removeChangeListener(handleAppearanceChange);
}
}
};
}, [props.theme]);

Expand Down

0 comments on commit 58851e3

Please sign in to comment.