Skip to content

Commit

Permalink
Merge pull request #27368 from software-mansion-labs/ts-migration/Sta…
Browse files Browse the repository at this point in the history
…tusBar
  • Loading branch information
francoisl authored Sep 21, 2023
2 parents b7f2480 + 2cc6726 commit bb84ee1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line no-restricted-imports
import {StatusBar} from 'react-native';
import StatusBar from './types';

// Only has custom web implementation
StatusBar.getBackgroundColor = () => null;
Expand All @@ -8,5 +7,4 @@ StatusBar.getBackgroundColor = () => null;
// Also because Reanimated's interpolateColor gives Android native colors instead of hex strings, causing this to display a warning.
StatusBar.setBackgroundColor = () => null;

// Just export StatusBar – no changes.
export default StatusBar;
3 changes: 1 addition & 2 deletions src/libs/StatusBar/index.js → src/libs/StatusBar/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line no-restricted-imports
import {StatusBar} from 'react-native';
import StatusBar from './types';

// Only has custom web implementation
StatusBar.getBackgroundColor = () => null;
Expand Down
20 changes: 0 additions & 20 deletions src/libs/StatusBar/index.web.js

This file was deleted.

23 changes: 23 additions & 0 deletions src/libs/StatusBar/index.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import StatusBar from './types';

StatusBar.getBackgroundColor = () => {
const element = document.querySelector<HTMLMetaElement>('meta[name=theme-color]');

if (!element?.content) {
return null;
}

return element.content;
};

StatusBar.setBackgroundColor = (backgroundColor) => {
const element = document.querySelector<HTMLMetaElement>('meta[name=theme-color]');

if (!element) {
return;
}

element.content = backgroundColor as string;
};

export default StatusBar;
10 changes: 10 additions & 0 deletions src/libs/StatusBar/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// eslint-disable-next-line no-restricted-imports
import {StatusBar as StatusBarRN} from 'react-native';

type StatusBarExtended = typeof StatusBarRN & {
getBackgroundColor(): string | null;
};

const StatusBar = StatusBarRN as StatusBarExtended;

export default StatusBar;

0 comments on commit bb84ee1

Please sign in to comment.