Commit 10b5456c authored by Jack Hsu's avatar Jack Hsu

adds real window height constant

parent f1bc8991
...@@ -4,22 +4,26 @@ ...@@ -4,22 +4,26 @@
const React = require('react-native'); const React = require('react-native');
const { const {
AppRegistry, AppRegistry,
StyleSheet, Dimensions,
Text, Text,
View, View
} = React; } = React;
const ExtraDimensions = require('react-native-extra-dimensions-android'); const ExtraDimensions = require('react-native-extra-dimensions-android');
const window = Dimensions.get('window');
const Example = React.createClass({ const Example = React.createClass({
render: function() { render() {
return ( return (
<View style={{ flex: 1, flexDirection: 'column' }}> <View style={{ flex: 1 }}>
<View style={{ backgroundColor: 'blue', justifyContent: 'center', alignItems: 'center', height: ExtraDimensions.get('STATUS_BAR_HEIGHT') }}> <View style={{ backgroundColor: 'red', justifyContent: 'center', alignItems: 'center', height: ExtraDimensions.get('STATUS_BAR_HEIGHT')}}>
<Text style={{ color: 'white' }}>STATUS_BAR_HEIGHT ({ExtraDimensions.get('STATUS_BAR_HEIGHT')})</Text> <Text style={{ color: 'white' }}>STATUS_BAR_HEIGHT ({ExtraDimensions.get('STATUS_BAR_HEIGHT')})</Text>
</View> </View>
<View style={{ flex: 1 }}/> <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<View style={{ backgroundColor: 'green', justifyContent: 'center', alignItems: 'center', height: ExtraDimensions.get('SOFT_MENU_BAR_HEIGHT') }}> <Text>REAL_WINDOW_HEIGHT ({ExtraDimensions.get('REAL_WINDOW_HEIGHT')})</Text>
</View>
<View style={{ backgroundColor: 'blue', justifyContent: 'center', alignItems: 'center', height: ExtraDimensions.get('SOFT_MENU_BAR_HEIGHT')}}>
<Text style={{ color: 'white' }}>SOFT_MENU_BAR_HEIGHT ({ExtraDimensions.get('SOFT_MENU_BAR_HEIGHT')})</Text> <Text style={{ color: 'white' }}>SOFT_MENU_BAR_HEIGHT ({ExtraDimensions.get('SOFT_MENU_BAR_HEIGHT')})</Text>
</View> </View>
</View> </View>
......
...@@ -32,6 +32,7 @@ public class ExtraDimensionsModule extends ReactContextBaseJavaModule { ...@@ -32,6 +32,7 @@ public class ExtraDimensionsModule extends ReactContextBaseJavaModule {
constants.put("STATUS_BAR_HEIGHT", getStatusBarHeight()); constants.put("STATUS_BAR_HEIGHT", getStatusBarHeight());
constants.put("SOFT_MENU_BAR_HEIGHT", getSoftMenuBarHeight()); constants.put("SOFT_MENU_BAR_HEIGHT", getSoftMenuBarHeight());
constants.put("REAL_WINDOW_HEIGHT", getRealHeight());
return constants; return constants;
} }
...@@ -54,10 +55,14 @@ public class ExtraDimensionsModule extends ReactContextBaseJavaModule { ...@@ -54,10 +55,14 @@ public class ExtraDimensionsModule extends ReactContextBaseJavaModule {
mCurrentActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); mCurrentActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels; int usableHeight = metrics.heightPixels;
mCurrentActivity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); return Math.max(0, getRealHeight() - usableHeight / metrics.density);
int realHeight = metrics.heightPixels; }
return Math.max(0, realHeight - usableHeight) / metrics.density; private float getRealHeight() {
Context ctx = getReactApplicationContext();
DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
mCurrentActivity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
return metrics.heightPixels / metrics.density;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment