ui-rn 1.0.5 → 1.0.7
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/Example/index.tsx +15 -24
- package/package.json +3 -2
- package/src/Icon/PropsStyle.tsx +3 -3
- package/src/Icon/index.tsx +15 -11
- package/src/Icon/makeProps.ts +48 -0
- package/src/Loading/Loading.tsx +107 -0
- package/src/Loading/LoadingType.tsx +24 -0
- package/src/Loading/index.tsx +22 -0
- package/src/Text/Props.ts +3 -2
- package/src/Text/Style.ts +4 -22
- package/src/Text/makeStyle.ts +84 -0
- package/src/Touch/Block.tsx +2 -2
- package/src/Touch/Props.ts +37 -122
- package/src/Touch/Style.ts +6 -109
- package/src/Touch/Touch.tsx +2 -2
- package/src/Touch/makeStyle.ts +85 -0
- package/src/Touch/utils.ts +0 -1
- package/src/config.ts +3 -3
- package/src/index.tsx +3 -1
package/Example/index.tsx
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
import { StyleSheet, Text, View } from 'react-native'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import {
|
|
4
|
-
export default function
|
|
5
|
-
const diameter = width
|
|
6
|
-
const radius = (diameter / 2)
|
|
7
|
-
const m = (Math.sqrt(3) / 2) * radius// Math.sin(60) * radius //-> x
|
|
8
|
-
const n = (1 / 2) * radius//Math.cos(60) * radius//-> y
|
|
9
|
-
const hexagonPoints = [
|
|
10
|
-
{ x: radius, y: 0 },
|
|
11
|
-
{ x: radius + m, y: radius - n },//60
|
|
12
|
-
{ x: radius + m, y: radius + n },
|
|
13
|
-
{ x: radius, y: diameter },//180
|
|
14
|
-
{ x: radius - m, y: radius + n },
|
|
15
|
-
{ x: radius - m, y: radius - n },
|
|
16
|
-
{ x: radius, y: 0 },
|
|
17
|
-
]
|
|
18
|
-
const points = hexagonPoints.map(point => `${point.x},${point.y}`).join(' ');
|
|
1
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Block } from 'ui-rn';
|
|
4
|
+
export default function App() {
|
|
19
5
|
return (
|
|
20
|
-
<View style={
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
</Svg>
|
|
6
|
+
<View style={styles.container}>
|
|
7
|
+
<Text>App</Text>
|
|
8
|
+
<Block></Block>
|
|
24
9
|
</View>
|
|
25
10
|
);
|
|
26
|
-
}
|
|
11
|
+
}
|
|
27
12
|
|
|
28
|
-
const styles = StyleSheet.create({
|
|
13
|
+
const styles = StyleSheet.create({
|
|
14
|
+
container: {
|
|
15
|
+
flex: 1,
|
|
16
|
+
justifyContent: 'center',
|
|
17
|
+
alignItems: 'center',
|
|
18
|
+
},
|
|
19
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ui-rn",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"repository": "https://github.com/phamha98/ui-rn",
|
|
5
5
|
"description": "ui-rn",
|
|
6
6
|
"author": "Phamha98",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"@types/underscore": "^1.11.15",
|
|
11
11
|
"validate-color": "^2.2.4",
|
|
12
12
|
"react-native-safe-area-view": "^1.1.1",
|
|
13
|
-
"react-native-linear-gradient": "^2.8.3"
|
|
13
|
+
"react-native-linear-gradient": "^2.8.3",
|
|
14
|
+
"react-native-indicators": "^0.17.0"
|
|
14
15
|
},
|
|
15
16
|
"scripts": {
|
|
16
17
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/src/Icon/PropsStyle.tsx
CHANGED
|
@@ -14,9 +14,10 @@ import {
|
|
|
14
14
|
} from 'react-native'
|
|
15
15
|
|
|
16
16
|
import { isArray, isEmpty, isNumber, isObject, isString } from "underscore";
|
|
17
|
-
|
|
17
|
+
import { MakeProp } from "./makeProps";
|
|
18
|
+
export interface Props extends MakeProp {
|
|
18
19
|
name: string
|
|
19
|
-
size?: number
|
|
20
|
+
size?: number
|
|
20
21
|
type?: keyof typeof RNVectorIcon
|
|
21
22
|
onPress?: () => void
|
|
22
23
|
styleContainer?: StyleProp<ViewStyle>
|
|
@@ -28,5 +29,4 @@ export interface Props {
|
|
|
28
29
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
type size = 18 | 20 | 22 | 23 | 24 | 25 | 26 | 28 | 30 | 32 | 34 | 36
|
|
32
32
|
|
package/src/Icon/index.tsx
CHANGED
|
@@ -39,26 +39,31 @@ export const RNVectorIcon = {
|
|
|
39
39
|
}
|
|
40
40
|
export type IconType = keyof typeof RNVectorIcon
|
|
41
41
|
import { Props, } from './PropsStyle'
|
|
42
|
-
import {
|
|
42
|
+
import { makeProps } from './makeProps'
|
|
43
43
|
export default class IconApp extends React.PureComponent<Props> {
|
|
44
44
|
static defaultProps: Props = {
|
|
45
45
|
size: 23,
|
|
46
46
|
color: 'gray',
|
|
47
47
|
name: 'home',
|
|
48
48
|
}
|
|
49
|
+
res: { color: string, style: any, size: number }
|
|
50
|
+
constructor(props) {
|
|
51
|
+
super(props)
|
|
52
|
+
this.res = makeProps(props)
|
|
53
|
+
}
|
|
49
54
|
render() {
|
|
55
|
+
const { size, color, style } = this.res
|
|
56
|
+
console.debug('res', this.res)
|
|
50
57
|
if (this.props.name === "none") return null
|
|
51
58
|
const IconView = RNVectorIcon[this.props.type || 'Ionicons']
|
|
52
59
|
if (typeof this.props.onPress != "function") {
|
|
53
60
|
return (
|
|
54
61
|
<IconView
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
color={Colors(this.props.color) ?? this.props.color}
|
|
62
|
+
size={size}
|
|
63
|
+
color={color}
|
|
64
|
+
style={style}
|
|
59
65
|
name={this.props.name}
|
|
60
66
|
onPress={this.props.onPress}
|
|
61
|
-
style={this.props.style as any}
|
|
62
67
|
/>
|
|
63
68
|
)
|
|
64
69
|
}
|
|
@@ -76,13 +81,12 @@ export default class IconApp extends React.PureComponent<Props> {
|
|
|
76
81
|
this.props.styleContainer,
|
|
77
82
|
|
|
78
83
|
]} >
|
|
79
|
-
<IconView
|
|
80
|
-
size={
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
<IconView
|
|
85
|
+
size={size}
|
|
86
|
+
color={color}
|
|
87
|
+
style={style}
|
|
83
88
|
name={this.props.name}
|
|
84
89
|
onPress={this.props.onPress}
|
|
85
|
-
style={this.props.style as any}
|
|
86
90
|
/>
|
|
87
91
|
</TouchableOpacity>
|
|
88
92
|
)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { isNaN, isNumber } from "underscore";
|
|
3
|
+
enum COLORS { "white" = 1, "red", "blue", "black", "green", "yellow", "pink", "gray", "primary" }
|
|
4
|
+
enum NAMES { "ic_back" = "add-circle", }
|
|
5
|
+
type ColorModifiers = Partial<Record<keyof typeof COLORS, boolean>>;
|
|
6
|
+
type NameModifiers = Partial<Record<keyof typeof NAMES, boolean>>;
|
|
7
|
+
|
|
8
|
+
const SHORT_VARIATIONS = {
|
|
9
|
+
mar: "margin",
|
|
10
|
+
marH: "marginHorizontal",
|
|
11
|
+
marV: "marginVertical",
|
|
12
|
+
marL: "marginLeft",
|
|
13
|
+
marT: "marginTop",
|
|
14
|
+
marR: "marginRight",
|
|
15
|
+
marB: "marginBottom",
|
|
16
|
+
zIndex: 'zIndex',
|
|
17
|
+
opacity: 'opacity',
|
|
18
|
+
size: 'size',
|
|
19
|
+
|
|
20
|
+
};
|
|
21
|
+
export type ShortKey = keyof typeof SHORT_VARIATIONS;
|
|
22
|
+
export type Convert<T extends string> = Partial<Record<T, boolean | number | string>>
|
|
23
|
+
export type MakeProp = Convert<ShortKey> & ColorModifiers & NameModifiers
|
|
24
|
+
|
|
25
|
+
export const makeProps = (props: { [key: string]: any }) => {
|
|
26
|
+
const style: { [key: string]: number | string } = {};
|
|
27
|
+
let res = { size: props.size ?? 23, color: props.color ?? 'gray', name: props.name ?? 'home' }
|
|
28
|
+
Object.keys(props).forEach((key) => {
|
|
29
|
+
const match = key.match(/^(\w+)-(\w+)$/) as string[]
|
|
30
|
+
console.debug('COLORS11', key, COLORS[key])
|
|
31
|
+
if (COLORS[key]) {
|
|
32
|
+
console.debug('COLORS22', match)
|
|
33
|
+
res['color'] = key
|
|
34
|
+
}
|
|
35
|
+
if (NAMES[key]) {
|
|
36
|
+
let match = key.match(/^(\w+)_(\w+)$/) as string[]
|
|
37
|
+
res['name'] = NAMES[match[1]]
|
|
38
|
+
}
|
|
39
|
+
else if (match) {
|
|
40
|
+
const value = isNaN(parseInt(match[2], 10)) ? match[2] : parseInt(match[2], 10)
|
|
41
|
+
if (match[1] == 'size') res['size'] = parseInt(match[2], 10)
|
|
42
|
+
else if (match[1] == 'color') res['color'] = match[2]
|
|
43
|
+
else if (SHORT_VARIATIONS[match[1]]) style[SHORT_VARIATIONS[match[1]]] = value
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
return { ...res, style: StyleSheet.create({ style }).style }
|
|
48
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React, { PureComponent } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
Dimensions,
|
|
4
|
+
Modal,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
View,
|
|
8
|
+
ViewProps,
|
|
9
|
+
Text
|
|
10
|
+
} from 'react-native'
|
|
11
|
+
import LoadingType, { LoadingTypeI } from './LoadingType'
|
|
12
|
+
export type Props = {
|
|
13
|
+
boxStyle?: ViewProps['style']
|
|
14
|
+
containerStyle?: ViewProps['style']
|
|
15
|
+
}
|
|
16
|
+
type State = {
|
|
17
|
+
visible: boolean,
|
|
18
|
+
touch: boolean,
|
|
19
|
+
progress: number,
|
|
20
|
+
progressShow: boolean,
|
|
21
|
+
type: LoadingTypeI
|
|
22
|
+
}
|
|
23
|
+
export default class Loading extends PureComponent<Props, State> {
|
|
24
|
+
state: State
|
|
25
|
+
constructor(props: any) {
|
|
26
|
+
super(props)
|
|
27
|
+
this.state = {
|
|
28
|
+
visible: false,
|
|
29
|
+
touch: false,
|
|
30
|
+
progress: 0,
|
|
31
|
+
progressShow: false,
|
|
32
|
+
type: 'BallIndicator'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
show(touch = true) {
|
|
36
|
+
this.setState({ visible: true, touch })
|
|
37
|
+
}
|
|
38
|
+
hide() {
|
|
39
|
+
this.setState({ visible: false, progress: 0, progressShow: false })
|
|
40
|
+
}
|
|
41
|
+
openProgress(e: any) { this.setState(prev => ({ ...prev, ...e })) }
|
|
42
|
+
onPressOut() {
|
|
43
|
+
if (this.state.touch) {
|
|
44
|
+
this.hide()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
componentDidMount(): void {
|
|
49
|
+
}
|
|
50
|
+
componentWillUnmount(): void {
|
|
51
|
+
}
|
|
52
|
+
renderIcon() {
|
|
53
|
+
if (this.state.type) return React.createElement(LoadingType[this.state.type], { color: '#4481EB' })
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
renderProgress() {
|
|
57
|
+
if (this.state.progressShow) {
|
|
58
|
+
return (<Text style={styles.text}>{this.state.progress}{'%'}</Text>)
|
|
59
|
+
}
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
return (
|
|
64
|
+
<Modal
|
|
65
|
+
visible={this.state.visible}
|
|
66
|
+
transparent
|
|
67
|
+
style={{ zIndex: 999999 }}
|
|
68
|
+
>
|
|
69
|
+
<TouchableOpacity onPress={() => this.onPressOut()}
|
|
70
|
+
activeOpacity={1} style={[styles.container, this.props.containerStyle]}>
|
|
71
|
+
<View style={[styles.box, this.props.boxStyle]}>
|
|
72
|
+
{this.renderProgress()}
|
|
73
|
+
{this.renderIcon()}
|
|
74
|
+
</View>
|
|
75
|
+
</TouchableOpacity>
|
|
76
|
+
</Modal>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const styles = StyleSheet.create({
|
|
81
|
+
container: {
|
|
82
|
+
flex: 1,
|
|
83
|
+
justifyContent: 'center',
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
backgroundColor: '#06060660',
|
|
86
|
+
},
|
|
87
|
+
box: {
|
|
88
|
+
width: Dimensions.get('screen').width * 0.25,
|
|
89
|
+
height: Dimensions.get('screen').width * 0.25,
|
|
90
|
+
backgroundColor: '#fff',
|
|
91
|
+
justifyContent: 'center',
|
|
92
|
+
alignItems: 'center',
|
|
93
|
+
borderRadius: 16,
|
|
94
|
+
shadowColor: '#000',
|
|
95
|
+
elevation: 3,
|
|
96
|
+
shadowOffset: {
|
|
97
|
+
width: 3,
|
|
98
|
+
height: 5,
|
|
99
|
+
},
|
|
100
|
+
shadowOpacity: 0.1,
|
|
101
|
+
},
|
|
102
|
+
text: {
|
|
103
|
+
position: 'absolute',
|
|
104
|
+
fontSize: 10,
|
|
105
|
+
color: '#4481EB'
|
|
106
|
+
},
|
|
107
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BallIndicator,
|
|
3
|
+
BarIndicator,
|
|
4
|
+
DotIndicator,
|
|
5
|
+
MaterialIndicator,
|
|
6
|
+
PacmanIndicator,
|
|
7
|
+
PulseIndicator,
|
|
8
|
+
SkypeIndicator,
|
|
9
|
+
UIActivityIndicator,
|
|
10
|
+
WaveIndicator,
|
|
11
|
+
} from 'react-native-indicators';
|
|
12
|
+
const LoadingType = {
|
|
13
|
+
BallIndicator,
|
|
14
|
+
BarIndicator,
|
|
15
|
+
DotIndicator,
|
|
16
|
+
MaterialIndicator,
|
|
17
|
+
PacmanIndicator,
|
|
18
|
+
PulseIndicator,
|
|
19
|
+
SkypeIndicator,
|
|
20
|
+
UIActivityIndicator,
|
|
21
|
+
WaveIndicator,
|
|
22
|
+
}
|
|
23
|
+
export type LoadingTypeI = keyof typeof LoadingType
|
|
24
|
+
export default LoadingType
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { PureComponent, ReactNode } from "react"
|
|
2
|
+
import RNLoading, { Props } from "./Loading"
|
|
3
|
+
|
|
4
|
+
const loadingRef = React.createRef<RNLoading>()
|
|
5
|
+
export class Loading {
|
|
6
|
+
static show() {
|
|
7
|
+
loadingRef.current?.show()
|
|
8
|
+
}
|
|
9
|
+
static hide() {
|
|
10
|
+
loadingRef.current?.hide()
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export default class LoadingView extends PureComponent<Props> {
|
|
14
|
+
render(): ReactNode {
|
|
15
|
+
return (
|
|
16
|
+
|
|
17
|
+
<RNLoading ref={loadingRef} {...this.props} />
|
|
18
|
+
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/Text/Props.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { TextProps, TextStyle } from 'react-native'
|
|
3
3
|
import { IColor, ILanguage } from '../config'
|
|
4
|
+
import { MakeProp } from './makeStyle'
|
|
4
5
|
interface PropsParent {
|
|
5
6
|
children?: React.ReactNode
|
|
6
7
|
bold?: boolean | TextStyle['fontWeight']
|
|
@@ -11,10 +12,10 @@ interface PropsParent {
|
|
|
11
12
|
color?: string | Array<IColor>
|
|
12
13
|
toUpperCase?: boolean
|
|
13
14
|
toLowerCase?: boolean
|
|
14
|
-
flex1?: boolean; flex2?: boolean; flex3?: boolean; flex4?: boolean; flex5?: boolean; flex6?: boolean; flex7?: boolean; flex8?: boolean; flex9?: boolean;
|
|
15
15
|
background?: string | Array<ILanguage>
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
export interface Props extends TextProps, PropsParent, MakeProp {
|
|
18
19
|
backgroundColor?: string
|
|
19
20
|
primary?: boolean
|
|
20
21
|
white?: boolean
|
package/src/Text/Style.ts
CHANGED
|
@@ -1,40 +1,22 @@
|
|
|
1
1
|
import { Colors } from "../config";
|
|
2
2
|
import { StyleProp, ViewStyle, StyleSheet } from "react-native";
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
import { Props } from './Props'
|
|
5
|
+
import { makeStyle } from "./makeStyle";
|
|
5
6
|
export const Style: any = (props: Props, ColorApp = Colors) => {
|
|
6
7
|
const PropsConvert = StyleSheet.flatten([
|
|
7
|
-
props.color && { color:
|
|
8
|
-
props.background && { backgroundColor: props.background },
|
|
9
|
-
props.size && { fontSize: props.size },
|
|
8
|
+
props.color && { color: props.color },
|
|
10
9
|
props.center && { textAlign: 'center' },
|
|
11
10
|
props.italic && { fontStyle: 'italic' },
|
|
12
11
|
props.bold && { fontWeight: typeof props.bold == "boolean" ? '500' : props.bold },
|
|
13
12
|
props.underline && { textDecorationLine: 'underline' },
|
|
14
13
|
props.toUpperCase && { textTransform: 'uppercase' },
|
|
15
14
|
props.toLowerCase && { textTransform: 'lowercase' },
|
|
16
|
-
props.white && { color: "white" }, props.red && { color: "red" },
|
|
17
|
-
props.blue && { color: "blue" }, props.green && { color: "green" },
|
|
18
|
-
props.yellow && { color: "yellow" }, props.pink && { color: "pink" },
|
|
19
|
-
props.gray && { color: "gray" }, props.primary && { color: Colors('primary') },
|
|
20
|
-
props.black && { color: "black" },
|
|
21
|
-
props.flex1 && { flex: 1 }, props.flex2 && { flex: 2 }, props.flex3 && { flex: 3 },
|
|
22
|
-
props.flex4 && { flex: 4 }, props.flex5 && { flex: 5 }, props.flex6 && { flex: 6 },
|
|
23
|
-
props.flex7 && { flex: 7 }, props.flex8 && { flex: 8 }, props.flex9 && { flex: 9 },
|
|
24
|
-
|
|
25
|
-
])
|
|
26
|
-
const PropsApp = StyleSheet.flatten([
|
|
27
15
|
|
|
28
16
|
])
|
|
29
17
|
return [
|
|
30
|
-
|
|
18
|
+
makeStyle(props),
|
|
31
19
|
PropsConvert,
|
|
32
20
|
]
|
|
33
21
|
}
|
|
34
22
|
|
|
35
|
-
const switchArrayValueFromData = (value: any, ColorApp = Colors) => {
|
|
36
|
-
if (isArray(value) && value.length == 1) return ColorApp(value[0])
|
|
37
|
-
if (isString(value) || isNumber(value)) return value
|
|
38
|
-
return undefined
|
|
39
|
-
}
|
|
40
|
-
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { isNaN, isNumber } from "underscore";
|
|
3
|
+
enum COLORS {
|
|
4
|
+
"white" = 1,
|
|
5
|
+
"red",
|
|
6
|
+
"blue",
|
|
7
|
+
"black",
|
|
8
|
+
"green",
|
|
9
|
+
"yellow",
|
|
10
|
+
"pink",
|
|
11
|
+
"gray",
|
|
12
|
+
"primary"
|
|
13
|
+
}
|
|
14
|
+
type ColorModifiers = Partial<Record<keyof typeof COLORS, boolean>>;
|
|
15
|
+
|
|
16
|
+
const SHORT_VARIATIONS = {
|
|
17
|
+
bg: "backgroundColor",
|
|
18
|
+
background: "backgroundColor",
|
|
19
|
+
color: "color",
|
|
20
|
+
w: "width",
|
|
21
|
+
width: "width",
|
|
22
|
+
minW: "minWidth",
|
|
23
|
+
maxW: "maxWidth",
|
|
24
|
+
h: "height",
|
|
25
|
+
height: "height",
|
|
26
|
+
minH: "minHeight",
|
|
27
|
+
maxH: "maxHeight",
|
|
28
|
+
pad: "padding",
|
|
29
|
+
padH: "paddingHorizontal",
|
|
30
|
+
padV: "paddingVertical",
|
|
31
|
+
padL: "paddingLeft",
|
|
32
|
+
padT: "paddingTop",
|
|
33
|
+
padR: "paddingRight",
|
|
34
|
+
padB: "paddingBottom",
|
|
35
|
+
mar: "margin",
|
|
36
|
+
marH: "marginHorizontal",
|
|
37
|
+
marV: "marginVertical",
|
|
38
|
+
marL: "marginLeft",
|
|
39
|
+
marT: "marginTop",
|
|
40
|
+
marR: "marginRight",
|
|
41
|
+
marB: "marginBottom",
|
|
42
|
+
border: 'borderWidth',
|
|
43
|
+
borderW: 'borderWidth',
|
|
44
|
+
borderR: "borderRadius",
|
|
45
|
+
borderC: "borderColor",
|
|
46
|
+
borderLW: "borderLeftWidth",
|
|
47
|
+
borderTW: "borderTopWidth",
|
|
48
|
+
borderRW: "borderRightWidth",
|
|
49
|
+
borderBW: "borderBottomWidth",
|
|
50
|
+
flex: 'flex',
|
|
51
|
+
zIndex: 'zIndex',
|
|
52
|
+
left: 'left',
|
|
53
|
+
top: 'top',
|
|
54
|
+
bottom: 'bottom',
|
|
55
|
+
right: 'right',
|
|
56
|
+
opacity: 'opacity',
|
|
57
|
+
//
|
|
58
|
+
size: 'fontSize'
|
|
59
|
+
};
|
|
60
|
+
export type ShortKey = keyof typeof SHORT_VARIATIONS;
|
|
61
|
+
export type Convert<T extends string> = Partial<Record<T, boolean | number | string>>
|
|
62
|
+
export type MakeProp = Convert<ShortKey> & ColorModifiers
|
|
63
|
+
|
|
64
|
+
export const makeStyle = (props: { [key: string]: any }) => {
|
|
65
|
+
const style: { [key: string]: number | string } = {};
|
|
66
|
+
Object.keys(props).forEach((key) => {
|
|
67
|
+
const match = key.match(/^(\w+)-(\w+)$/) as string[]
|
|
68
|
+
if (COLORS[key]) {
|
|
69
|
+
style['colors'] = key
|
|
70
|
+
}
|
|
71
|
+
else if (match) {
|
|
72
|
+
const value = isNaN(parseInt(match[2], 10)) ? match[2] : parseInt(match[2], 10)
|
|
73
|
+
if (SHORT_VARIATIONS[match[1]]) style[SHORT_VARIATIONS[match[1]]] = value
|
|
74
|
+
else style[match[1]] = value
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (SHORT_VARIATIONS[key]) {
|
|
78
|
+
style[SHORT_VARIATIONS[key]] = props[key]
|
|
79
|
+
}
|
|
80
|
+
// else style[key] = props[key]
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return StyleSheet.create({ style }).style;
|
|
84
|
+
};
|
package/src/Touch/Block.tsx
CHANGED
|
@@ -16,12 +16,12 @@ const Block = React.forwardRef<TouchableOpacityRef, Props>(({ style, ...props },
|
|
|
16
16
|
colors={props.background}
|
|
17
17
|
start={props.gradient == "vertical" ? { x: 0, y: 0 } : { x: 0, y: 0 }}
|
|
18
18
|
end={props.gradient == "vertical" ? { x: 0, y: 1 } : { x: 1, y: 0 }}
|
|
19
|
-
style={[Style(props), style
|
|
19
|
+
style={[Style(props), style]}>
|
|
20
20
|
{props.children}
|
|
21
21
|
</LinearGradient >
|
|
22
22
|
)
|
|
23
23
|
//@ts-ignore
|
|
24
|
-
return (<View ref={ref} style={[Style(props), style
|
|
24
|
+
return (<View ref={ref} style={[Style(props), style]}
|
|
25
25
|
{...props}>
|
|
26
26
|
{props.children}
|
|
27
27
|
</View>
|
package/src/Touch/Props.ts
CHANGED
|
@@ -1,134 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IColor } from "../config"
|
|
2
2
|
import { StyleProp, FlexStyle, TouchableWithoutFeedbackProps, ViewStyle } from "react-native"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
w?: FlexStyle['width']
|
|
9
|
-
h?: FlexStyle['height']
|
|
10
|
-
pad?: N
|
|
11
|
-
padH?: N
|
|
12
|
-
padV?: N
|
|
13
|
-
padL?: N
|
|
14
|
-
padT?: N
|
|
15
|
-
padR?: N
|
|
16
|
-
padB?: N
|
|
17
|
-
flex?: N
|
|
18
|
-
mar?: N
|
|
19
|
-
marH?: N
|
|
20
|
-
marV?: N
|
|
21
|
-
marL?: N
|
|
22
|
-
marT?: N
|
|
23
|
-
marR?: N
|
|
24
|
-
marB?: N
|
|
25
|
-
minW?: N
|
|
26
|
-
maxW?: N
|
|
27
|
-
minH?: N
|
|
28
|
-
maxH?: N
|
|
29
|
-
borderC?: S | Array<color>
|
|
30
|
-
borderW?: N | Array<border>
|
|
31
|
-
borderLW?: N | Array<border>
|
|
32
|
-
borderTW?: N | Array<border>
|
|
33
|
-
borderRW?: N | Array<border>
|
|
34
|
-
borderBW?: N | Array<border>
|
|
35
|
-
borderR?: N | Array<size>
|
|
36
|
-
borderUpRadius?: N | Array<size>
|
|
37
|
-
borderDownRadius?: N | Array<size>
|
|
3
|
+
import { MakeProp } from "./makeStyle"
|
|
4
|
+
|
|
5
|
+
export interface PropsApp {
|
|
6
|
+
borderUpRadius?: number
|
|
7
|
+
borderDownRadius?: number
|
|
38
8
|
alignItems?: FlexStyle['alignItems']
|
|
39
9
|
alignSelf?: FlexStyle['alignSelf']
|
|
40
10
|
justifyContent?: FlexStyle['justifyContent']
|
|
41
11
|
borderStyle?: ViewStyle['borderStyle']
|
|
42
12
|
opacity?: ViewStyle['opacity']
|
|
43
13
|
overflow?: ViewStyle['overflow']
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
overH?: B //old
|
|
59
|
-
w100?: B //old
|
|
60
|
-
h100?: B //old
|
|
61
|
-
width?: FlexStyle['width']//old
|
|
62
|
-
height?: FlexStyle['height']//old
|
|
63
|
-
borderR100?: boolean
|
|
64
|
-
//
|
|
65
|
-
mid?: B
|
|
66
|
-
row?: B
|
|
67
|
-
alignCenter?: B
|
|
68
|
-
justifyCenter?: B
|
|
69
|
-
borderCircle?: B
|
|
70
|
-
centerBetween?: B
|
|
71
|
-
justifyBetween?: B
|
|
72
|
-
overHidden?: B
|
|
73
|
-
square?: N
|
|
74
|
-
width100?: B
|
|
75
|
-
height100?: B
|
|
76
|
-
white?: B
|
|
77
|
-
red?: B
|
|
78
|
-
blue?: B
|
|
79
|
-
black?: B
|
|
80
|
-
green?: B
|
|
81
|
-
yellow?: B
|
|
82
|
-
pink?: B
|
|
83
|
-
gray?: B
|
|
84
|
-
primary?: B
|
|
85
|
-
background?: Array<ColorName> | Array<(S)> | S
|
|
14
|
+
w100?: boolean
|
|
15
|
+
h100?: boolean
|
|
16
|
+
mid?: boolean
|
|
17
|
+
row?: boolean
|
|
18
|
+
alignCenter?: boolean
|
|
19
|
+
justifyCenter?: boolean
|
|
20
|
+
borderCircle?: boolean
|
|
21
|
+
centerBetween?: boolean
|
|
22
|
+
justifyBetween?: boolean
|
|
23
|
+
overHidden?: boolean
|
|
24
|
+
square?: number
|
|
25
|
+
width100?: boolean
|
|
26
|
+
height100?: boolean
|
|
27
|
+
background?: Array<IColor> | Array<(string)> | string
|
|
86
28
|
gradient?: 'vertical' | 'horizontal'
|
|
87
|
-
flexOne?:
|
|
88
|
-
shadowColor?:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
//recent
|
|
98
|
-
pad5?: B; pad10?: B; pad20?: B;
|
|
99
|
-
padV5?: B; padV10?: B; padV20?: B;
|
|
100
|
-
padH5?: B; padH10?: B; padH20?: B;
|
|
101
|
-
padL5?: B; padL10?: B; padL20?: B;
|
|
102
|
-
padT5?: B; padT10?: B; padT20?: B;
|
|
103
|
-
padR5?: B; padR10?: B; padR20?: B;
|
|
104
|
-
padB5?: B; padB10?: B; padB20?: B;
|
|
105
|
-
//
|
|
106
|
-
mar5?: B; mar10?: B; mar20?: B;
|
|
107
|
-
marH5?: B; marH10?: B; marH20?: B;
|
|
108
|
-
marV5?: B; marV10?: B; marV20?: B;
|
|
109
|
-
marL5?: B; marL10?: B; marL20?: B;
|
|
110
|
-
marT5?: B; marT10?: B; marT20?: B;
|
|
111
|
-
marR5?: B; marR10?: B; marR20?: B;
|
|
112
|
-
marB5?: B; marB10?: B; marB20?: B;
|
|
113
|
-
//
|
|
114
|
-
flex1?: B; flex2?: B; flex3?: B; flex4?: B; flex5?: B; flex6?: B; flex7?: B; flex8?: B; flex9?: B;
|
|
115
|
-
borderR2?: B; borderR5?: B; borderR10?: B; borderR15?: B; borderR20?: B;
|
|
116
|
-
borderW1?: B; borderW2?: B; borderW3?: B; borderW4?: B; borderW5?: B;
|
|
117
|
-
/**'padding30;marginTop6;borderRadius11;' */
|
|
118
|
-
styleChar?: S
|
|
119
|
-
//
|
|
29
|
+
flexOne?: boolean
|
|
30
|
+
shadowColor?: string | boolean
|
|
31
|
+
borderOption?: { top?: number, left?: number, right?: number, bottom?: number, color?: string }
|
|
32
|
+
positionOption?: { top?: number, left?: number, right?: number, bottom?: number }
|
|
33
|
+
paddingOption?: { all?: number, top?: number, left?: number, right?: number, bottom?: number }
|
|
34
|
+
paddingFlex?: { vertical?: number, horizontal?: number }
|
|
35
|
+
marginFlex?: { vertical?: number, horizontal?: number }
|
|
36
|
+
marginOption?: { all?: number, top?: number, left?: number, right?: number, bottom?: number }
|
|
37
|
+
shadowOption?: { color?: string, width?: number, height?: number, opacity?: number, radius?: number, elevation?: number }
|
|
38
|
+
styleChar?: string
|
|
120
39
|
widthScreen?: boolean
|
|
121
40
|
heightScreen?: boolean
|
|
41
|
+
|
|
122
42
|
}
|
|
123
|
-
|
|
43
|
+
|
|
44
|
+
//@ts-ignore
|
|
45
|
+
export interface Props extends TouchableWithoutFeedbackProps, PropsApp, MakeProp {
|
|
124
46
|
children?: React.ReactNode
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* backfaceVisibility:route hidden
|
|
131
|
-
*/
|
|
132
|
-
type size = 0 | 5 | 10 | 15 | 20 | 30 | 40 | 50 | 100
|
|
133
|
-
type color = '#ddd' | '#fff' | '#eee' | '#000' | 'white' | 'blue' | 'green' | 'pink' | 'yellow' | "white" | 'black' | 'blue'
|
|
134
|
-
type border = 0.3 | 0.5 | 0.8 | 1 | 2 | 3 | 4 | 5
|
|
47
|
+
hidden?: boolean
|
|
48
|
+
activeOpacity?: number
|
|
49
|
+
}
|
package/src/Touch/Style.ts
CHANGED
|
@@ -2,53 +2,17 @@ import { StyleProp, ViewStyle, StyleSheet, Dimensions } from "react-native";
|
|
|
2
2
|
import { isArray, isEmpty, isNumber, isObject, isString } from "underscore";
|
|
3
3
|
import { Props } from './Props'
|
|
4
4
|
import { Colors } from "../config";
|
|
5
|
+
import { makeStyle } from "./makeStyle";
|
|
5
6
|
|
|
6
7
|
export const Style: any = (props: Props) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
props.background && { backgroundColor: props.background },
|
|
10
|
-
props.w && { width: props.w },
|
|
11
|
-
props.minW && { minWidth: props.minW },
|
|
12
|
-
props.maxW && { maxWidth: props.maxW },
|
|
13
|
-
props.h && { height: props.h },
|
|
14
|
-
props.minH && { minHeight: props.minH },
|
|
15
|
-
props.maxH && { maxHeight: props.maxH },
|
|
16
|
-
props.pad && { padding: props.pad },
|
|
17
|
-
props.padH && { paddingHorizontal: props.padH },
|
|
18
|
-
props.padV && { paddingVertical: props.padV },
|
|
19
|
-
props.padL && { paddingLeft: props.padL },
|
|
20
|
-
props.padT && { paddingTop: props.padT },
|
|
21
|
-
props.padR && { paddingRight: props.padR },
|
|
22
|
-
props.padB && { paddingBottom: props.padB },
|
|
23
|
-
props.mar && { margin: props.mar },
|
|
24
|
-
props.marH && { marginHorizontal: props.marH },
|
|
25
|
-
props.marV && { marginVertical: props.marV },
|
|
26
|
-
props.marL && { marginLeft: props.marL },
|
|
27
|
-
props.marT && { marginTop: props.marT },
|
|
28
|
-
props.marR && { marginRight: props.marR },
|
|
29
|
-
props.marB && { marginBottom: props.marB },
|
|
30
|
-
//new
|
|
31
|
-
props.borderR && { borderRadius: (props.borderR) },
|
|
32
|
-
props.borderC && { borderColor: (props.borderC) },
|
|
33
|
-
props.borderW && { borderWidth: (props.borderW) },
|
|
34
|
-
props.borderLW && { borderLeftWidth: (props.borderLW) },
|
|
35
|
-
props.borderTW && { borderTopWidth: (props.borderTW) },
|
|
36
|
-
props.borderRW && { borderRightWidth: (props.borderRW) },
|
|
37
|
-
props.borderBW && { borderBottomWidth: (props.borderBW) },
|
|
38
|
-
//new
|
|
8
|
+
|
|
9
|
+
const PropsApp = StyleSheet.flatten([
|
|
39
10
|
props.alignItems && { alignItems: props.alignItems },
|
|
40
11
|
props.justifyContent && { justifyContent: props.justifyContent },
|
|
41
12
|
props.borderStyle && { borderStyle: props.borderStyle },
|
|
42
|
-
props.opacity && { opacity: props.opacity },
|
|
43
13
|
props.overflow && { overflow: props.overflow },
|
|
44
|
-
props.zIndex && { zIndex: props.zIndex },
|
|
45
|
-
|
|
46
|
-
])
|
|
47
|
-
const PropsApp = StyleSheet.flatten([
|
|
48
|
-
props._background && { backgroundColor: props._background },
|
|
49
14
|
props.borderUpRadius && { borderTopLeftRadius: (props.borderUpRadius), borderTopRightRadius: (props.borderUpRadius) },
|
|
50
15
|
props.borderDownRadius && { borderBottomLeftRadius: (props.borderUpRadius), borderBottomRightRadius: (props.borderUpRadius) },
|
|
51
|
-
//
|
|
52
16
|
props.mid && { alignItems: 'center', justifyContent: 'center' },
|
|
53
17
|
props.row && { flexDirection: 'row' },
|
|
54
18
|
props.width100 && { width: '100%' },
|
|
@@ -61,10 +25,6 @@ export const Style: any = (props: Props) => {
|
|
|
61
25
|
props.overHidden && { overflow: 'hidden' },
|
|
62
26
|
props.centerBetween && { alignItems: 'center', justifyContent: 'space-between', },
|
|
63
27
|
|
|
64
|
-
props.white && { backgroundColor: "white" }, props.black && { backgroundColor: "black" }, props.red && { backgroundColor: "red" },
|
|
65
|
-
props.blue && { backgroundColor: "blue" }, props.green && { backgroundColor: "green" },
|
|
66
|
-
props.yellow && { backgroundColor: "yellow" }, props.pink && { backgroundColor: "pink" },
|
|
67
|
-
props.gray && { backgroundColor: "gray" }, props.primary && { backgroundColor: Colors('primary') },
|
|
68
28
|
//
|
|
69
29
|
props.positionOption && {
|
|
70
30
|
position: 'absolute',
|
|
@@ -92,14 +52,6 @@ export const Style: any = (props: Props) => {
|
|
|
92
52
|
borderRightWidth: props.borderOption.right,
|
|
93
53
|
borderColor: props.borderOption.color,
|
|
94
54
|
},
|
|
95
|
-
props.marginFlex && {
|
|
96
|
-
paddingHorizontal: props.marginFlex.horizontal,
|
|
97
|
-
paddingVertical: props.marginFlex.vertical,
|
|
98
|
-
},
|
|
99
|
-
props.paddingFlex && {
|
|
100
|
-
paddingHorizontal: props.paddingFlex.horizontal,
|
|
101
|
-
paddingVertical: props.paddingFlex.vertical,
|
|
102
|
-
},
|
|
103
55
|
!isEmpty(props.shadowOption) && {
|
|
104
56
|
shadowColor: props.shadowOption?.color,
|
|
105
57
|
shadowOffset: {
|
|
@@ -117,71 +69,16 @@ export const Style: any = (props: Props) => {
|
|
|
117
69
|
shadowRadius: 10,
|
|
118
70
|
elevation: 2,
|
|
119
71
|
},
|
|
120
|
-
props.
|
|
121
|
-
props.
|
|
122
|
-
props.padV10 && { paddingVertical: 10 }, props.padV20 && { paddingVertical: 20 },
|
|
123
|
-
props.padH5 && { paddingHorizontal: 5 }, props.padH10 && { paddingHorizontal: 10 },
|
|
124
|
-
props.padH20 && { paddingHorizontal: 20 }, props.padL10 && { paddingLeft: 10 },
|
|
125
|
-
props.padT10 && { paddingTop: 10 }, props.padR10 && { paddingRight: 10 },
|
|
126
|
-
props.padB10 && { paddingBottom: 10 }, props.mar5 && { margin: 5 },
|
|
127
|
-
props.mar10 && { margin: 10 }, props.mar20 && { margin: 20 },
|
|
128
|
-
props.marH5 && { marginHorizontal: 5 }, props.marH10 && { marginHorizontal: 10 },
|
|
129
|
-
props.marH20 && { marginHorizontal: 20 }, props.marV5 && { marginVertical: 5 },
|
|
130
|
-
props.marV10 && { marginVertical: 10 }, props.marV20 && { marginVertical: 20 },
|
|
131
|
-
props.marL10 && { marginLeft: 10 }, props.marT10 && { marginTop: 10 },
|
|
132
|
-
props.marR10 && { marginRight: 10 },
|
|
133
|
-
props.marB5 && { marginBottom: 5 }, props.marB10 && { marginBottom: 10 }, props.marB20 && { marginBottom: 20 },
|
|
134
|
-
/** */
|
|
72
|
+
props.w100 && { width: '100%' },
|
|
73
|
+
props.h100 && { height: '100%' },
|
|
135
74
|
|
|
136
|
-
props.pad5 && { padding: 5 }, props.pad10 && { padding: 10 }, props.pad20 && { padding: 20 },
|
|
137
|
-
props.padV5 && { paddingVertical: 5 }, props.padV10 && { paddingVertical: 10 }, props.padV20 && { paddingVertical: 20 },
|
|
138
|
-
props.padH5 && { paddingHorizontal: 5 }, props.padH10 && { paddingHorizontal: 10 }, props.padH20 && { paddingHorizontal: 20 },
|
|
139
|
-
props.padL5 && { paddingLeft: 5 }, props.padL10 && { paddingLeft: 10 }, props.padL20 && { paddingLeft: 20 },
|
|
140
|
-
props.padT5 && { paddingTop: 5 }, props.padT10 && { paddingTop: 10 }, props.padT20 && { paddingTop: 20 },
|
|
141
|
-
props.padR5 && { paddingRight: 5 }, props.padR10 && { paddingRight: 10 }, props.padR20 && { paddingRight: 20 },
|
|
142
|
-
props.padB5 && { paddingBottom: 5 }, props.padB10 && { paddingBottom: 10 }, props.padB20 && { paddingBottom: 20 },
|
|
143
|
-
//
|
|
144
|
-
props.mar5 && { margin: 5 }, props.mar10 && { margin: 10 }, props.mar20 && { margin: 20 },
|
|
145
|
-
props.marV5 && { marginVertical: 5 }, props.marV10 && { marginVertical: 10 }, props.marV20 && { marginVertical: 20 },
|
|
146
|
-
props.marH5 && { marginHorizontal: 5 }, props.marH10 && { marginHorizontal: 10 }, props.marH20 && { marginHorizontal: 20 },
|
|
147
|
-
props.marL5 && { marginLeft: 5 }, props.marL10 && { marginLeft: 10 }, props.marL20 && { marginLeft: 20 },
|
|
148
|
-
props.marT5 && { marginTop: 5 }, props.marT10 && { marginTop: 10 }, props.marT20 && { marginTop: 20 },
|
|
149
|
-
props.marR5 && { marginRight: 5 }, props.marR10 && { marginRight: 10 }, props.marR20 && { marginRight: 20 },
|
|
150
|
-
props.marB5 && { marginBottom: 5 }, props.marB10 && { marginBottom: 10 }, props.marB20 && { marginBottom: 20 },
|
|
151
|
-
/** */
|
|
152
|
-
|
|
153
|
-
props.flex1 && { flex: 1 }, props.flex2 && { flex: 2 }, props.flex3 && { flex: 3 },
|
|
154
|
-
props.flex4 && { flex: 4 }, props.flex5 && { flex: 5 }, props.flex6 && { flex: 6 },
|
|
155
|
-
props.flex7 && { flex: 7 }, props.flex8 && { flex: 8 }, props.flex9 && { flex: 9 },
|
|
156
|
-
props.borderR2 && { borderRadius: 2 }, props.borderR5 && { borderRadius: 5 },
|
|
157
|
-
props.borderR10 && { borderRadius: 10 }, props.borderR15 && { borderRadius: 15 }, props.borderR20 && { borderRadius: 20 },
|
|
158
|
-
props.borderW1 && { borderWidth: 1 }, props.borderW2 && { borderWidth: 2 },
|
|
159
|
-
props.borderW3 && { borderWidth: 3 }, props.borderW4 && { borderWidth: 4 }, props.borderW5 && { borderWidth: 5 }, ///
|
|
160
|
-
//old
|
|
161
|
-
props.positionA && { position: 'absolute' }, //old
|
|
162
|
-
props.left0 && { left: 0, }, //old
|
|
163
|
-
props.top0 && { top: 0, }, //old
|
|
164
|
-
props.right0 && { right: 0, }, //old
|
|
165
|
-
props.bottom0 && { bottom: 0, }, //old
|
|
166
|
-
props.flexOne && { flex: 1 }, //old
|
|
167
|
-
props.bgW && { backgroundColor: "white" }, //old
|
|
168
|
-
props.centerH && { alignItems: 'center', justifyContent: 'space-between', },//old
|
|
169
|
-
props.overH && { overflow: 'hidden' },//old
|
|
170
|
-
props.w100 && { width: '100%' }, //old
|
|
171
|
-
props.h100 && { height: '100%' }, //old
|
|
172
|
-
props.width && { width: props.width },
|
|
173
|
-
props.height && { height: props.height },
|
|
174
|
-
props.alignI && { alignItems: props.alignI },
|
|
175
|
-
props.justifyC && { justifyContent: props.justifyC },
|
|
176
|
-
props.borderR100 && { borderRadius: 100 },
|
|
177
|
-
//
|
|
178
75
|
props.widthScreen && { width: Dimensions.get('screen').width },
|
|
179
76
|
props.heightScreen && { height: Dimensions.get('screen').height },
|
|
180
77
|
|
|
181
78
|
|
|
182
79
|
])
|
|
183
80
|
return [
|
|
81
|
+
makeStyle(props),
|
|
184
82
|
PropsApp,
|
|
185
|
-
PropsConvert,
|
|
186
83
|
]
|
|
187
84
|
}
|
package/src/Touch/Touch.tsx
CHANGED
|
@@ -21,7 +21,7 @@ const Touch = React.forwardRef<TouchableOpacityRef, Props>(({ style, ...props },
|
|
|
21
21
|
colors={props.background}
|
|
22
22
|
start={props.gradient == "vertical" ? { x: 0, y: 0 } : { x: 0, y: 0 }}
|
|
23
23
|
end={props.gradient == "vertical" ? { x: 0, y: 1 } : { x: 1, y: 0 }}
|
|
24
|
-
style={[Style(props), style
|
|
24
|
+
style={[Style(props), style]}
|
|
25
25
|
>
|
|
26
26
|
{props.children}
|
|
27
27
|
</LinearGradient >
|
|
@@ -31,7 +31,7 @@ const Touch = React.forwardRef<TouchableOpacityRef, Props>(({ style, ...props },
|
|
|
31
31
|
<TouchableOpacity
|
|
32
32
|
ref={ref}
|
|
33
33
|
activeOpacity={props.activeOpacity || 0.5}
|
|
34
|
-
style={[Style(props), style
|
|
34
|
+
style={[Style(props), style]}
|
|
35
35
|
{...props}>
|
|
36
36
|
{props.children}
|
|
37
37
|
</TouchableOpacity>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { isNaN, isNumber } from "underscore";
|
|
3
|
+
enum COLORS {
|
|
4
|
+
"white" = 1,
|
|
5
|
+
"red",
|
|
6
|
+
"blue",
|
|
7
|
+
"black",
|
|
8
|
+
"green",
|
|
9
|
+
"yellow",
|
|
10
|
+
"pink",
|
|
11
|
+
"gray",
|
|
12
|
+
"primary"
|
|
13
|
+
}
|
|
14
|
+
type ColorModifiers = Partial<Record<keyof typeof COLORS, boolean>>;
|
|
15
|
+
|
|
16
|
+
const SHORT_VARIATIONS = {
|
|
17
|
+
bg: "backgroundColor",
|
|
18
|
+
background: "backgroundColor",
|
|
19
|
+
w: "width",
|
|
20
|
+
width: "width",
|
|
21
|
+
minW: "minWidth",
|
|
22
|
+
maxW: "maxWidth",
|
|
23
|
+
h: "height",
|
|
24
|
+
height: "height",
|
|
25
|
+
minH: "minHeight",
|
|
26
|
+
maxH: "maxHeight",
|
|
27
|
+
pad: "padding",
|
|
28
|
+
padH: "paddingHorizontal",
|
|
29
|
+
padV: "paddingVertical",
|
|
30
|
+
padL: "paddingLeft",
|
|
31
|
+
padT: "paddingTop",
|
|
32
|
+
padR: "paddingRight",
|
|
33
|
+
padB: "paddingBottom",
|
|
34
|
+
mar: "margin",
|
|
35
|
+
marH: "marginHorizontal",
|
|
36
|
+
marV: "marginVertical",
|
|
37
|
+
marL: "marginLeft",
|
|
38
|
+
marT: "marginTop",
|
|
39
|
+
marR: "marginRight",
|
|
40
|
+
marB: "marginBottom",
|
|
41
|
+
border: 'borderWidth',
|
|
42
|
+
borderW: 'borderWidth',
|
|
43
|
+
borderR: "borderRadius",
|
|
44
|
+
borderC: "borderColor",
|
|
45
|
+
borderLW: "borderLeftWidth",
|
|
46
|
+
borderTW: "borderTopWidth",
|
|
47
|
+
borderRW: "borderRightWidth",
|
|
48
|
+
borderBW: "borderBottomWidth",
|
|
49
|
+
flex: 'flex',
|
|
50
|
+
zIndex: 'zIndex',
|
|
51
|
+
left: 'left',
|
|
52
|
+
top: 'top',
|
|
53
|
+
bottom: 'bottom',
|
|
54
|
+
right: 'right',
|
|
55
|
+
opacity: 'opacity'
|
|
56
|
+
};
|
|
57
|
+
export type ShortKey = keyof typeof SHORT_VARIATIONS;
|
|
58
|
+
export type Convert<T extends string> = Partial<Record<T, boolean | number | string>>
|
|
59
|
+
export type MakeProp = Convert<ShortKey> & ColorModifiers
|
|
60
|
+
|
|
61
|
+
export const makeStyle = (props: { [key: string]: any }) => {
|
|
62
|
+
const style: { [key: string]: number | string } = {};
|
|
63
|
+
Object.keys(props).forEach((key) => {
|
|
64
|
+
const match = key.match(/^(\w+)-(\w+)$/) as string[]
|
|
65
|
+
console.debug(key, match)
|
|
66
|
+
if (COLORS[key]) {
|
|
67
|
+
style['backgroundColor'] = key
|
|
68
|
+
}
|
|
69
|
+
else if (match) {
|
|
70
|
+
const value = isNaN(parseInt(match[2], 10)) ? match[2] : parseInt(match[2], 10)
|
|
71
|
+
console.debug('value', value)
|
|
72
|
+
console.debug('value', parseInt(match[2], 10))
|
|
73
|
+
console.debug('value', isNumber(parseInt(match[2], 10)))
|
|
74
|
+
if (SHORT_VARIATIONS[match[1]]) style[SHORT_VARIATIONS[match[1]]] = value
|
|
75
|
+
else style[match[1]] = value
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if (SHORT_VARIATIONS[key]) {
|
|
79
|
+
style[SHORT_VARIATIONS[key]] = props[key]
|
|
80
|
+
}
|
|
81
|
+
else style[key] = props[key]
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return StyleSheet.create({ style }).style;
|
|
85
|
+
};
|
package/src/Touch/utils.ts
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export const Colors = (e) => {
|
|
1
|
+
export const Colors = (e: any) => {
|
|
2
2
|
return e
|
|
3
3
|
}
|
|
4
|
-
export const Language = (e) => {
|
|
4
|
+
export const Language = (e: any) => {
|
|
5
5
|
return e
|
|
6
6
|
}
|
|
7
7
|
export type IColor = keyof typeof COLOR
|
|
@@ -33,4 +33,4 @@ export const Icons = {
|
|
|
33
33
|
up: 'chevron-up-outline',
|
|
34
34
|
up1: 'caret-up-outline',
|
|
35
35
|
header: 'heart-outline'
|
|
36
|
-
}
|
|
36
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -2,4 +2,6 @@ export { default as Touch } from './Touch/Touch'
|
|
|
2
2
|
export { default as Block } from './Touch/Block'
|
|
3
3
|
export { default as Text } from './Text'
|
|
4
4
|
export { default as Icon } from './Icon'
|
|
5
|
-
export { default as Layout } from './Layout'
|
|
5
|
+
export { default as Layout } from './Layout'
|
|
6
|
+
export { default as LoadingView } from './Loading'
|
|
7
|
+
export { Loading } from './Loading'
|