From 6353a61b11f7dfe876a366e461c63ad7e3650937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Gon=C3=A7alves?= Date: Tue, 19 Sep 2023 10:19:09 +0100 Subject: [PATCH 1/2] Converted to ts addresing types and files extension --- .../BootSplash/{index.native.js => index.native.ts} | 3 ++- src/libs/BootSplash/{index.js => index.ts} | 13 +++++++++---- src/libs/BootSplash/types.ts | 9 +++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) rename src/libs/BootSplash/{index.native.js => index.native.ts} (75%) rename src/libs/BootSplash/{index.js => index.ts} (66%) create mode 100644 src/libs/BootSplash/types.ts diff --git a/src/libs/BootSplash/index.native.js b/src/libs/BootSplash/index.native.ts similarity index 75% rename from src/libs/BootSplash/index.native.js rename to src/libs/BootSplash/index.native.ts index 942b3cadb74a..f0082afa46d5 100644 --- a/src/libs/BootSplash/index.native.js +++ b/src/libs/BootSplash/index.native.ts @@ -1,7 +1,8 @@ import {NativeModules} from 'react-native'; import Log from '../Log'; +import {BootSplashModule} from './types'; -const BootSplash = NativeModules.BootSplash; +const BootSplash: BootSplashModule = NativeModules.BootSplash; function hide() { Log.info('[BootSplash] hiding splash screen', false); diff --git a/src/libs/BootSplash/index.js b/src/libs/BootSplash/index.ts similarity index 66% rename from src/libs/BootSplash/index.js rename to src/libs/BootSplash/index.ts index ff7ab5562b1f..d614c06da090 100644 --- a/src/libs/BootSplash/index.js +++ b/src/libs/BootSplash/index.ts @@ -1,6 +1,7 @@ import Log from '../Log'; +import {VisibilityStatus} from './types'; -function resolveAfter(delay) { +function resolveAfter(delay: number) { return new Promise((resolve) => setTimeout(resolve, delay)); } @@ -9,16 +10,20 @@ function hide() { return document.fonts.ready.then(() => { const splash = document.getElementById('splash'); - if (splash) splash.style.opacity = 0; + if (splash) { + splash.style.opacity = '0'; + } return resolveAfter(250).then(() => { - if (!splash || !splash.parentNode) return; + if (!splash?.parentNode) { + return; + } splash.parentNode.removeChild(splash); }); }); } -function getVisibilityStatus() { +function getVisibilityStatus(): Promise { return Promise.resolve(document.getElementById('splash') ? 'visible' : 'hidden'); } diff --git a/src/libs/BootSplash/types.ts b/src/libs/BootSplash/types.ts new file mode 100644 index 000000000000..2329d5315817 --- /dev/null +++ b/src/libs/BootSplash/types.ts @@ -0,0 +1,9 @@ +type VisibilityStatus = 'visible' | 'hidden'; + +type BootSplashModule = { + navigationBarHeight: number; + hide: () => Promise; + getVisibilityStatus: () => Promise; +}; + +export type {BootSplashModule, VisibilityStatus}; From a1dff6f28fb81b71fee4e898445e757cb96297a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Gon=C3=A7alves?= Date: Thu, 21 Sep 2023 01:08:43 +0100 Subject: [PATCH 2/2] Addressed PR comments --- src/libs/BootSplash/index.native.ts | 5 ++--- src/libs/BootSplash/index.ts | 6 +++--- src/types/modules/react-native.d.ts | 5 +++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libs/BootSplash/index.native.ts b/src/libs/BootSplash/index.native.ts index f0082afa46d5..0790b4de89bc 100644 --- a/src/libs/BootSplash/index.native.ts +++ b/src/libs/BootSplash/index.native.ts @@ -1,10 +1,9 @@ import {NativeModules} from 'react-native'; import Log from '../Log'; -import {BootSplashModule} from './types'; -const BootSplash: BootSplashModule = NativeModules.BootSplash; +const BootSplash = NativeModules.BootSplash; -function hide() { +function hide(): Promise { Log.info('[BootSplash] hiding splash screen', false); return BootSplash.hide(); } diff --git a/src/libs/BootSplash/index.ts b/src/libs/BootSplash/index.ts index d614c06da090..24842fe631f4 100644 --- a/src/libs/BootSplash/index.ts +++ b/src/libs/BootSplash/index.ts @@ -1,11 +1,11 @@ import Log from '../Log'; import {VisibilityStatus} from './types'; -function resolveAfter(delay: number) { - return new Promise((resolve) => setTimeout(resolve, delay)); +function resolveAfter(delay: number): Promise { + return new Promise((resolve) => setTimeout(resolve, delay)); } -function hide() { +function hide(): Promise { Log.info('[BootSplash] hiding splash screen', false); return document.fonts.ready.then(() => { diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts index 1b0b39e5f67d..ebe0974db690 100644 --- a/src/types/modules/react-native.d.ts +++ b/src/types/modules/react-native.d.ts @@ -1,9 +1,14 @@ /* eslint-disable @typescript-eslint/consistent-type-definitions */ import 'react-native'; +import {BootSplashModule} from '../../libs/BootSplash/types'; declare module 'react-native' { interface TextInput { // Typescript type declaration is missing in React Native for setting text selection. setSelection: (start: number, end: number) => void; } + + interface NativeModulesStatic { + BootSplash: BootSplashModule; + } }