rn-css 1.9.1 → 1.9.3
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/cssToRN/index.js +13 -1
- package/dist/features.d.ts +16 -1
- package/dist/features.js +45 -1
- package/dist/index.d.ts +2720 -3
- package/dist/index.js +56 -172
- package/dist/styleComponent.d.ts +9 -2
- package/dist/styleComponent.js +30 -6
- package/dist/types.d.ts +2 -0
- package/package.json +2 -2
- package/src/features.tsx +4 -4
- package/src/styleComponent.tsx +13 -13
- package/dist/app.json +0 -4
- package/dist/src/convertStyle.d.ts +0 -5
- package/dist/src/convertStyle.js +0 -56
- package/dist/src/convertUnits.d.ts +0 -5
- package/dist/src/convertUnits.js +0 -71
- package/dist/src/cssToRN/convert.d.ts +0 -55
- package/dist/src/cssToRN/convert.js +0 -418
- package/dist/src/cssToRN/index.d.ts +0 -8
- package/dist/src/cssToRN/index.js +0 -140
- package/dist/src/cssToRN/maths.d.ts +0 -4
- package/dist/src/cssToRN/maths.js +0 -86
- package/dist/src/cssToRN/mediaQueries.d.ts +0 -7
- package/dist/src/cssToRN/mediaQueries.js +0 -161
- package/dist/src/features.d.ts +0 -43
- package/dist/src/features.js +0 -130
- package/dist/src/generateHash.d.ts +0 -2
- package/dist/src/generateHash.js +0 -8
- package/dist/src/index.d.ts +0 -2720
- package/dist/src/index.js +0 -60
- package/dist/src/polyfill.d.ts +0 -3
- package/dist/src/polyfill.js +0 -23
- package/dist/src/rnToCss.d.ts +0 -3
- package/dist/src/rnToCss.js +0 -8
- package/dist/src/styleComponent.d.ts +0 -50
- package/dist/src/styleComponent.js +0 -181
- package/dist/src/types.d.ts +0 -86
- package/dist/src/types.js +0 -2
- package/dist/src/useTheme.d.ts +0 -18
- package/dist/src/useTheme.js +0 -33
package/dist/index.js
CHANGED
|
@@ -1,176 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const View = src_1.default.View `
|
|
14
|
-
background: green;
|
|
15
|
-
border-radius: 50%;
|
|
16
|
-
width: 200px;
|
|
17
|
-
height: 200px;
|
|
18
|
-
`;
|
|
19
|
-
const Dot = (0, src_1.default)(react_native_1.Animated.View) `
|
|
20
|
-
width: 5em;
|
|
21
|
-
height: 5em;
|
|
22
|
-
margin: 2em;
|
|
23
|
-
border-radius: 50%;
|
|
24
|
-
z-index: 10;
|
|
25
|
-
`;
|
|
26
|
-
const StyledText = src_1.default.Text `
|
|
27
|
-
color: ${props => props.col || 'black'}
|
|
28
|
-
font-size: 1em;
|
|
29
|
-
@media (max-width: 40em) {
|
|
30
|
-
color: blue;
|
|
31
|
-
font-size: 2em;
|
|
32
|
-
}
|
|
33
|
-
@media (max-width: 20em) {
|
|
34
|
-
color: red;
|
|
35
|
-
font-size: 3em;
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
38
|
-
const Box = src_1.default.View `
|
|
39
|
-
width: ${value}em;
|
|
40
|
-
max-width: 50vw;
|
|
41
|
-
`;
|
|
42
|
-
const Box2 = src_1.default.View `
|
|
43
|
-
width: 100vw;
|
|
44
|
-
height: 2em;
|
|
45
|
-
background: blue;
|
|
46
|
-
`;
|
|
47
|
-
const Popup = src_1.default.View `
|
|
48
|
-
z-index: 20;
|
|
49
|
-
position: absolute;
|
|
50
|
-
top: calc(100% + 2px);
|
|
51
|
-
background-color: black;
|
|
52
|
-
`;
|
|
53
|
-
const Hoverable = src_1.default.View `
|
|
54
|
-
width: 100px;
|
|
55
|
-
height: 100px;
|
|
56
|
-
background: red;
|
|
57
|
-
&:hover {
|
|
58
|
-
background: blue;
|
|
59
|
-
}
|
|
60
|
-
`;
|
|
61
|
-
const HoverableText = src_1.default.Text `
|
|
62
|
-
&:hover {
|
|
63
|
-
fontSize: 2em
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
66
|
-
const Options = src_1.default.FlatList.attrs(props => ({ pressed: props.selected || props.pressed })) `
|
|
67
|
-
position: absolute;
|
|
68
|
-
top: 100%;
|
|
69
|
-
z-index: 1;
|
|
70
|
-
`;
|
|
71
|
-
const ColorCircle = src_1.default.TouchableOpacity `
|
|
72
|
-
background-color: ${props => props.color};
|
|
73
|
-
width: ${props => props.size || 2}em;
|
|
74
|
-
height: ${props => props.size || 2}em;
|
|
75
|
-
opacity: 1;
|
|
76
|
-
border-radius: 50%;
|
|
77
|
-
&:hover {
|
|
78
|
-
background-color: red;
|
|
79
|
-
opacity: 0.5;
|
|
80
|
-
}
|
|
81
|
-
`;
|
|
82
|
-
const FlatList = () => {
|
|
83
|
-
return react_1.default.createElement(Options, { data: ['teset'], selected: true, pressed: true, renderItem: ({ item }) => (react_1.default.createElement(StyledText, { col: 'blue' }, item)) });
|
|
84
|
-
};
|
|
85
|
-
const Comp = ({ style, text }) => {
|
|
86
|
-
return react_1.default.createElement(View, { style: style },
|
|
87
|
-
react_1.default.createElement(react_native_1.Text, null, text));
|
|
88
|
-
};
|
|
89
|
-
const ExtendedComp = (0, src_1.default)(Comp).attrs({ text: 'test' }) ``;
|
|
90
|
-
// const ExtendedComp2 = styled(Comp)<{ small: boolean }>`
|
|
91
|
-
// ${props => props.small ? 'font-size: 0.8em' : ''}
|
|
92
|
-
// `
|
|
93
|
-
const CustomTouchable = src_1.default.TouchableOpacity.attrs({ activeOpacity: 1 }) ``;
|
|
94
|
-
const Touchable = src_1.default.TouchableOpacity `
|
|
95
|
-
background-color: ${props => props.pressed ? 'blue' : 'red'};
|
|
96
|
-
&:active {
|
|
97
|
-
background-color: purple;
|
|
98
|
-
}
|
|
99
|
-
&:focus {
|
|
100
|
-
background-color: pink;
|
|
101
|
-
}
|
|
102
|
-
&:hover {
|
|
103
|
-
background-color: yellow;
|
|
104
|
-
}
|
|
105
|
-
`;
|
|
106
|
-
// const CustomSelectContainer = styled.TouchableOpacity.attrs({ activeOpacity: 1 })`
|
|
107
|
-
// padding: 2px;
|
|
108
|
-
// margin: 0.2em;
|
|
109
|
-
// border-radius: 0.6em;
|
|
110
|
-
// width: 8em;
|
|
111
|
-
// height: 3.6em;
|
|
112
|
-
// flex-direction: row;
|
|
113
|
-
// background-color: white;
|
|
114
|
-
// border-width: 1px;
|
|
115
|
-
// border-style: solid;
|
|
116
|
-
// `
|
|
117
|
-
const Forward = react_1.default.forwardRef((props, ref) => {
|
|
118
|
-
return react_1.default.createElement(Touchable, { ref: ref, ...props, pressed: true });
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
119
13
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
125
20
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const App = () => {
|
|
129
|
-
const ref = react_1.default.useRef(null);
|
|
130
|
-
const ref2 = react_1.default.useRef(null);
|
|
131
|
-
react_1.default.useLayoutEffect(() => console.log(ref), []);
|
|
132
|
-
const dotLeft = react_1.default.useRef(new react_native_1.Animated.Value(0));
|
|
133
|
-
const dotStyle = react_1.default.useMemo(() => ({
|
|
134
|
-
left: dotLeft.current.interpolate({
|
|
135
|
-
inputRange: [0, 50],
|
|
136
|
-
outputRange: ['0%', '50%']
|
|
137
|
-
})
|
|
138
|
-
}), []);
|
|
139
|
-
// const LangDropdownItem = styled.View.attrs<{ label: string; value: number }>(
|
|
140
|
-
// ({ label }) => ({
|
|
141
|
-
// label: label + 2
|
|
142
|
-
// })
|
|
143
|
-
// )`
|
|
144
|
-
// z-index: ${props => props.value + ''};
|
|
145
|
-
// `
|
|
146
|
-
const touchableProps = { activeOpacity: 0 };
|
|
147
|
-
return (react_1.default.createElement(Box, { ref: ref2 },
|
|
148
|
-
react_1.default.createElement(View, { style: { flexDirection: 'column' } },
|
|
149
|
-
react_1.default.createElement(StyledText, { ref: ref, col: 'black', numberOfLines: 1, style: { flexGrow: 1, flexBasis: 'auto' } }, "Welcome to ReactNativeStyledComponents")),
|
|
150
|
-
react_1.default.createElement(Box, null,
|
|
151
|
-
react_1.default.createElement(Box, null,
|
|
152
|
-
react_1.default.createElement(Box, null,
|
|
153
|
-
react_1.default.createElement(StyledText, { col: 'red' }, "Placeholder"),
|
|
154
|
-
react_1.default.createElement(Popup, null,
|
|
155
|
-
react_1.default.createElement(StyledText, { col: 'green' }, "Should be over")))),
|
|
156
|
-
react_1.default.createElement(Box, null,
|
|
157
|
-
react_1.default.createElement(StyledText, { col: 'red' }, "Placeholder"))),
|
|
158
|
-
react_1.default.createElement(Hoverable, null,
|
|
159
|
-
react_1.default.createElement(StyledText, { col: 'white' }, "Hover me !")),
|
|
160
|
-
react_1.default.createElement(HoverableText, null, "Hover me !"),
|
|
161
|
-
react_1.default.createElement(StyledButton, { fallbackColor: 'white' }),
|
|
162
|
-
react_1.default.createElement(StyledButton2, { color: 'white' }),
|
|
163
|
-
react_1.default.createElement(FlatList, null),
|
|
164
|
-
react_1.default.createElement(Box2, null),
|
|
165
|
-
react_1.default.createElement(ColorCircle, { color: "#236AFF", onLayout: (e) => { console.log(e.nativeEvent.layout); } }),
|
|
166
|
-
react_1.default.createElement(Dot, { style: dotStyle }),
|
|
167
|
-
react_1.default.createElement(CustomTouchable, { style: {}, ...touchableProps, activeOpacity: 0, extra: 'test' },
|
|
168
|
-
react_1.default.createElement(ExtendedComp, { style: {}, text: 'notest' }))));
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
169
23
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
exports.
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.RemContext = exports.FontSizeContext = exports.SharedValue = exports.cssToRNStyle = void 0;
|
|
26
|
+
const RN = __importStar(require("react-native"));
|
|
27
|
+
require("./polyfill");
|
|
28
|
+
const styleComponent_1 = __importStar(require("./styleComponent"));
|
|
29
|
+
var cssToRN_1 = require("./cssToRN");
|
|
30
|
+
Object.defineProperty(exports, "cssToRNStyle", { enumerable: true, get: function () { return cssToRN_1.cssToRNStyle; } });
|
|
31
|
+
var styleComponent_2 = require("./styleComponent");
|
|
32
|
+
Object.defineProperty(exports, "SharedValue", { enumerable: true, get: function () { return styleComponent_2.SharedValue; } });
|
|
33
|
+
Object.defineProperty(exports, "FontSizeContext", { enumerable: true, get: function () { return styleComponent_2.FontSizeContext; } });
|
|
34
|
+
Object.defineProperty(exports, "RemContext", { enumerable: true, get: function () { return styleComponent_2.RemContext; } });
|
|
35
|
+
__exportStar(require("./useTheme"), exports);
|
|
36
|
+
const styled = (Component) => (0, styleComponent_1.default)(Component);
|
|
37
|
+
styled.ActivityIndicator = styled(RN.ActivityIndicator);
|
|
38
|
+
styled.DrawerLayoutAndroid = styled(RN.DrawerLayoutAndroid);
|
|
39
|
+
styled.Image = styled(RN.Image);
|
|
40
|
+
styled.ImageBackground = styled(RN.ImageBackground);
|
|
41
|
+
styled.KeyboardAvoidingView = styled(RN.KeyboardAvoidingView);
|
|
42
|
+
styled.Modal = styled(RN.Modal);
|
|
43
|
+
styled.NavigatorIOS = styled(RN.NavigatorIOS);
|
|
44
|
+
styled.ScrollView = styled(RN.ScrollView);
|
|
45
|
+
styled.SnapshotViewIOS = styled(RN.SnapshotViewIOS);
|
|
46
|
+
styled.Switch = styled(RN.Switch);
|
|
47
|
+
styled.RecyclerViewBackedScrollView = styled(RN.RecyclerViewBackedScrollView);
|
|
48
|
+
styled.RefreshControl = styled(RN.RefreshControl);
|
|
49
|
+
styled.SafeAreaView = styled(RN.SafeAreaView);
|
|
50
|
+
styled.Text = styled(RN.Text);
|
|
51
|
+
styled.TextInput = styled(RN.TextInput);
|
|
52
|
+
styled.TouchableHighlight = styled(RN.TouchableHighlight);
|
|
53
|
+
styled.TouchableNativeFeedback = styled(RN.TouchableNativeFeedback);
|
|
54
|
+
styled.TouchableOpacity = styled(RN.TouchableOpacity);
|
|
55
|
+
styled.TouchableWithoutFeedback = styled(RN.TouchableWithoutFeedback);
|
|
56
|
+
styled.View = styled(RN.View);
|
|
57
|
+
styled.FlatList = styleComponent_1.styledFlatList;
|
|
58
|
+
styled.SectionList = styleComponent_1.styledSectionList;
|
|
59
|
+
styled.VirtualizedList = styleComponent_1.styledVirtualizedList;
|
|
60
|
+
exports.default = styled;
|
package/dist/styleComponent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { MouseEvent } from 'react';
|
|
2
|
-
import { FlatListProps,
|
|
2
|
+
import { FlatListProps, SectionListProps, StyleProp, TouchableHighlightProps, ViewProps, VirtualizedListProps } from 'react-native';
|
|
3
3
|
import type { CompleteStyle, Units } from './types';
|
|
4
4
|
export declare const defaultUnits: Units;
|
|
5
5
|
export declare const RemContext: React.Context<number>;
|
|
@@ -15,9 +15,16 @@ declare type Functs<T> = (arg: T & {
|
|
|
15
15
|
}) => Primitive;
|
|
16
16
|
declare type OptionalProps = {
|
|
17
17
|
rnCSS?: `${string};`;
|
|
18
|
+
onFocus?: TouchableHighlightProps['onFocus'];
|
|
19
|
+
onBlur?: TouchableHighlightProps['onBlur'];
|
|
20
|
+
onPressIn?: TouchableHighlightProps['onPressIn'];
|
|
21
|
+
onPressOut?: TouchableHighlightProps['onPressOut'];
|
|
22
|
+
onResponderStart?: ViewProps['onResponderStart'];
|
|
23
|
+
onResponderRelease?: ViewProps['onResponderRelease'];
|
|
24
|
+
onStartShouldSetResponder?: ViewProps['onStartShouldSetResponder'];
|
|
18
25
|
onMouseEnter?: (event: MouseEvent) => void;
|
|
19
26
|
onMouseLeave?: (event: MouseEvent) => void;
|
|
20
|
-
onLayout?:
|
|
27
|
+
onLayout?: ViewProps['onLayout'];
|
|
21
28
|
children?: React.ReactNode;
|
|
22
29
|
};
|
|
23
30
|
declare const styled: <StyleType, InitialProps extends {
|
package/dist/styleComponent.js
CHANGED
|
@@ -58,22 +58,34 @@ const styled = (Component) => {
|
|
|
58
58
|
const css = react_1.default.useMemo(() => buildCSSString(chunks, functs, props, shared), [props, shared]);
|
|
59
59
|
// Store the style in RN format
|
|
60
60
|
const rnStyle = react_1.default.useMemo(() => (0, cssToRN_1.default)(css), [css]);
|
|
61
|
-
const { needsLayout, needsHover } = react_1.default.useMemo(() => ({
|
|
61
|
+
const { needsLayout, needsHover, needsFocus, needsTouch } = react_1.default.useMemo(() => ({
|
|
62
62
|
// needsFontSize: !!css.match(/\b(\d+)(\.\d+)?em\b/)
|
|
63
63
|
// needsScreenSize: !!css.match(/\b(\d+)(\.\d*)?v([hw]|min|max)\b/) || !!rnStyle.media,
|
|
64
64
|
needsLayout: !!css.match(/\d%/),
|
|
65
|
-
needsHover: !!rnStyle.hover
|
|
66
|
-
|
|
65
|
+
needsHover: !!rnStyle.hover,
|
|
66
|
+
needsTouch: !!rnStyle.active,
|
|
67
|
+
needsFocus: !!rnStyle.focus
|
|
68
|
+
}), [css, rnStyle.active, rnStyle.focus, rnStyle.hover]);
|
|
67
69
|
// Handle hover
|
|
68
70
|
const { onMouseEnter, onMouseLeave, hover } = (0, features_1.useHover)(props.onMouseEnter, props.onMouseLeave, needsHover);
|
|
71
|
+
// Handle active
|
|
72
|
+
const { onPressIn, onPressOut, onStartShouldSetResponder, onResponderRelease, onResponderStart, active } = (0, features_1.useActive)(props.onPressIn, props.onPressOut, props.onResponderStart, props.onResponderRelease, props.onStartShouldSetResponder, needsTouch);
|
|
73
|
+
// Handle focus
|
|
74
|
+
const { onFocus, onBlur, focused } = (0, features_1.useFocus)(props.onFocus, props.onBlur, needsFocus);
|
|
69
75
|
const tempStyle = react_1.default.useMemo(() => {
|
|
70
76
|
const style = { ...rnStyle };
|
|
71
77
|
delete style.media;
|
|
72
78
|
delete style.hover;
|
|
79
|
+
delete style.active;
|
|
80
|
+
delete style.focus;
|
|
81
|
+
if (focused)
|
|
82
|
+
Object.assign(style, rnStyle.focus);
|
|
73
83
|
if (hover)
|
|
74
84
|
Object.assign(style, rnStyle.hover);
|
|
85
|
+
if (active)
|
|
86
|
+
Object.assign(style, rnStyle.active);
|
|
75
87
|
return style;
|
|
76
|
-
}, [hover, rnStyle]);
|
|
88
|
+
}, [active, focused, hover, rnStyle]);
|
|
77
89
|
// Calculate current em unit for media-queries
|
|
78
90
|
const parentEm = react_1.default.useContext(exports.FontSizeContext);
|
|
79
91
|
const { em: tempEm } = (0, features_1.useFontSize)(tempStyle.fontSize, rem, parentEm);
|
|
@@ -111,12 +123,24 @@ const styled = (Component) => {
|
|
|
111
123
|
return { style: getStyle(hash, style), hash };
|
|
112
124
|
}, [finalStyle, units]);
|
|
113
125
|
const newProps = react_1.default.useMemo(() => {
|
|
114
|
-
const newProps = {
|
|
126
|
+
const newProps = {
|
|
127
|
+
style: [styleConvertedFromCSS, props.style],
|
|
128
|
+
onMouseEnter,
|
|
129
|
+
onMouseLeave,
|
|
130
|
+
onLayout,
|
|
131
|
+
onFocus,
|
|
132
|
+
onBlur,
|
|
133
|
+
onPressIn,
|
|
134
|
+
onPressOut,
|
|
135
|
+
onStartShouldSetResponder,
|
|
136
|
+
onResponderStart,
|
|
137
|
+
onResponderRelease
|
|
138
|
+
};
|
|
115
139
|
if (finalStyle.textOverflow === 'ellipsis') {
|
|
116
140
|
Object.assign(newProps, { numberOfLines: 1 });
|
|
117
141
|
}
|
|
118
142
|
return newProps;
|
|
119
|
-
}, [finalStyle.textOverflow, onLayout, onMouseEnter, onMouseLeave, props.style, styleConvertedFromCSS]);
|
|
143
|
+
}, [finalStyle.textOverflow, onBlur, onFocus, onLayout, onMouseEnter, onMouseLeave, onPressIn, onPressOut, onStartShouldSetResponder, onResponderRelease, onResponderStart, props.style, styleConvertedFromCSS]);
|
|
120
144
|
react_1.default.useEffect(() => () => removeStyle(hash), [hash]);
|
|
121
145
|
// em !== parentEm alone is a bit dangerous as the component would rerender when the font size change
|
|
122
146
|
if (em !== parentEm || finalStyle.fontSize !== undefined) {
|
package/dist/types.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ export declare type PartialStyle = Partial<Record<keyof CompleteStyle, string>>
|
|
|
67
67
|
};
|
|
68
68
|
export declare type Style = PartialStyle & {
|
|
69
69
|
hover?: PartialStyle;
|
|
70
|
+
active?: PartialStyle;
|
|
71
|
+
focus?: PartialStyle;
|
|
70
72
|
media?: MediaQuery[];
|
|
71
73
|
};
|
|
72
74
|
export declare type MediaQuery = (context: Context) => false | PartialStyle;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-css",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"test": "jest",
|
|
6
|
-
"prepare": "tsc",
|
|
6
|
+
"prepare": "rm -rf dist && tsc",
|
|
7
7
|
"android": "react-native run-android",
|
|
8
8
|
"ios": "react-native run-ios",
|
|
9
9
|
"start": "react-native start",
|
package/src/features.tsx
CHANGED
|
@@ -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,7 +57,7 @@ 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
|
|
package/src/styleComponent.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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
8
|
import { useFontSize, useHover, useLayout, useScreenSize, useMediaQuery, useActive, useFocus } from './features'
|
|
@@ -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?: TouchableHighlightProps['onFocus'];
|
|
28
|
+
onBlur?: TouchableHighlightProps['onBlur'];
|
|
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
|
|
package/dist/app.json
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { /* StyleSheet, */ Animated, TextStyle } from 'react-native';
|
|
2
|
-
import type { AnyStyle, PartialStyle, Units } from './types';
|
|
3
|
-
/** Mix the calculated RN style within the object style */
|
|
4
|
-
declare const convertStyle: <T extends AnyStyle | Animated.WithAnimatedObject<import("react-native").ViewStyle> | Animated.WithAnimatedObject<TextStyle> | Animated.WithAnimatedObject<import("react-native").ImageStyle> = AnyStyle>(rnStyle: PartialStyle, units: Units) => T;
|
|
5
|
-
export default convertStyle;
|
package/dist/src/convertStyle.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const convertUnits_1 = require("./convertUnits");
|
|
4
|
-
/** Mix the calculated RN style within the object style */
|
|
5
|
-
const convertStyle = (rnStyle, units) => {
|
|
6
|
-
/** This is the result of the convertions from css style into RN style */
|
|
7
|
-
const convertedStyle = {};
|
|
8
|
-
// If width and height are specified, we can use those values for the first render
|
|
9
|
-
['width', 'height'].forEach(key => {
|
|
10
|
-
if (!units[key] && rnStyle[key]) {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
12
|
-
const converted = (0, convertUnits_1.convertValue)(key, rnStyle[key], units);
|
|
13
|
-
if (!Number.isNaN(converted))
|
|
14
|
-
units[key] = converted;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
Object.keys(rnStyle).forEach(key => {
|
|
18
|
-
const value = rnStyle[key] || '0';
|
|
19
|
-
// Handle object values
|
|
20
|
-
if (key === 'transform' && rnStyle.transform) {
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22
|
-
convertedStyle.transform = rnStyle.transform.map(transformation => {
|
|
23
|
-
const result = {};
|
|
24
|
-
Object.keys(transformation).forEach(k => (result[k] = (0, convertUnits_1.convertValue)(k, transformation[k], units)));
|
|
25
|
-
return result;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
else if (key === 'shadowOffset' && rnStyle.shadowOffset) {
|
|
29
|
-
convertedStyle.shadowOffset = {
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
31
|
-
width: (0, convertUnits_1.convertValue)(key, rnStyle.shadowOffset.width || '0', units),
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
|
-
height: (0, convertUnits_1.convertValue)(key, rnStyle.shadowOffset.height || '0', units)
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
else if (key === 'textShadowOffset' && rnStyle.textShadowOffset) {
|
|
37
|
-
convertedStyle.textShadowOffset = {
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
39
|
-
width: (0, convertUnits_1.convertValue)(key, rnStyle.textShadowOffset.width || '0', units),
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
41
|
-
height: (0, convertUnits_1.convertValue)(key, rnStyle.textShadowOffset.height || '0', units)
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
// Font family should not be transformed (same as cursor for web in case of base64 value)
|
|
45
|
-
else if (['cursor', 'fontFamily'].includes(key)) {
|
|
46
|
-
convertedStyle[key] = value;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
convertedStyle[key] = (0, convertUnits_1.convertValue)(key, value, units);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return convertedStyle;
|
|
55
|
-
};
|
|
56
|
-
exports.default = convertStyle;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { PartialStyle, Transform, Units } from './types';
|
|
2
|
-
/** Take a css value like 12em and return [12, 'em'] */
|
|
3
|
-
export declare function parseValue(value: string): [number, string | undefined];
|
|
4
|
-
/** Convert a value using the provided unit transform table */
|
|
5
|
-
export declare function convertValue(key: keyof PartialStyle | keyof Transform, value: string, units: Units): string | number;
|
package/dist/src/convertUnits.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertValue = exports.parseValue = void 0;
|
|
4
|
-
const maths_1 = require("./cssToRN/maths");
|
|
5
|
-
const react_native_1 = require("react-native");
|
|
6
|
-
/** Take a css value like 12em and return [12, 'em'] */
|
|
7
|
-
function parseValue(value) {
|
|
8
|
-
// Match a single unit
|
|
9
|
-
const unit = value.match(/([+-]?\b\d+(\.\d+)?)([a-z]+\b|%)?/i);
|
|
10
|
-
return [parseFloat(unit[1]), unit[3]];
|
|
11
|
-
}
|
|
12
|
-
exports.parseValue = parseValue;
|
|
13
|
-
/** Convert a value using the provided unit transform table */
|
|
14
|
-
function convertValue(key, value, units) {
|
|
15
|
-
if (typeof value !== 'string') {
|
|
16
|
-
console.error(`Failed to parse CSS instruction: ${key}=${value}. We expect a string, but ${value} was of type ${typeof value}.`);
|
|
17
|
-
return 0;
|
|
18
|
-
}
|
|
19
|
-
// colors should be left untouched
|
|
20
|
-
if (value.startsWith('#'))
|
|
21
|
-
return value;
|
|
22
|
-
// Percentage values need to rely on an other unit as reference
|
|
23
|
-
const finalUnits = { ...units };
|
|
24
|
-
if (value.includes('%')) {
|
|
25
|
-
if (react_native_1.Platform.OS === 'web')
|
|
26
|
-
return value;
|
|
27
|
-
if (['marginTop', 'marginBottom', 'translateY'].includes(key))
|
|
28
|
-
finalUnits['%'] = units.height / 100;
|
|
29
|
-
else if (['marginLeft', 'marginRight', 'translateX'].includes(key))
|
|
30
|
-
finalUnits['%'] = units.width / 100;
|
|
31
|
-
else if (key.startsWith('border') && key.endsWith('Radius'))
|
|
32
|
-
finalUnits['%'] = (units.width + units.height) / 200;
|
|
33
|
-
else if (['width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', 'top', 'left', 'bottom', 'right', 'flexBasis', 'rotate3d'].includes(key)) {
|
|
34
|
-
if (value.startsWith('calc') || value.startsWith('max') || value.startsWith('min')) {
|
|
35
|
-
if (['height', 'minHeight', 'maxHeight', 'top', 'bottom'].includes(key))
|
|
36
|
-
finalUnits['%'] = units.height / 100;
|
|
37
|
-
else
|
|
38
|
-
finalUnits['%'] = units.width / 100;
|
|
39
|
-
}
|
|
40
|
-
// width: 100%, height: 100% are supported
|
|
41
|
-
else
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
else if (['lineHeight'].includes(key))
|
|
45
|
-
finalUnits['%'] = units.em / 100;
|
|
46
|
-
else
|
|
47
|
-
finalUnits['%'] = 0.01;
|
|
48
|
-
}
|
|
49
|
-
// We replace all units within the value
|
|
50
|
-
const convertedValue = value.replace(/(\b\d+(\.\d+)?)([a-z]+\b|%)/ig, occ => {
|
|
51
|
-
const [val, unit] = parseValue(occ);
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
53
|
-
if (['deg', 'rad', 'turn', 's'].includes(unit))
|
|
54
|
-
return occ; // We don't want to convert deg, rad, turn, second units
|
|
55
|
-
return val * (finalUnits[unit || 'px']) + '';
|
|
56
|
-
});
|
|
57
|
-
// We handle extra calculations (calc, min, max, parsing...)
|
|
58
|
-
if (convertedValue.startsWith('calc('))
|
|
59
|
-
return (0, maths_1.calculate)(convertedValue.substring(4)); // remove calc. We can keep the parenthesis
|
|
60
|
-
else if (convertedValue.startsWith('max('))
|
|
61
|
-
return (0, maths_1.max)(convertedValue.substring(4, convertedValue.length - 1)); // Remove max()
|
|
62
|
-
else if (convertedValue.startsWith('min('))
|
|
63
|
-
return (0, maths_1.min)(convertedValue.substring(4, convertedValue.length - 1)); // remove min()
|
|
64
|
-
else if (key === 'fontWeight')
|
|
65
|
-
return convertedValue; // fontWeight must be a string even when it is an integer value.
|
|
66
|
-
else if (parseFloat(convertedValue) + '' === convertedValue)
|
|
67
|
-
return parseFloat(convertedValue);
|
|
68
|
-
else
|
|
69
|
-
return convertedValue;
|
|
70
|
-
}
|
|
71
|
-
exports.convertValue = convertValue;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { Style, Transform } from '../types';
|
|
2
|
-
/** Parse a css value for border */
|
|
3
|
-
export declare function border(value: string): {
|
|
4
|
-
[x: string]: string;
|
|
5
|
-
};
|
|
6
|
-
/** Parse a css value for border-like elements */
|
|
7
|
-
export declare function borderLike(prefixKey: 'outline' | 'borderLeft' | 'borderRight' | 'borderTop' | 'borderBottom', value: string): {
|
|
8
|
-
[x: string]: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function shadow(prefix: 'textShadow' | 'shadow', value: string): {
|
|
11
|
-
[x: string]: string | {
|
|
12
|
-
width: string;
|
|
13
|
-
height: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export declare function flex(value: string): {
|
|
17
|
-
flexBasis: string;
|
|
18
|
-
flexGrow?: undefined;
|
|
19
|
-
flexShrink?: undefined;
|
|
20
|
-
} | {
|
|
21
|
-
flexGrow: string;
|
|
22
|
-
flexBasis: string;
|
|
23
|
-
flexShrink?: undefined;
|
|
24
|
-
} | {
|
|
25
|
-
flexGrow: string;
|
|
26
|
-
flexShrink: string;
|
|
27
|
-
flexBasis: string;
|
|
28
|
-
};
|
|
29
|
-
export declare function flexFlow(value: string): {
|
|
30
|
-
[prop: string]: string;
|
|
31
|
-
};
|
|
32
|
-
export declare function placeContent(value: string): {
|
|
33
|
-
alignContent: string;
|
|
34
|
-
justifyContent: string;
|
|
35
|
-
};
|
|
36
|
-
export declare function background(value: string): {
|
|
37
|
-
backgroundColor: string | undefined;
|
|
38
|
-
};
|
|
39
|
-
export declare function textDecoration(value: string): {
|
|
40
|
-
textDecorationLine: string;
|
|
41
|
-
textDecorationStyle: string;
|
|
42
|
-
textDecorationColor: string;
|
|
43
|
-
};
|
|
44
|
-
export declare function transform(value: string): {
|
|
45
|
-
transform: Transform[];
|
|
46
|
-
};
|
|
47
|
-
export declare function font(value: string): Style;
|
|
48
|
-
/** Parses a css value for the side of an element (border-width, margin, padding) */
|
|
49
|
-
export declare function sideValue<T extends 'padding' | 'margin' | 'border'>(prefixKey: T, value: string, postFix?: T extends 'border' ? 'Width' | 'Style' | 'Color' | '' : ''): {
|
|
50
|
-
[x: string]: string;
|
|
51
|
-
};
|
|
52
|
-
/** Parses a css value for the corner of an element (border-radius) */
|
|
53
|
-
export declare function cornerValue(prefixKey: 'border', value: string, postFix: 'Radius'): {
|
|
54
|
-
[x: string]: string;
|
|
55
|
-
};
|