Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should raises an error when cast to wrong type', () => {
Navigation.constants().then(result => {
// $ExpectError - backButtonId is string
(result.backButtonId: boolean);
// $ExpectError - backButtonId is number
(result.bottomTabsHeight: string);
// $ExpectError - backButtonId is number
(result.statusBarHeight: string);
// $ExpectError - backButtonId is number
(result.topBarHeight: string);
});
});
});
async update() {
// Add device width and height
const { width, height } = Dimensions.get('window');
setVar('--window-width', width);
setVar('--window-height', height);
// Add navigation constants
const res = await Navigation.constants();
setVar('--bottom-tabs-height', res.bottomTabsHeight);
setVar('--status-bar-height', res.statusBarHeight);
setVar('--top-bar-height', res.topBarHeight);
// Add dynamic variables here
// ...
return true;
},
};
const getStatusBarHeight = async () => {
const navConstants = await Navigation.constants();
// for more info - https://stackoverflow.com/a/48759750
if (Platform.OS === 'ios') {
setKeyboardVerticalOffset(navConstants.statusBarHeight + navConstants.topBarHeight);
}
};
it('should return constants', () => {
Navigation.constants().then(result => {
(result.backButtonId: string);
(result.bottomTabsHeight: number);
(result.statusBarHeight: number);
(result.topBarHeight: number);
});
});
static async getConstFromNavigation() {
if (Platform.OS === 'android') {
let constants = await Navigation.constants();
CommonUtil.topBarHeight = constants.topBarHeight;
CommonUtil.bottomTabsHeight = constants.bottomTabsHeight;
CommonUtil.statusBarHeight = constants.statusBarHeight;
} else {
//自己写的才可以
let constants = await NativeModules.Utils.addEventRNNConst();
console.log({constants});
CommonUtil.topBarHeight = constants.topBarHeight;
CommonUtil.bottomTabsHeight = constants.bottomTabsHeight;
CommonUtil.statusBarHeight = constants.statusBarHeight;
}
}
return flow(function* () {
const { width, height } = window;
const isX = Platform.OS === 'ios' && ((width === 375 && height === 812) || (width === 812 && height === 375));
const isLandscape = width > height;
self.layout.inset = (isX && isLandscape) ? 44 : 0;
self.layout.width = width;
self.layout.height = height;
const constants = yield (Platform.OS === 'android') ? Navigation.constants() : RNHekla.getHeights(self.componentId);
if (constants) {
self.layout.bottomTabsHeight = constants.bottomTabsHeight;
self.layout.topBarHeight = constants.topBarHeight;
self.layout.statusBarHeight = constants.statusBarHeight;
}
})();
},
text: translate('museumScreen_Title'),
icon: require('../src/assets/museumTab.png'),
selectedIcon: require('../src/assets/museumTabSelected.png'),
textColor: OFF_WHITE,
selectedTextColor: 'white',
fontSize: 12,
},
},
},
},
],
},
},
});
const constants = await Navigation.constants();
setBottomTabsHeight(constants.bottomTabsHeight);
const shouldShowTutorial = museumMode || newVersion || showWelcomeScreen;
if (shouldShowTutorial) {
store.dispatch(showTutorial({ showWelcomeScreen }));
}
});
export const stylesUpdateConstants = () => {
Navigation.constants()
.then((constants) => {
let tmpStatusBarHeight = constants.statusBarHeight > 0 ? constants.statusBarHeight : statusBarHeight;
statusBarHeight = tmpStatusBarHeight;
topBarHeight = constants.topBarHeight > 0 ? constants.topBarHeight : topBarHeight;
tabBarHeight = constants.bottomTabsHeight > 0 ? constants.bottomTabsHeight : tabBarHeight;
availableScreenHeight = screenHeight - topBarHeight - tabBarHeight;
availableModalHeight = screenHeight - topBarHeight - 0.5 * tabBarMargin;
})
}
componentWillMount() {
if (!nav) {
Navigation.constants().then(({ statusBarHeight, topBarHeight }) => {
nav = { statusBarHeight, topBarHeight };
this.setState({ nav });
});
}
}