react-native-smart-layout 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yashvi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # react-native-smart-layout 📱
2
+
3
+ Adaptive, measurement-aware layout utilities for React Native. Build responsive, orientation-aware, and keyboard-friendly UIs with ease.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install react-native-smart-layout
9
+ # or
10
+ yarn add react-native-smart-layout
11
+ ```
12
+
13
+ ## Features
14
+
15
+ - 📏 **Responsive Scaling**: Scale sizes automatically based on screen dimensions.
16
+ - 🔄 **Orientation Detection**: Real-time landscape/portrait state.
17
+ - ⌨️ **Keyboard Avoidance**: Simple hook to get keyboard height/offset.
18
+ - 📐 **Easy Measurement**: Simplified `onLayout` handling for elements.
19
+
20
+ ## Usage
21
+
22
+ ### Responsive Scaling
23
+
24
+ ```tsx
25
+ import { useResponsiveScale } from 'react-native-smart-layout';
26
+
27
+ const MyComponent = () => {
28
+ const rs = useResponsiveScale();
29
+
30
+ return (
31
+ <View style={{ width: rs(100), height: rs(50) }} />
32
+ );
33
+ };
34
+ ```
35
+
36
+ ### Orientation Detection
37
+
38
+ ```tsx
39
+ import { useOrientation } from 'react-native-smart-layout';
40
+
41
+ const MyComponent = () => {
42
+ const isLandscape = useOrientation();
43
+
44
+ return (
45
+ <View style={{ flexDirection: isLandscape ? 'row' : 'column' }}>
46
+ {/* content */}
47
+ </View>
48
+ );
49
+ };
50
+ ```
51
+
52
+ ### Keyboard Offset
53
+
54
+ ```tsx
55
+ import { useKeyboardOffset } from 'react-native-smart-layout';
56
+
57
+ const MyComponent = () => {
58
+ const offset = useKeyboardOffset();
59
+
60
+ return (
61
+ <View style={{ paddingBottom: offset }}>
62
+ <TextInput placeholder="Type here..." />
63
+ </View>
64
+ );
65
+ };
66
+ ```
67
+
68
+ ### Element Measurement
69
+
70
+ ```tsx
71
+ import { useMeasure } from 'react-native-smart-layout';
72
+
73
+ const MyComponent = () => {
74
+ const { width, height, onLayout } = useMeasure();
75
+
76
+ return (
77
+ <View onLayout={onLayout}>
78
+ <Text>Width: {width}</Text>
79
+ </View>
80
+ );
81
+ };
82
+ ```
83
+
84
+ ## License
85
+
86
+ MIT
@@ -0,0 +1 @@
1
+ export declare const useKeyboardOffset: () => number;
@@ -0,0 +1,14 @@
1
+ import { useEffect, useState } from "react";
2
+ import { Keyboard } from "react-native";
3
+ export const useKeyboardOffset = () => {
4
+ const [offset, setOffset] = useState(0);
5
+ useEffect(() => {
6
+ const show = Keyboard.addListener("keyboardDidShow", (e) => setOffset(e.endCoordinates.height));
7
+ const hide = Keyboard.addListener("keyboardDidHide", () => setOffset(0));
8
+ return () => {
9
+ show.remove();
10
+ hide.remove();
11
+ };
12
+ }, []);
13
+ return offset;
14
+ };
@@ -0,0 +1,6 @@
1
+ import { LayoutChangeEvent } from "react-native";
2
+ export declare const useMeasure: () => {
3
+ onLayout: (event: LayoutChangeEvent) => void;
4
+ width: number;
5
+ height: number;
6
+ };
@@ -0,0 +1,12 @@
1
+ import { useState, useCallback } from "react";
2
+ export const useMeasure = () => {
3
+ const [layout, setLayout] = useState({ width: 0, height: 0 });
4
+ const onLayout = useCallback((event) => {
5
+ const { width, height } = event.nativeEvent.layout;
6
+ setLayout({ width, height });
7
+ }, []);
8
+ return {
9
+ ...layout,
10
+ onLayout,
11
+ };
12
+ };
@@ -0,0 +1 @@
1
+ export declare const useOrientation: () => boolean;
@@ -0,0 +1,16 @@
1
+ import { useEffect, useState } from "react";
2
+ import { Dimensions } from "react-native";
3
+ export const useOrientation = () => {
4
+ const getValue = () => {
5
+ const { width, height } = Dimensions.get("window");
6
+ return width > height;
7
+ };
8
+ const [isLandscape, setIsLandscape] = useState(getValue());
9
+ useEffect(() => {
10
+ const sub = Dimensions.addEventListener("change", () => {
11
+ setIsLandscape(getValue());
12
+ });
13
+ return () => sub.remove();
14
+ }, []);
15
+ return isLandscape;
16
+ };
@@ -0,0 +1 @@
1
+ export declare const useResponsiveScale: () => (size: number) => number;
@@ -0,0 +1,6 @@
1
+ import { Dimensions } from "react-native";
2
+ const { width } = Dimensions.get("window");
3
+ const BASE_WIDTH = 375;
4
+ export const useResponsiveScale = () => {
5
+ return (size) => (width / BASE_WIDTH) * size;
6
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Hook to create a responsive scaling function.
3
+ * The scaling function takes a size and returns a value relative to the base screen width (375).
4
+ */
5
+ export { useResponsiveScale } from "./hooks/useResponsiveScale";
6
+ /**
7
+ * Hook to detect screen orientation.
8
+ * Returns true if landscape, false if portrait.
9
+ */
10
+ export { useOrientation } from "./hooks/useOrientation";
11
+ /**
12
+ * Hook to get the current keyboard height/offset.
13
+ * Useful for keyboard-avoiding views.
14
+ */
15
+ export { useKeyboardOffset } from "./hooks/useKeyboardOffset";
16
+ /**
17
+ * Hook to measure the dimensions and position of a component.
18
+ */
19
+ export { useMeasure } from "./hooks/useMeasure";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Hook to create a responsive scaling function.
3
+ * The scaling function takes a size and returns a value relative to the base screen width (375).
4
+ */
5
+ export { useResponsiveScale } from "./hooks/useResponsiveScale";
6
+ /**
7
+ * Hook to detect screen orientation.
8
+ * Returns true if landscape, false if portrait.
9
+ */
10
+ export { useOrientation } from "./hooks/useOrientation";
11
+ /**
12
+ * Hook to get the current keyboard height/offset.
13
+ * Useful for keyboard-avoiding views.
14
+ */
15
+ export { useKeyboardOffset } from "./hooks/useKeyboardOffset";
16
+ /**
17
+ * Hook to measure the dimensions and position of a component.
18
+ */
19
+ export { useMeasure } from "./hooks/useMeasure";
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "react-native-smart-layout",
3
+ "version": "1.0.0",
4
+ "description": "Adaptive, measurement-aware layout utilities for React Native with support for responsive scaling and keyboard avoidance.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "src",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc"
15
+ },
16
+ "peerDependencies": {
17
+ "react": ">=16.8.0",
18
+ "react-native": ">=0.60.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/react": "^19.2.14",
22
+ "@types/react-native": "^0.72.8",
23
+ "typescript": "^5.0.0"
24
+ },
25
+ "keywords": [
26
+ "react-native",
27
+ "layout",
28
+ "responsive",
29
+ "keyboard",
30
+ "orientation",
31
+ "hooks",
32
+ "adaptive-ui"
33
+ ],
34
+ "author": "Yashvi",
35
+ "license": "MIT"
36
+ }
@@ -0,0 +1,21 @@
1
+ import { useEffect, useState } from "react";
2
+ import { Keyboard } from "react-native";
3
+
4
+ export const useKeyboardOffset = () => {
5
+ const [offset, setOffset] = useState(0);
6
+
7
+ useEffect(() => {
8
+ const show = Keyboard.addListener("keyboardDidShow", (e) =>
9
+ setOffset(e.endCoordinates.height),
10
+ );
11
+
12
+ const hide = Keyboard.addListener("keyboardDidHide", () => setOffset(0));
13
+
14
+ return () => {
15
+ show.remove();
16
+ hide.remove();
17
+ };
18
+ }, []);
19
+
20
+ return offset;
21
+ };
@@ -0,0 +1,16 @@
1
+ import { useState, useCallback } from "react";
2
+ import { LayoutChangeEvent } from "react-native";
3
+
4
+ export const useMeasure = () => {
5
+ const [layout, setLayout] = useState({ width: 0, height: 0 });
6
+
7
+ const onLayout = useCallback((event: LayoutChangeEvent) => {
8
+ const { width, height } = event.nativeEvent.layout;
9
+ setLayout({ width, height });
10
+ }, []);
11
+
12
+ return {
13
+ ...layout,
14
+ onLayout,
15
+ };
16
+ };
@@ -0,0 +1,21 @@
1
+ import { useEffect, useState } from "react";
2
+ import { Dimensions } from "react-native";
3
+
4
+ export const useOrientation = () => {
5
+ const getValue = () => {
6
+ const { width, height } = Dimensions.get("window");
7
+ return width > height;
8
+ };
9
+
10
+ const [isLandscape, setIsLandscape] = useState(getValue());
11
+
12
+ useEffect(() => {
13
+ const sub = Dimensions.addEventListener("change", () => {
14
+ setIsLandscape(getValue());
15
+ });
16
+
17
+ return () => sub.remove();
18
+ }, []);
19
+
20
+ return isLandscape;
21
+ };
@@ -0,0 +1,8 @@
1
+ import { Dimensions } from "react-native";
2
+
3
+ const { width } = Dimensions.get("window");
4
+ const BASE_WIDTH = 375;
5
+
6
+ export const useResponsiveScale = () => {
7
+ return (size: number) => (width / BASE_WIDTH) * size;
8
+ };
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Hook to create a responsive scaling function.
3
+ * The scaling function takes a size and returns a value relative to the base screen width (375).
4
+ */
5
+ export { useResponsiveScale } from "./hooks/useResponsiveScale";
6
+ /**
7
+ * Hook to detect screen orientation.
8
+ * Returns true if landscape, false if portrait.
9
+ */
10
+ export { useOrientation } from "./hooks/useOrientation";
11
+ /**
12
+ * Hook to get the current keyboard height/offset.
13
+ * Useful for keyboard-avoiding views.
14
+ */
15
+ export { useKeyboardOffset } from "./hooks/useKeyboardOffset";
16
+ /**
17
+ * Hook to measure the dimensions and position of a component.
18
+ */
19
+ export { useMeasure } from "./hooks/useMeasure";