Skip to content

Commit

Permalink
Memoize repeated calls to getConstants() in MP Home, and Search
Browse files Browse the repository at this point in the history
Reviewed By: fkgozali

Differential Revision: D21899206

fbshipit-source-id: 44ab118dc49697c1270d3c3f164c1ddf7bef0be4
  • Loading branch information
RSNara authored and facebook-github-bot committed Jun 5, 2020
1 parent 8821d27 commit 6de3fff
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 11 deletions.
40 changes: 37 additions & 3 deletions Libraries/Components/StatusBar/NativeStatusBarManagerAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,40 @@ export interface Spec extends TurboModule {
+setHidden: (hidden: boolean) => void;
}

export default (TurboModuleRegistry.getEnforcing<Spec>(
'StatusBarManager',
): Spec);
const NativeModule = TurboModuleRegistry.getEnforcing<Spec>('StatusBarManager');
let constants = null;

const NativeStatusBarManager = {
getConstants(): {|
+HEIGHT: number,
+DEFAULT_BACKGROUND_COLOR?: number,
|} {
if (constants == null) {
constants = NativeModule.getConstants();
}
return constants;
},

setColor(color: number, animated: boolean): void {
NativeModule.setColor(color, animated);
},

setTranslucent(translucent: boolean): void {
NativeModule.setTranslucent(translucent);
},

/**
* - statusBarStyles can be:
* - 'default'
* - 'dark-content'
*/
setStyle(statusBarStyle?: ?string): void {
NativeModule.setStyle(statusBarStyle);
},

setHidden(hidden: boolean): void {
NativeModule.setHidden(hidden);
},
};

export default NativeStatusBarManager;
53 changes: 50 additions & 3 deletions Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,53 @@ export interface Spec extends TurboModule {
+setHidden: (hidden: boolean, withAnimation: string) => void;
}

export default (TurboModuleRegistry.getEnforcing<Spec>(
'StatusBarManager',
): Spec);
const NativeModule = TurboModuleRegistry.getEnforcing<Spec>('StatusBarManager');
let constants = null;

const NativeStatusBarManager = {
getConstants(): {|
+HEIGHT: number,
+DEFAULT_BACKGROUND_COLOR?: number,
|} {
if (constants == null) {
constants = NativeModule.getConstants();
}
return constants;
},

// TODO(T47754272) Can we remove this method?
getHeight(callback: (result: {|height: number|}) => void): void {
NativeModule.getHeight(callback);
},

setNetworkActivityIndicatorVisible(visible: boolean): void {
NativeModule.setNetworkActivityIndicatorVisible(visible);
},

addListener(eventType: string): void {
NativeModule.addListener(eventType);
},

removeListeners(count: number): void {
NativeModule.removeListeners(count);
},

/**
* - statusBarStyles can be:
* - 'default'
* - 'dark-content'
* - 'light-content'
*/
setStyle(statusBarStyle?: ?string, animated: boolean): void {
NativeModule.setStyle(statusBarStyle, animated);
},

/**
* - withAnimation can be: 'none' | 'fade' | 'slide'
*/
setHidden(hidden: boolean, withAnimation: string): void {
NativeModule.setHidden(hidden, withAnimation);
},
};

export default NativeStatusBarManager;
12 changes: 7 additions & 5 deletions Libraries/Components/ToastAndroid/ToastAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ import NativeToastAndroid from './NativeToastAndroid';
* ```
*/

const ToastAndroidConstants = NativeToastAndroid.getConstants();

const ToastAndroid = {
// Toast duration constants
SHORT: (NativeToastAndroid.getConstants().SHORT: number),
LONG: (NativeToastAndroid.getConstants().LONG: number),
SHORT: (ToastAndroidConstants.SHORT: number),
LONG: (ToastAndroidConstants.LONG: number),
// Toast gravity constants
TOP: (NativeToastAndroid.getConstants().TOP: number),
BOTTOM: (NativeToastAndroid.getConstants().BOTTOM: number),
CENTER: (NativeToastAndroid.getConstants().CENTER: number),
TOP: (ToastAndroidConstants.TOP: number),
BOTTOM: (ToastAndroidConstants.BOTTOM: number),
CENTER: (ToastAndroidConstants.CENTER: number),

show: function(message: string, duration: number): void {
NativeToastAndroid.show(message, duration);
Expand Down

0 comments on commit 6de3fff

Please sign in to comment.