rn-css 1.9.2 → 1.9.4
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/dist/features.d.ts +8 -6
- package/dist/features.js +3 -3
- package/dist/index.d.ts +570 -570
- package/dist/styleComponent.d.ts +10 -9
- package/dist/styleComponent.js +3 -3
- package/package.json +1 -1
- package/src/features.tsx +10 -8
- package/src/styleComponent.tsx +14 -14
package/dist/styleComponent.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { MouseEvent } from 'react';
|
|
2
|
-
import { FlatListProps,
|
|
2
|
+
import { FlatListProps, SectionListProps, StyleProp, TouchableHighlightProps, ViewProps, VirtualizedListProps } from 'react-native';
|
|
3
|
+
import { FocusEventListener, BlurEventListener } from './features';
|
|
3
4
|
import type { CompleteStyle, Units } from './types';
|
|
4
5
|
export declare const defaultUnits: Units;
|
|
5
6
|
export declare const RemContext: React.Context<number>;
|
|
@@ -15,16 +16,16 @@ declare type Functs<T> = (arg: T & {
|
|
|
15
16
|
}) => Primitive;
|
|
16
17
|
declare type OptionalProps = {
|
|
17
18
|
rnCSS?: `${string};`;
|
|
18
|
-
onFocus?:
|
|
19
|
-
onBlur?:
|
|
20
|
-
onPressIn?:
|
|
21
|
-
onPressOut?:
|
|
22
|
-
onResponderStart?:
|
|
23
|
-
onResponderRelease?:
|
|
24
|
-
|
|
19
|
+
onFocus?: FocusEventListener;
|
|
20
|
+
onBlur?: BlurEventListener;
|
|
21
|
+
onPressIn?: TouchableHighlightProps['onPressIn'];
|
|
22
|
+
onPressOut?: TouchableHighlightProps['onPressOut'];
|
|
23
|
+
onResponderStart?: ViewProps['onResponderStart'];
|
|
24
|
+
onResponderRelease?: ViewProps['onResponderRelease'];
|
|
25
|
+
onStartShouldSetResponder?: ViewProps['onStartShouldSetResponder'];
|
|
25
26
|
onMouseEnter?: (event: MouseEvent) => void;
|
|
26
27
|
onMouseLeave?: (event: MouseEvent) => void;
|
|
27
|
-
onLayout?:
|
|
28
|
+
onLayout?: ViewProps['onLayout'];
|
|
28
29
|
children?: React.ReactNode;
|
|
29
30
|
};
|
|
30
31
|
declare const styled: <StyleType, InitialProps extends {
|
package/dist/styleComponent.js
CHANGED
|
@@ -69,7 +69,7 @@ const styled = (Component) => {
|
|
|
69
69
|
// Handle hover
|
|
70
70
|
const { onMouseEnter, onMouseLeave, hover } = (0, features_1.useHover)(props.onMouseEnter, props.onMouseLeave, needsHover);
|
|
71
71
|
// Handle active
|
|
72
|
-
const { onPressIn, onPressOut,
|
|
72
|
+
const { onPressIn, onPressOut, onStartShouldSetResponder, onResponderRelease, onResponderStart, active } = (0, features_1.useActive)(props.onPressIn, props.onPressOut, props.onResponderStart, props.onResponderRelease, props.onStartShouldSetResponder, needsTouch);
|
|
73
73
|
// Handle focus
|
|
74
74
|
const { onFocus, onBlur, focused } = (0, features_1.useFocus)(props.onFocus, props.onBlur, needsFocus);
|
|
75
75
|
const tempStyle = react_1.default.useMemo(() => {
|
|
@@ -132,7 +132,7 @@ const styled = (Component) => {
|
|
|
132
132
|
onBlur,
|
|
133
133
|
onPressIn,
|
|
134
134
|
onPressOut,
|
|
135
|
-
|
|
135
|
+
onStartShouldSetResponder,
|
|
136
136
|
onResponderStart,
|
|
137
137
|
onResponderRelease
|
|
138
138
|
};
|
|
@@ -140,7 +140,7 @@ const styled = (Component) => {
|
|
|
140
140
|
Object.assign(newProps, { numberOfLines: 1 });
|
|
141
141
|
}
|
|
142
142
|
return newProps;
|
|
143
|
-
}, [finalStyle.textOverflow, onBlur, onFocus, onLayout, onMouseEnter, onMouseLeave, onPressIn, onPressOut,
|
|
143
|
+
}, [finalStyle.textOverflow, onBlur, onFocus, onLayout, onMouseEnter, onMouseLeave, onPressIn, onPressOut, onStartShouldSetResponder, onResponderRelease, onResponderStart, props.style, styleConvertedFromCSS]);
|
|
144
144
|
react_1.default.useEffect(() => () => removeStyle(hash), [hash]);
|
|
145
145
|
// em !== parentEm alone is a bit dangerous as the component would rerender when the font size change
|
|
146
146
|
if (em !== parentEm || finalStyle.fontSize !== undefined) {
|
package/package.json
CHANGED
package/src/features.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/display-name */
|
|
2
2
|
import React, { MouseEvent } from 'react'
|
|
3
3
|
import type { Style, Units, MediaQuery, PartialStyle } from './types'
|
|
4
|
-
import { useWindowDimensions, LayoutChangeEvent,
|
|
4
|
+
import { useWindowDimensions, LayoutChangeEvent, GestureResponderEvent, TouchableHighlightProps, TextInputProps } from 'react-native'
|
|
5
5
|
import { parseValue } from './convertUnits'
|
|
6
6
|
import { createContext } from './cssToRN/mediaQueries'
|
|
7
7
|
|
|
@@ -33,7 +33,7 @@ export const useActive = (
|
|
|
33
33
|
onPressOut: undefined | ((event: GestureResponderEvent) => void),
|
|
34
34
|
onResponderStart: undefined | ((event: GestureResponderEvent) => void),
|
|
35
35
|
onResponderRelease: undefined | ((event: GestureResponderEvent) => void),
|
|
36
|
-
|
|
36
|
+
onStartShouldSetResponder: undefined | ((event: GestureResponderEvent) => void),
|
|
37
37
|
needsTouch: boolean
|
|
38
38
|
) => {
|
|
39
39
|
const [active, setActive] = React.useState(false)
|
|
@@ -48,8 +48,8 @@ export const useActive = (
|
|
|
48
48
|
setActive(false)
|
|
49
49
|
} : undefined, [needsTouch, onResponderRelease, onPressOut])
|
|
50
50
|
const grantTouch = React.useMemo(() =>
|
|
51
|
-
needsTouch ?
|
|
52
|
-
, [needsTouch,
|
|
51
|
+
needsTouch ? onStartShouldSetResponder || (() => true) : undefined
|
|
52
|
+
, [needsTouch, onStartShouldSetResponder]
|
|
53
53
|
)
|
|
54
54
|
return {
|
|
55
55
|
active,
|
|
@@ -57,18 +57,20 @@ export const useActive = (
|
|
|
57
57
|
onPressOut: touchEnd || onPressOut,
|
|
58
58
|
onResponderStart: touchStart || onResponderStart,
|
|
59
59
|
onResponderRelease: touchEnd || onResponderRelease,
|
|
60
|
-
|
|
60
|
+
onStartShouldSetResponder: grantTouch || onStartShouldSetResponder
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
export type FocusEventListener = TouchableHighlightProps['onFocus'] | TextInputProps['onFocus']
|
|
65
|
+
export type BlurEventListener = TouchableHighlightProps['onBlur'] | TextInputProps['onBlur']
|
|
64
66
|
/** Hook that will apply the style reserved for active state if needed */
|
|
65
|
-
export const useFocus = (onFocus: undefined |
|
|
67
|
+
export const useFocus = (onFocus: undefined | FocusEventListener, onBlur: undefined | BlurEventListener, needsFocus: boolean) => {
|
|
66
68
|
const [focused, setFocused] = React.useState(false)
|
|
67
|
-
const focusStart = React.useMemo(() => needsFocus ? (event:
|
|
69
|
+
const focusStart = React.useMemo(() => needsFocus ? (event: any) => {
|
|
68
70
|
if (onFocus) onFocus(event)
|
|
69
71
|
setFocused(true)
|
|
70
72
|
} : undefined, [needsFocus, onFocus])
|
|
71
|
-
const focusStop = React.useMemo(() => needsFocus ? (event:
|
|
73
|
+
const focusStop = React.useMemo(() => needsFocus ? (event: any) => {
|
|
72
74
|
if (onBlur) onBlur(event)
|
|
73
75
|
setFocused(false)
|
|
74
76
|
} : undefined, [needsFocus, onBlur])
|
package/src/styleComponent.tsx
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
/* eslint-disable react/prop-types */
|
|
3
3
|
/* eslint-disable react/display-name */
|
|
4
4
|
import React, { MouseEvent } from 'react'
|
|
5
|
-
import { FlatList, FlatListProps,
|
|
5
|
+
import { FlatList, FlatListProps, Platform, SectionList, SectionListProps, StyleProp, StyleSheet, TouchableHighlightProps, ViewProps, ViewStyle, VirtualizedList, VirtualizedListProps } from 'react-native'
|
|
6
6
|
import convertStyle from './convertStyle'
|
|
7
7
|
import cssToStyle from './cssToRN'
|
|
8
|
-
import { useFontSize, useHover, useLayout, useScreenSize, useMediaQuery, useActive, useFocus } from './features'
|
|
8
|
+
import { useFontSize, useHover, useLayout, useScreenSize, useMediaQuery, useActive, useFocus, FocusEventListener, BlurEventListener } from './features'
|
|
9
9
|
import type { AnyStyle, CompleteStyle, Style, Units } from './types'
|
|
10
10
|
import generateHash from './generateHash'
|
|
11
11
|
import rnToCSS from './rnToCss'
|
|
@@ -24,16 +24,16 @@ type Primitive = number | string | null | undefined | boolean | CompleteStyle
|
|
|
24
24
|
type Functs<T> = (arg: T & { rnCSS?: string; shared: unknown, theme: DefaultTheme }) => Primitive
|
|
25
25
|
type OptionalProps = {
|
|
26
26
|
rnCSS?: `${string};`;
|
|
27
|
-
onFocus?:
|
|
28
|
-
onBlur?:
|
|
29
|
-
onPressIn?:
|
|
30
|
-
onPressOut?:
|
|
31
|
-
onResponderStart?:
|
|
32
|
-
onResponderRelease?:
|
|
33
|
-
|
|
27
|
+
onFocus?: FocusEventListener;
|
|
28
|
+
onBlur?: BlurEventListener;
|
|
29
|
+
onPressIn?: TouchableHighlightProps['onPressIn'];
|
|
30
|
+
onPressOut?: TouchableHighlightProps['onPressOut'];
|
|
31
|
+
onResponderStart?: ViewProps['onResponderStart'];
|
|
32
|
+
onResponderRelease?: ViewProps['onResponderRelease'];
|
|
33
|
+
onStartShouldSetResponder?: ViewProps['onStartShouldSetResponder'];
|
|
34
34
|
onMouseEnter?: (event: MouseEvent) => void;
|
|
35
35
|
onMouseLeave?: (event: MouseEvent) => void;
|
|
36
|
-
onLayout?:
|
|
36
|
+
onLayout?: ViewProps['onLayout'];
|
|
37
37
|
children?: React.ReactNode;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -89,9 +89,9 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
|
|
|
89
89
|
// Handle hover
|
|
90
90
|
const { onMouseEnter, onMouseLeave, hover } = useHover(props.onMouseEnter, props.onMouseLeave, needsHover)
|
|
91
91
|
// Handle active
|
|
92
|
-
const { onPressIn, onPressOut,
|
|
92
|
+
const { onPressIn, onPressOut, onStartShouldSetResponder, onResponderRelease, onResponderStart, active } = useActive(
|
|
93
93
|
props.onPressIn, props.onPressOut,
|
|
94
|
-
props.onResponderStart, props.onResponderRelease, props.
|
|
94
|
+
props.onResponderStart, props.onResponderRelease, props.onStartShouldSetResponder,
|
|
95
95
|
needsTouch
|
|
96
96
|
)
|
|
97
97
|
// Handle focus
|
|
@@ -157,7 +157,7 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
|
|
|
157
157
|
onBlur,
|
|
158
158
|
onPressIn,
|
|
159
159
|
onPressOut,
|
|
160
|
-
|
|
160
|
+
onStartShouldSetResponder,
|
|
161
161
|
onResponderStart,
|
|
162
162
|
onResponderRelease
|
|
163
163
|
}
|
|
@@ -165,7 +165,7 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
|
|
|
165
165
|
Object.assign(newProps, { numberOfLines: 1 })
|
|
166
166
|
}
|
|
167
167
|
return newProps
|
|
168
|
-
}, [finalStyle.textOverflow, onBlur, onFocus, onLayout, onMouseEnter, onMouseLeave, onPressIn, onPressOut,
|
|
168
|
+
}, [finalStyle.textOverflow, onBlur, onFocus, onLayout, onMouseEnter, onMouseLeave, onPressIn, onPressOut, onStartShouldSetResponder, onResponderRelease, onResponderStart, props.style, styleConvertedFromCSS])
|
|
169
169
|
|
|
170
170
|
React.useEffect(() => () => removeStyle(hash), [hash])
|
|
171
171
|
|