Skip to content

fix: android top positioning bug #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/Tooltip.style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StyleProp, StyleSheet, ViewStyle } from "react-native";
import { Platform, StyleProp, StyleSheet, ViewStyle } from "react-native";
import { Placement, PlacementStyle } from "./Tooltip.type";
import { getAndroidStatusBarHeight } from "./helpers";

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -185,8 +186,11 @@ const styleGenerator = (styleGeneratorProps: any) => {
adjustedContentSize.width !== 0 &&
measurementsFinished &&
styles.containerVisible,
topAdjustment !== 0 && {
top: topAdjustment,
{
top:
Platform.OS === "android"
? (topAdjustment || 0) - getAndroidStatusBarHeight()
: topAdjustment || 0,
},
),
],
Expand Down
26 changes: 26 additions & 0 deletions lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { PixelRatio, StatusBar } from "react-native";

export const getAndroidStatusBarHeight = () => {
const statusBarHeight = StatusBar.currentHeight;
if (statusBarHeight) {
return statusBarHeight;
} else {
const density = PixelRatio.get();
if (density <= 1) {
// mdpi
return 25;
} else if (density <= 1.5) {
// hdpi
return 38;
} else if (density <= 2) {
// xhdpi
return 50;
} else if (density <= 3) {
// xxhdpi
return 76;
} else {
// other densities, e.g., xxxhdpi
return 76; // Default to xxhdpi height
}
}
};
267 changes: 262 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"prettier-format": "^3.0.3",
"react-native-typescript-transformer": "^1.2.13",
"semantic-release": "^19.0.5",
"typescript": "^4.0.3"
"typescript": "^4.0.3",
"tslint": "^6.1.3"
},
"scripts": {
"build": "cd lib && tsc && npm run copy:assets && npm run copy:package",
Expand All @@ -57,4 +58,4 @@
"husky:lint": "npx husky add .husky/pre-commit 'npm run lint'",
"husky:prettier": "npx husky set .husky/pre-commit 'npm run prettier'"
}
}
}