react-native-is-edge-to-edge
Advanced tools
Comparing version
export declare const isEdgeToEdge: () => boolean; | ||
export declare const controlEdgeToEdgeValues: (values: Record<string, unknown>) => void; |
@@ -6,7 +6,32 @@ 'use strict'; | ||
// src/index.android.ts | ||
var isEdgeToEdge = () => hasReactNativeEdgeToEdgePackage; | ||
var hasReactNativeEdgeToEdgePackage = reactNative.TurboModuleRegistry.get("RNEdgeToEdge") != null; | ||
var isEdgeToEdge = () => hasReactNativeEdgeToEdgePackage; | ||
var warnings = /* @__PURE__ */ new Set(); | ||
var controlEdgeToEdgeValues = (values) => { | ||
if (__DEV__) { | ||
if (hasReactNativeEdgeToEdgePackage) { | ||
const entries = Object.entries(values).filter( | ||
([, value]) => typeof value !== "undefined" | ||
); | ||
const stableKey = entries.join(" "); | ||
if (entries.length < 1 || warnings.has(stableKey)) { | ||
return; | ||
} | ||
warnings.add(stableKey); | ||
const isPlural = entries.length > 1; | ||
const lastIndex = entries.length - 1; | ||
const list = entries.reduce( | ||
(acc, [name], index) => index === 0 ? name : acc + (index === lastIndex ? " and " : ", ") + name, | ||
"" | ||
); | ||
console.warn( | ||
`${list} ${isPlural ? "value" : "values"} are ignored when using react-native-edge-to-edge` | ||
); | ||
} | ||
} | ||
}; | ||
exports.controlEdgeToEdgeValues = controlEdgeToEdgeValues; | ||
exports.isEdgeToEdge = isEdgeToEdge; | ||
//# sourceMappingURL=index.android.js.map | ||
//# sourceMappingURL=index.android.js.map |
export declare const isEdgeToEdge: () => boolean; | ||
export declare const controlEdgeToEdgeValues: (values: Record<string, unknown>) => void; |
@@ -5,5 +5,8 @@ 'use strict'; | ||
var isEdgeToEdge = () => true; | ||
var controlEdgeToEdgeValues = (values) => { | ||
}; | ||
exports.controlEdgeToEdgeValues = controlEdgeToEdgeValues; | ||
exports.isEdgeToEdge = isEdgeToEdge; | ||
//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-native-is-edge-to-edge", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -30,3 +30,4 @@ "description": "Detect react-native-edge-to-edge package install", | ||
"clean": "rm -rf dist", | ||
"build": "yarn clean && tsup && tsc --emitDeclarationOnly" | ||
"test": "vitest run", | ||
"build": "yarn clean && yarn test && tsup && tsc -p tsconfig.build.json --emitDeclarationOnly" | ||
}, | ||
@@ -41,4 +42,5 @@ "peerDependencies": { | ||
"tsup": "^8.3.0", | ||
"typescript": "^5.6.3" | ||
"typescript": "^5.6.3", | ||
"vitest": "^2.1.3" | ||
} | ||
} |
@@ -7,8 +7,27 @@ # react-native-is-edge-to-edge | ||
```ts | ||
import { isEdgeToEdge } from "react-native-is-edge-to-edge"; | ||
```jsx | ||
import { | ||
isEdgeToEdge, | ||
controlEdgeToEdgeValues, | ||
} from "react-native-is-edge-to-edge"; | ||
if (isEdgeToEdge()) { | ||
// …do something | ||
const EDGE_TO_EDGE = isEdgeToEdge(); | ||
function MyLibraryComponent({ | ||
statusBarTranslucent, | ||
navigationBarTranslucent, | ||
}) { | ||
if (__DEV__) { | ||
// warn the user once about unnecessary defined values | ||
controlEdgeToEdgeValues({ statusBarTranslucent, navigationBarTranslucent }); | ||
} | ||
return ( | ||
<MyLibraryNativeComponent | ||
statusBarTranslucent={EDGE_TO_EDGE || statusBarTranslucent} | ||
navigationBarTranslucent={EDGE_TO_EDGE || navigationBarTranslucent} | ||
// … | ||
/> | ||
); | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10381
181.63%80
233.33%33
135.71%5
25%