rn-css 1.9.3 → 1.10.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/dist/convertUnits.js +2 -2
- package/dist/features.d.ts +6 -4
- package/dist/index.d.ts +368 -368
- package/dist/styleComponent.d.ts +3 -2
- package/package.json +1 -1
- package/src/convertUnits.ts +2 -2
- package/src/features.tsx +6 -4
- package/src/styleComponent.tsx +3 -3
package/dist/styleComponent.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { MouseEvent } from 'react';
|
|
2
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,8 +16,8 @@ declare type Functs<T> = (arg: T & {
|
|
|
15
16
|
}) => Primitive;
|
|
16
17
|
declare type OptionalProps = {
|
|
17
18
|
rnCSS?: `${string};`;
|
|
18
|
-
onFocus?:
|
|
19
|
-
onBlur?:
|
|
19
|
+
onFocus?: FocusEventListener;
|
|
20
|
+
onBlur?: BlurEventListener;
|
|
20
21
|
onPressIn?: TouchableHighlightProps['onPressIn'];
|
|
21
22
|
onPressOut?: TouchableHighlightProps['onPressOut'];
|
|
22
23
|
onResponderStart?: ViewProps['onResponderStart'];
|
package/package.json
CHANGED
package/src/convertUnits.ts
CHANGED
|
@@ -22,8 +22,8 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
|
|
|
22
22
|
const finalUnits = { ...units }
|
|
23
23
|
if (value.includes('%')) {
|
|
24
24
|
if (Platform.OS === 'web') return value
|
|
25
|
-
if (['marginTop', 'marginBottom', 'translateY'].includes(key)) finalUnits['%'] = units.height! / 100
|
|
26
|
-
else if (['marginLeft', 'marginRight', 'translateX'].includes(key)) finalUnits['%'] = units.width! / 100
|
|
25
|
+
if (['marginTop', 'marginBottom', 'translateY'].includes(key) || key.startsWith('borderTop') || key.startsWith('borderBottom')) finalUnits['%'] = units.height! / 100
|
|
26
|
+
else if (['marginLeft', 'marginRight', 'translateX'].includes(key) || key.startsWith('borderLeft') || key.startsWith('borderRight')) finalUnits['%'] = units.width! / 100
|
|
27
27
|
else if (key.startsWith('border') && key.endsWith('Radius')) finalUnits['%'] = (units.width! + units.height!) / 200
|
|
28
28
|
else if (['width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', 'top', 'left', 'bottom', 'right', 'flexBasis', 'rotate3d'].includes(key)) {
|
|
29
29
|
if (value.startsWith('calc') || value.startsWith('max') || value.startsWith('min')) {
|
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
|
|
|
@@ -61,14 +61,16 @@ export const useActive = (
|
|
|
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
|
@@ -5,7 +5,7 @@ import React, { MouseEvent } from 'react'
|
|
|
5
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,8 +24,8 @@ 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?:
|
|
27
|
+
onFocus?: FocusEventListener;
|
|
28
|
+
onBlur?: BlurEventListener;
|
|
29
29
|
onPressIn?: TouchableHighlightProps['onPressIn'];
|
|
30
30
|
onPressOut?: TouchableHighlightProps['onPressOut'];
|
|
31
31
|
onResponderStart?: ViewProps['onResponderStart'];
|