react-native-dynamic-responsive 1.0.2 → 1.1.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/README.md +149 -1209
- package/dist/responsive.d.ts +20 -5
- package/dist/responsive.js +5 -11
- package/package.json +2 -2
package/dist/responsive.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
1
2
|
import { StyleSheet } from 'react-native';
|
|
2
3
|
export declare const SCREEN_WIDTH: () => number;
|
|
3
4
|
export declare const SCREEN_HEIGHT: () => number;
|
|
@@ -42,10 +43,24 @@ export type ResponsiveUtils = {
|
|
|
42
43
|
};
|
|
43
44
|
export declare const useResponsive: () => ResponsiveUtils;
|
|
44
45
|
/**
|
|
45
|
-
* Hook to create dynamic stylesheets that recalculate on dimension changes
|
|
46
|
+
* Hook to create dynamic stylesheets that recalculate on dimension changes,
|
|
47
|
+
* theme switching, or custom dependency updates.
|
|
48
|
+
*
|
|
46
49
|
* Usage:
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* }
|
|
50
|
+
* 1. Responsive only:
|
|
51
|
+
* const styles = useStyles((r) => ({
|
|
52
|
+
* container: { padding: r.ms(16) }
|
|
53
|
+
* }));
|
|
54
|
+
*
|
|
55
|
+
* 2. With Theme / Custom Props (recommended for dynamic theming):
|
|
56
|
+
* const styles = useStyles((r, theme) => ({
|
|
57
|
+
* container: { backgroundColor: theme.colors.background, padding: r.ms(16) }
|
|
58
|
+
* }), theme);
|
|
59
|
+
*
|
|
60
|
+
* 3. With Dependency Array:
|
|
61
|
+
* const styles = useStyles((r) => ({
|
|
62
|
+
* container: { backgroundColor: theme.colors.background, padding: r.ms(16) }
|
|
63
|
+
* }), [theme]);
|
|
50
64
|
*/
|
|
51
|
-
export declare function useStyles<T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>>(createStyles: (utils: ResponsiveUtils) => T | StyleSheet.NamedStyles<T
|
|
65
|
+
export declare function useStyles<T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>>(createStyles: (utils: ResponsiveUtils) => T | StyleSheet.NamedStyles<T>, deps?: DependencyList): T;
|
|
66
|
+
export declare function useStyles<T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>, P = undefined>(createStyles: (utils: ResponsiveUtils, props: P) => T | StyleSheet.NamedStyles<T>, props?: P, deps?: DependencyList): T;
|
package/dist/responsive.js
CHANGED
|
@@ -100,16 +100,10 @@ const useResponsive = () => {
|
|
|
100
100
|
}, [width, height]);
|
|
101
101
|
};
|
|
102
102
|
exports.useResponsive = useResponsive;
|
|
103
|
-
|
|
104
|
-
* Hook to create dynamic stylesheets that recalculate on dimension changes.
|
|
105
|
-
* Usage:
|
|
106
|
-
* const styles = useStyles((r) => ({
|
|
107
|
-
* container: { padding: r.ms(16) }
|
|
108
|
-
* }));
|
|
109
|
-
*/
|
|
110
|
-
function useStyles(createStyles) {
|
|
103
|
+
function useStyles(createStyles, propsOrDeps, deps) {
|
|
111
104
|
const responsive = (0, exports.useResponsive)();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
105
|
+
const isDepsArray = Array.isArray(propsOrDeps);
|
|
106
|
+
const resolvedProps = (isDepsArray ? undefined : propsOrDeps);
|
|
107
|
+
const extraDeps = (isDepsArray ? propsOrDeps : deps) || [];
|
|
108
|
+
return (0, react_1.useMemo)(() => react_native_1.StyleSheet.create(createStyles(responsive, resolvedProps)), [responsive.width, responsive.height, resolvedProps, ...extraDeps]);
|
|
115
109
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-dynamic-responsive",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Production-ready dynamic responsive setup for React Native apps.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://gitlab.com/code_dharmendra/react-native-dynamic-responsive.git"
|
|
9
|
+
"url": "git+https://gitlab.com/code_dharmendra/react-native-dynamic-responsive.git"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsc",
|