revas 1.0.2 → 2.0.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 +61 -1
- package/dist/chunk-JPUKLNW3.js +1710 -0
- package/dist/chunk-JPUKLNW3.js.map +1 -0
- package/dist/revas-common.cjs +1768 -0
- package/dist/revas-common.cjs.map +1 -0
- package/dist/revas-common.d.cts +363 -0
- package/dist/revas-common.d.ts +363 -0
- package/dist/revas-common.js +3 -0
- package/dist/revas-common.js.map +1 -0
- package/dist/revas.cjs +1881 -0
- package/dist/revas.cjs.map +1 -0
- package/dist/revas.d.cts +13 -0
- package/dist/revas.d.ts +13 -0
- package/dist/revas.js +108 -1967
- package/dist/revas.js.map +1 -1
- package/package.json +58 -45
- package/.eslintcache +0 -1
- package/common.d.ts +0 -1
- package/common.js +0 -1
- package/dist/revas.common.js +0 -1861
- package/dist/revas.common.js.map +0 -1
- package/dist/revas.es.js +0 -1932
- package/dist/revas.es.js.map +0 -1
- package/dist/types/develop/App.d.ts +0 -8
- package/dist/types/develop/Intro/About.d.ts +0 -2
- package/dist/types/develop/Intro/Animation.d.ts +0 -2
- package/dist/types/develop/Intro/Component.d.ts +0 -2
- package/dist/types/develop/Intro/Entry.d.ts +0 -6
- package/dist/types/develop/Intro/Gesture.d.ts +0 -2
- package/dist/types/develop/Intro/Interactable.d.ts +0 -10
- package/dist/types/develop/Intro/Navbar.d.ts +0 -6
- package/dist/types/develop/Intro/Panel.d.ts +0 -14
- package/dist/types/develop/Intro/Style.d.ts +0 -2
- package/dist/types/develop/Intro/index.d.ts +0 -2
- package/dist/types/develop/Music/Player.d.ts +0 -79
- package/dist/types/develop/Music/data.d.ts +0 -8
- package/dist/types/develop/Music/index.d.ts +0 -23
- package/dist/types/develop/Music/styles.d.ts +0 -19
- package/dist/types/develop/Timeline/data.d.ts +0 -5
- package/dist/types/develop/Timeline/index.d.ts +0 -11
- package/dist/types/develop/common/back.d.ts +0 -2
- package/dist/types/develop/common/simple-router.d.ts +0 -44
- package/dist/types/develop/serviceWorker.d.ts +0 -7
- package/dist/types/index.d.ts +0 -1
- package/dist/types/revas/common.d.ts +0 -24
- package/dist/types/revas/components/Context.d.ts +0 -12
- package/dist/types/revas/components/Image.d.ts +0 -20
- package/dist/types/revas/components/LinearGradient.d.ts +0 -38
- package/dist/types/revas/components/ListView.d.ts +0 -22
- package/dist/types/revas/components/ScrollView.d.ts +0 -43
- package/dist/types/revas/components/Text.d.ts +0 -16
- package/dist/types/revas/components/Touchable.d.ts +0 -34
- package/dist/types/revas/components/View.d.ts +0 -3
- package/dist/types/revas/components/common/Scroller.d.ts +0 -35
- package/dist/types/revas/components/common/drawImage.d.ts +0 -3
- package/dist/types/revas/components/common/drawText.d.ts +0 -17
- package/dist/types/revas/components/common/imageLoader.d.ts +0 -2
- package/dist/types/revas/core/Animated.d.ts +0 -59
- package/dist/types/revas/core/Canvas.d.ts +0 -17
- package/dist/types/revas/core/Container.d.ts +0 -18
- package/dist/types/revas/core/Node.d.ts +0 -46
- package/dist/types/revas/core/css-layout/index.d.ts +0 -9
- package/dist/types/revas/core/draw.d.ts +0 -4
- package/dist/types/revas/core/offscreen.d.ts +0 -11
- package/dist/types/revas/core/reconciler.d.ts +0 -5
- package/dist/types/revas/core/touch.d.ts +0 -3
- package/dist/types/revas/core/utils.d.ts +0 -22
- package/dist/types/revas/core/yoga-layout/index.d.ts +0 -3
- package/dist/types/revas/core/yoga-layout/init.d.ts +0 -3
- package/dist/types/revas/core/yoga-layout/style.d.ts +0 -3
- package/dist/types/revas/index.d.ts +0 -2
- package/dist/types/revas/web/index.d.ts +0 -1
- package/dist/types/revas/web/render.d.ts +0 -7
- package/doc/API.md +0 -241
- package/doc/README-zh.md +0 -266
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -64
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -2
- package/public/stats.min.js +0 -5
- package/public/touch-emulator.js +0 -363
- package/rollup.config.ts +0 -44
- package/tsconfig.json +0 -30
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare class RevasCanvas {
|
|
2
|
-
readonly transform: Transform;
|
|
3
|
-
constructor(context: CanvasRenderingContext2D);
|
|
4
|
-
get context(): CanvasRenderingContext2D;
|
|
5
|
-
get element(): HTMLCanvasElement;
|
|
6
|
-
}
|
|
7
|
-
export declare class Transform {
|
|
8
|
-
readonly context: CanvasRenderingContext2D;
|
|
9
|
-
_stack: DOMMatrix[];
|
|
10
|
-
_canGetTransform: boolean;
|
|
11
|
-
constructor(context: CanvasRenderingContext2D);
|
|
12
|
-
save(): void;
|
|
13
|
-
restore(): void;
|
|
14
|
-
translate(x: number, y: number): void;
|
|
15
|
-
rotate(rad: number): void;
|
|
16
|
-
scale(sx: number, sy: number): void;
|
|
17
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Node, RevasTouchEvent } from './Node';
|
|
2
|
-
import { RevasCanvas } from './Canvas';
|
|
3
|
-
import { AppContextType } from '../components/Context';
|
|
4
|
-
export declare class Container {
|
|
5
|
-
private _ready;
|
|
6
|
-
private _next;
|
|
7
|
-
private _reflow;
|
|
8
|
-
private _root?;
|
|
9
|
-
get canvas(): RevasCanvas | void;
|
|
10
|
-
get width(): number;
|
|
11
|
-
get height(): number;
|
|
12
|
-
get scale(): number;
|
|
13
|
-
constructor();
|
|
14
|
-
setRoot(root?: Node<AppContextType>): void;
|
|
15
|
-
handleTouch: (evt: RevasTouchEvent) => void;
|
|
16
|
-
draw: (reflow?: boolean) => void;
|
|
17
|
-
private ready;
|
|
18
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
export declare class Frame {
|
|
3
|
-
x: number;
|
|
4
|
-
y: number;
|
|
5
|
-
width: number;
|
|
6
|
-
height: number;
|
|
7
|
-
constructor(x?: number, y?: number, width?: number, height?: number);
|
|
8
|
-
}
|
|
9
|
-
export declare class Node<T = any> {
|
|
10
|
-
readonly type: string;
|
|
11
|
-
props: NodeProps & T;
|
|
12
|
-
readonly children: Node[];
|
|
13
|
-
frame: Frame;
|
|
14
|
-
parent?: Node;
|
|
15
|
-
constructor(type: string, props: NodeProps & T);
|
|
16
|
-
get $ready(): boolean;
|
|
17
|
-
}
|
|
18
|
-
export interface RevasTouch {
|
|
19
|
-
identifier: number;
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
}
|
|
23
|
-
export declare type RevasTouchType = 'touchstart' | 'touchmove' | 'touchend';
|
|
24
|
-
export interface RevasTouchEvent {
|
|
25
|
-
type: RevasTouchType;
|
|
26
|
-
touches: {
|
|
27
|
-
[key: string]: RevasTouch;
|
|
28
|
-
};
|
|
29
|
-
timestamp: number;
|
|
30
|
-
[key: string]: any;
|
|
31
|
-
}
|
|
32
|
-
export declare type RevasTouchEventListener = (event: RevasTouchEvent) => any;
|
|
33
|
-
export interface BaseProps {
|
|
34
|
-
children?: ReactNode;
|
|
35
|
-
style?: any | any[];
|
|
36
|
-
cache?: string | boolean;
|
|
37
|
-
forceCache?: boolean;
|
|
38
|
-
}
|
|
39
|
-
export interface NodeProps extends BaseProps {
|
|
40
|
-
onTouchStart?: RevasTouchEventListener;
|
|
41
|
-
onTouchMove?: RevasTouchEventListener;
|
|
42
|
-
onTouchEnd?: RevasTouchEventListener;
|
|
43
|
-
onLayout?: (frame: Frame) => any;
|
|
44
|
-
pointerEvents?: 'auto' | 'none' | 'box-none';
|
|
45
|
-
$ready?: boolean;
|
|
46
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Node } from '../Node';
|
|
2
|
-
import { AppContextType } from '../../components/Context';
|
|
3
|
-
export interface YogaNode {
|
|
4
|
-
node: Node;
|
|
5
|
-
style: any;
|
|
6
|
-
layout: any;
|
|
7
|
-
children: YogaNode[];
|
|
8
|
-
}
|
|
9
|
-
export declare function updateLayout(root: Node<AppContextType>): () => void;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Node } from './Node';
|
|
2
|
-
import { RevasCanvas } from './Canvas';
|
|
3
|
-
export interface CachedCanvas {
|
|
4
|
-
id: string;
|
|
5
|
-
canvas: RevasCanvas;
|
|
6
|
-
style: any;
|
|
7
|
-
}
|
|
8
|
-
export declare function getCache(id: string): CachedCanvas | undefined;
|
|
9
|
-
export declare function createCache(style: any, w: number, h: number, id: string): CachedCanvas;
|
|
10
|
-
export declare function autoCacheId(node: Node): string | undefined;
|
|
11
|
-
export declare function clearCache(): void;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Node } from './Node';
|
|
2
|
-
import { RevasCanvas } from './Canvas';
|
|
3
|
-
export declare function noop(): any;
|
|
4
|
-
export declare const EMPTY_OBJECT: any;
|
|
5
|
-
export declare const EMPTY_ARRAY: any[];
|
|
6
|
-
export declare function flatten(array: any[]): any[];
|
|
7
|
-
export declare const now: () => number;
|
|
8
|
-
export declare function applyAnimated(style: any, callback?: Function): any;
|
|
9
|
-
export declare function getMergedStyleFromNode(node: Node, callback?: Function): any;
|
|
10
|
-
export declare function getFrameFromNode(node: Node): import("./Node").Frame;
|
|
11
|
-
export declare function sortByZIndexAscending(a: Node, b: Node): number;
|
|
12
|
-
export declare function clamp(n: number, min: number, max: number): number;
|
|
13
|
-
export declare function getChars(str: string): readonly string[];
|
|
14
|
-
export declare function getWords(str: string): readonly string[];
|
|
15
|
-
export declare function setShadow(canvas: RevasCanvas, color: string, x?: number, y?: number, blur?: number): () => void;
|
|
16
|
-
export declare function pushOpacity(canvas: RevasCanvas, opacity: number): typeof noop;
|
|
17
|
-
export declare type RevasAdapter = {
|
|
18
|
-
createImage: () => HTMLImageElement;
|
|
19
|
-
createOffscreenCanvas?: (width: number, height: number) => RevasCanvas;
|
|
20
|
-
resetOffscreenCanvas?: (ctx: RevasCanvas, width: number, height: number) => RevasCanvas;
|
|
21
|
-
};
|
|
22
|
-
export declare const adapter: RevasAdapter;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './render';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Component } from 'react';
|
|
2
|
-
import { noop } from '../core/utils';
|
|
3
|
-
export declare function render(app: React.ReactNode, parent: HTMLElement, parentComponent?: Component<any>, callback?: typeof noop): {
|
|
4
|
-
readonly $: HTMLCanvasElement;
|
|
5
|
-
update(next?: import("react").ReactNode, callback?: typeof noop): void;
|
|
6
|
-
unmount(callback?: typeof noop): void;
|
|
7
|
-
};
|
package/doc/API.md
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
# Revas Document
|
|
2
|
-
|
|
3
|
-
## Install
|
|
4
|
-
|
|
5
|
-
``` bash
|
|
6
|
-
$ yarn add revas react
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
|
|
11
|
-
### Render to a DOM
|
|
12
|
-
```jsx
|
|
13
|
-
import React from 'react'
|
|
14
|
-
import {render, View, Text} from 'revas'
|
|
15
|
-
|
|
16
|
-
render(
|
|
17
|
-
<View style={{ flex: 1 }}>
|
|
18
|
-
<Text style={{ fontSize: 20 }}>Revas</Text>
|
|
19
|
-
</View>,
|
|
20
|
-
document.getElementById('container')
|
|
21
|
-
)
|
|
22
|
-
```
|
|
23
|
-
[](https://codesandbox.io/s/purple-browser-h56ht?fontsize=14&hidenavigation=1&theme=dark)
|
|
24
|
-
|
|
25
|
-
### Render to a DOM rendered by React
|
|
26
|
-
```jsx
|
|
27
|
-
import React from 'react'
|
|
28
|
-
import {render, View, Text} from 'revas'
|
|
29
|
-
|
|
30
|
-
export class Widget extends React.Component {
|
|
31
|
-
componentDidMount() {
|
|
32
|
-
this.app = render(
|
|
33
|
-
<View style={{ flex: 1 }}>
|
|
34
|
-
<Text style={{ fontSize: 20 }}>Revas</Text>
|
|
35
|
-
</View>,
|
|
36
|
-
document.getElementById('container'),
|
|
37
|
-
this
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
componentDidUpdate() {
|
|
41
|
-
this.app.update()
|
|
42
|
-
}
|
|
43
|
-
componentWillUnmount() {
|
|
44
|
-
this.app.unmount()
|
|
45
|
-
}
|
|
46
|
-
render() {
|
|
47
|
-
return <div id="container" />
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
[](https://codesandbox.io/s/reverent-river-vbypp?fontsize=14&hidenavigation=1&theme=dark)
|
|
52
|
-
|
|
53
|
-
## Components
|
|
54
|
-
|
|
55
|
-
### View
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
#### ViewProps
|
|
59
|
-
|
|
60
|
-
| Property | Type | Description |
|
|
61
|
-
| -: | - | - |
|
|
62
|
-
| style | `ViewStyle` | Inline css|
|
|
63
|
-
| pointerEvents | `'auto' \| 'box-none' \| 'none'` | |
|
|
64
|
-
| onLayout | `(Frame): void` | x, y, width, height |
|
|
65
|
-
| onTouchStart | `(RevasTouch): void` | callback |
|
|
66
|
-
| onTouchMove | `(RevasTouch): void` | callback |
|
|
67
|
-
| onTouchEnd | `(RevasTouch): void` | callback |
|
|
68
|
-
| cache | `boolean \| string` | enable offscreen cache |
|
|
69
|
-
| forceCache | `boolean` | force enable cache |
|
|
70
|
-
|
|
71
|
-
```jsx
|
|
72
|
-
<View {...props} />
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Text
|
|
76
|
-
|
|
77
|
-
#### TextProps
|
|
78
|
-
|
|
79
|
-
> extends ViewProps
|
|
80
|
-
|
|
81
|
-
| Property | Type | Description |
|
|
82
|
-
| -: | - | - |
|
|
83
|
-
| style | `TextStyle` | Inline css|
|
|
84
|
-
| numberOfLines | `number` | max lines |
|
|
85
|
-
|
|
86
|
-
```jsx
|
|
87
|
-
<Text numberOfLines={1}>Hello World</Text>
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Image
|
|
91
|
-
|
|
92
|
-
#### ImageProps
|
|
93
|
-
|
|
94
|
-
> extends ViewProps
|
|
95
|
-
|
|
96
|
-
| Property | Type | Description |
|
|
97
|
-
| -: | - | - |
|
|
98
|
-
| style | `ImageStyle` | Inline css|
|
|
99
|
-
| src | string | `Image` source url |
|
|
100
|
-
|
|
101
|
-
```jsx
|
|
102
|
-
<Image src="https://some.img/url.jpg" />
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Touchable
|
|
106
|
-
|
|
107
|
-
#### TouchableProps
|
|
108
|
-
|
|
109
|
-
> extends ViewProps
|
|
110
|
-
|
|
111
|
-
| Property | Type | Description |
|
|
112
|
-
| -: | - | - |
|
|
113
|
-
| onPress | `Function` | callback |
|
|
114
|
-
| onPressIn | `Function` | callback |
|
|
115
|
-
| onPressOut | `Function` | callback |
|
|
116
|
-
| activeOpacity | `number` | opacity when pressing in |
|
|
117
|
-
|
|
118
|
-
```jsx
|
|
119
|
-
<Touchable onPress={() => alert('Enjoy!~🎉')}>
|
|
120
|
-
<Text>Go</Text>
|
|
121
|
-
</Touchable>
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### ScrollView
|
|
125
|
-
|
|
126
|
-
#### ScrollViewProps
|
|
127
|
-
|
|
128
|
-
> extends ViewProps
|
|
129
|
-
|
|
130
|
-
| Property | Type | Description |
|
|
131
|
-
| -: | - | - |
|
|
132
|
-
| horizontal | `boolean` | direction |
|
|
133
|
-
| onScroll | `(RevasScrollEvent): void` | scrolling callback |
|
|
134
|
-
| onScrollStart | `(RevasScrollEvent): void` | scroll start |
|
|
135
|
-
| onScrollEnd | `(RevasScrollEvent): void` | scroll end |
|
|
136
|
-
| paging | `boolean \| number` | enable paging, and the length |
|
|
137
|
-
| offset | `{x: number, y: number}` | offset |
|
|
138
|
-
|
|
139
|
-
```jsx
|
|
140
|
-
<ScrollView>
|
|
141
|
-
{colors.map(renderColorItem)}
|
|
142
|
-
</ScrollView>
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### LinearGradient
|
|
146
|
-
|
|
147
|
-
#### LinearGradientProps
|
|
148
|
-
|
|
149
|
-
> extends ViewProps
|
|
150
|
-
|
|
151
|
-
| Property | Type | Description |
|
|
152
|
-
| -: | - | - |
|
|
153
|
-
| start | `{x: number, y: number}` | start position |
|
|
154
|
-
| end | `{x: number, y: number}` | end position |
|
|
155
|
-
| colors | `Color[]` | colors |
|
|
156
|
-
|
|
157
|
-
```jsx
|
|
158
|
-
<LinearGradient style={styles.decorator}
|
|
159
|
-
start={{x: 0, y, 0}} end={{x: 1, y, 0}}
|
|
160
|
-
colors={['#9254DE', '#B37FEB', '#91D5FF', '#40A9FF']} />
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
### ListView
|
|
164
|
-
|
|
165
|
-
#### ListViewProps
|
|
166
|
-
|
|
167
|
-
> extends ScrollViewProps
|
|
168
|
-
|
|
169
|
-
| Property | Type | Description |
|
|
170
|
-
| -: | - | - |
|
|
171
|
-
| data | `T[]` | list data |
|
|
172
|
-
| renderItem | `(item, index, data): JSX` | render item |
|
|
173
|
-
| itemHeight | `number` | height of each item |
|
|
174
|
-
|
|
175
|
-
```jsx
|
|
176
|
-
<ListView
|
|
177
|
-
data={[1, 2, 3, 4, 5, 12, 123, 1, 23, 2]}
|
|
178
|
-
getItemHeight={() => 80} renderItem={(item, index) => (
|
|
179
|
-
<View style={{ height: 80, backgroundColor: (index % 2) > 0 ? 'white' : 'black' }} />
|
|
180
|
-
)} />
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## API
|
|
184
|
-
|
|
185
|
-
### render(app: JSX, target: DOM): Renderer
|
|
186
|
-
|
|
187
|
-
> [WEB ONLY] render to a DOM container
|
|
188
|
-
|
|
189
|
-
### new AnimatedValue(number)
|
|
190
|
-
|
|
191
|
-
> animated value
|
|
192
|
-
|
|
193
|
-
```jsx
|
|
194
|
-
import { AnimatedValue } from 'revas'
|
|
195
|
-
|
|
196
|
-
const translateX = new AnimatedValue(0)
|
|
197
|
-
|
|
198
|
-
function Comp() {
|
|
199
|
-
return <View
|
|
200
|
-
style={{
|
|
201
|
-
translateX: translateX
|
|
202
|
-
}}
|
|
203
|
-
onTouchMove={e => {
|
|
204
|
-
translateX.setValue(e.touches[0].x)
|
|
205
|
-
}}
|
|
206
|
-
/>
|
|
207
|
-
}
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### timing(AnimatedValue, Config).start().stop()
|
|
211
|
-
|
|
212
|
-
> start a animation
|
|
213
|
-
|
|
214
|
-
### AnimatedValue.interpolate(inputRange: number[], outputRange: number[])
|
|
215
|
-
|
|
216
|
-
> interpolate animated value
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
### withContext(Component)
|
|
220
|
-
|
|
221
|
-
> inject context to a component
|
|
222
|
-
|
|
223
|
-
clientWidth, clientHeight, pixelRatio, canvas
|
|
224
|
-
|
|
225
|
-
## CSS
|
|
226
|
-
|
|
227
|
-
| Category | Styles |
|
|
228
|
-
| -: | - |
|
|
229
|
-
| Flexible Layout | **width**, minWidth, maxWidth, **height**, minHeight, maxHeight, **padding**, paddingLeft, **margin**, marginLeft, position, left, top, **flex**, flexDirection, justifyContent, alignItems [...more](https://github.com/pinqy520/revas/blob/master/src/revas/core/yoga-layout/style.ts)|
|
|
230
|
-
| Box | borderRadius, borderWidth, borderColor, borderTopLeftRadius, shadowColor, shadowOffsetX, shadowOffsetY, shadowBlur, backgroundColor, overflow, opacity |
|
|
231
|
-
| Text | fontFamily, fontSize, fontWeight, color, lineHeight, textAlign, wordBreak, fontStyle, textBaseline, textShadowBlur, textShadowColor, textShadowOffsetX, textShadowOffsetY |
|
|
232
|
-
| Image | resizeMode |
|
|
233
|
-
| Transform | translateX, translateY, rotate, scale, scaleX, scaleY |
|
|
234
|
-
| Other | animated, path |
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
## Advantage
|
|
238
|
-
|
|
239
|
-
### Render to a custom canvas
|
|
240
|
-
|
|
241
|
-
> TODO
|
package/doc/README-zh.md
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
<h1 align="center">
|
|
2
|
-
<img src="https://user-images.githubusercontent.com/5719833/74748305-3fb20680-52a3-11ea-81c3-98804dceb602.png" width=220 />
|
|
3
|
-
<br />
|
|
4
|
-
<a href="https://badge.fury.io/js/revas">
|
|
5
|
-
<img src="https://badge.fury.io/js/revas.svg" alt="npm version" height="18">
|
|
6
|
-
</a>
|
|
7
|
-
</h1>
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
用React和CSS在Canvas上编写高性能交互界面
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
<p align="center">
|
|
14
|
-
<a target="_blank" href="https://pinqy520.github.io/demo/revas-pwa/" rel="nofollow">Live DEMO</a> | <a target="_blank" href="https://github.com/pinqy520/revas/blob/master/src/develop/App.tsx">DEMO Code</a>
|
|
15
|
-
</p>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<p align="center">
|
|
19
|
-
<img src="https://user-images.githubusercontent.com/5719833/81006150-9b8f3300-8e81-11ea-8cb1-08de6550ea03.png" />
|
|
20
|
-
</p>
|
|
21
|
-
|
|
22
|
-
## 安装
|
|
23
|
-
|
|
24
|
-
``` bash
|
|
25
|
-
$ yarn add revas react
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## 基本用法
|
|
29
|
-
|
|
30
|
-
### 直接渲染到DOM元素
|
|
31
|
-
```jsx
|
|
32
|
-
import React from 'react'
|
|
33
|
-
import {render, View, Text} from 'revas'
|
|
34
|
-
|
|
35
|
-
render(
|
|
36
|
-
<View style={{ flex: 1 }}>
|
|
37
|
-
<Text style={{ fontSize: 20 }}>Revas</Text>
|
|
38
|
-
</View>,
|
|
39
|
-
document.getElementById('container')
|
|
40
|
-
)
|
|
41
|
-
```
|
|
42
|
-
[](https://codesandbox.io/s/purple-browser-h56ht?fontsize=14&hidenavigation=1&theme=dark)
|
|
43
|
-
|
|
44
|
-
### 在ReactDOM中嵌入
|
|
45
|
-
```jsx
|
|
46
|
-
import React from 'react'
|
|
47
|
-
import {render, View, Text} from 'revas'
|
|
48
|
-
|
|
49
|
-
export class Widget extends React.Component {
|
|
50
|
-
componentDidMount() {
|
|
51
|
-
this.app = render(
|
|
52
|
-
<View style={{ flex: 1 }}>
|
|
53
|
-
<Text style={{ fontSize: 20 }}>Revas</Text>
|
|
54
|
-
</View>,
|
|
55
|
-
document.getElementById('container'),
|
|
56
|
-
this
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
componentDidUpdate() {
|
|
60
|
-
this.app.update()
|
|
61
|
-
}
|
|
62
|
-
componentWillUnmount() {
|
|
63
|
-
this.app.unmount()
|
|
64
|
-
}
|
|
65
|
-
render() {
|
|
66
|
-
return <div id="container" />
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
[](https://codesandbox.io/s/reverent-river-vbypp?fontsize=14&hidenavigation=1&theme=dark)
|
|
71
|
-
|
|
72
|
-
## 组件
|
|
73
|
-
|
|
74
|
-
### View
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
#### ViewProps
|
|
78
|
-
|
|
79
|
-
| Property | Type | Description |
|
|
80
|
-
| -: | - | - |
|
|
81
|
-
| style | ViewStyle | Inline css|
|
|
82
|
-
| pointerEvents | `'auto' \| 'box-none' \| 'none'` | 点击事件接受类型 |
|
|
83
|
-
| onLayout | `(Frame): void` | 获取当前布局 |
|
|
84
|
-
| onTouchStart | `(RevasTouch): void` | 开始触碰回调 |
|
|
85
|
-
| onTouchMove | `(RevasTouch): void` | 触碰移动回调 |
|
|
86
|
-
| onTouchEnd | `(RevasTouch): void` | 结束触碰回调 |
|
|
87
|
-
| cache | `boolean \| string` | 开启离屏缓存 |
|
|
88
|
-
| forceCache | `boolean` | 不等待子组件加载完毕就缓存 |
|
|
89
|
-
|
|
90
|
-
```jsx
|
|
91
|
-
<View {...props} />
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Text
|
|
95
|
-
|
|
96
|
-
#### TextProps
|
|
97
|
-
|
|
98
|
-
> extends ViewProps
|
|
99
|
-
|
|
100
|
-
| Property | Type | Description |
|
|
101
|
-
| -: | - | - |
|
|
102
|
-
| style | `TextStyle` | Inline css|
|
|
103
|
-
| numberOfLines | `number` | 最多多少行 |
|
|
104
|
-
|
|
105
|
-
```jsx
|
|
106
|
-
<Text numberOfLines={1}>Hello World</Text>
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Image
|
|
110
|
-
|
|
111
|
-
#### ImageProps
|
|
112
|
-
|
|
113
|
-
> extends ViewProps
|
|
114
|
-
|
|
115
|
-
| Property | Type | Description |
|
|
116
|
-
| -: | - | - |
|
|
117
|
-
| style | ImageStyle | Inline css|
|
|
118
|
-
| src | string | Image source url |
|
|
119
|
-
|
|
120
|
-
```jsx
|
|
121
|
-
<Image src="https://some.img/url.jpg" />
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Touchable
|
|
125
|
-
|
|
126
|
-
#### TouchableProps
|
|
127
|
-
|
|
128
|
-
> extends ViewProps
|
|
129
|
-
|
|
130
|
-
| Property | Type | Description |
|
|
131
|
-
| -: | - | - |
|
|
132
|
-
| onPress | `Function` | 点击回调 |
|
|
133
|
-
| onPressIn | `Function` | 点按回调 |
|
|
134
|
-
| onPressOut | `Function` | 点按弹起回调 |
|
|
135
|
-
| activeOpacity | `number` | 点击的时候透明度 |
|
|
136
|
-
|
|
137
|
-
```jsx
|
|
138
|
-
<Touchable onPress={() => alert('Enjoy!~🎉')}>
|
|
139
|
-
<Text>Go</Text>
|
|
140
|
-
</Touchable>
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### ScrollView
|
|
144
|
-
|
|
145
|
-
#### ScrollViewProps
|
|
146
|
-
|
|
147
|
-
> extends ViewProps
|
|
148
|
-
|
|
149
|
-
| Property | Type | Description |
|
|
150
|
-
| -: | - | - |
|
|
151
|
-
| horizontal | `boolean` | 滑动方向 |
|
|
152
|
-
| onScroll | `(RevasScrollEvent): void` | 滑动回调 |
|
|
153
|
-
| onScrollStart | `(RevasScrollEvent): void` | 滑动开始回调 |
|
|
154
|
-
| onScrollEnd | `(RevasScrollEvent): void` | 滑动停止回调 |
|
|
155
|
-
| paging | `boolean \| number` | 是否开启paging,paging长度 |
|
|
156
|
-
| offset | `{x: number, y: number}` | 相对位移 |
|
|
157
|
-
|
|
158
|
-
```jsx
|
|
159
|
-
<ScrollView>
|
|
160
|
-
{colors.map(renderColorItem)}
|
|
161
|
-
</ScrollView>
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### LinearGradient
|
|
165
|
-
|
|
166
|
-
#### LinearGradientProps
|
|
167
|
-
|
|
168
|
-
> extends ViewProps
|
|
169
|
-
|
|
170
|
-
| Property | Type | Description |
|
|
171
|
-
| -: | - | - |
|
|
172
|
-
| start | `{x: number, y: number}` | 渐变色开始的点 |
|
|
173
|
-
| end | `{x: number, y: number}` | 渐变色结束的点 |
|
|
174
|
-
| colors | `Color[]` | 滑动回调 |
|
|
175
|
-
|
|
176
|
-
```jsx
|
|
177
|
-
<LinearGradient style={styles.decorator}
|
|
178
|
-
start={{x: 0, y, 0}} end={{x: 1, y, 0}}
|
|
179
|
-
colors={['#9254DE', '#B37FEB', '#91D5FF', '#40A9FF']} />
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### ListView
|
|
183
|
-
|
|
184
|
-
#### ListViewProps
|
|
185
|
-
|
|
186
|
-
> extends ScrollViewProps
|
|
187
|
-
|
|
188
|
-
| Property | Type | Description |
|
|
189
|
-
| -: | - | - |
|
|
190
|
-
| data | `T[]` | 数据 |
|
|
191
|
-
| renderItem | `(item, index, data): JSX` |渲染每一行 |
|
|
192
|
-
| itemHeight | `number` | 一行的高度 |
|
|
193
|
-
|
|
194
|
-
```jsx
|
|
195
|
-
<ListView
|
|
196
|
-
data={[1, 2, 3, 4, 5, 12, 123, 1, 23, 2]}
|
|
197
|
-
itemHeight={80} renderItem={(item, index) => (
|
|
198
|
-
<View style={{ height: 80, backgroundColor: (index % 2) > 0 ? 'white' : 'black' }} />
|
|
199
|
-
)} />
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
## API
|
|
203
|
-
|
|
204
|
-
### render(app: JSX, target: DOM): Renderer
|
|
205
|
-
|
|
206
|
-
> [WEB ONLY] 渲染到指定DOM节点里
|
|
207
|
-
|
|
208
|
-
### new AnimatedValue(number)
|
|
209
|
-
|
|
210
|
-
> 控制动画
|
|
211
|
-
|
|
212
|
-
```jsx
|
|
213
|
-
import { AnimatedValue } from 'revas'
|
|
214
|
-
|
|
215
|
-
const translateX = new AnimatedValue(0)
|
|
216
|
-
|
|
217
|
-
function Comp() {
|
|
218
|
-
return <View
|
|
219
|
-
style={{
|
|
220
|
-
translateX: translateX
|
|
221
|
-
}}
|
|
222
|
-
onTouchMove={e => {
|
|
223
|
-
translateX.setValue(e.touches[0].x)
|
|
224
|
-
}}
|
|
225
|
-
/>
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
### timing(AnimatedValue, Config).start().stop()
|
|
230
|
-
|
|
231
|
-
> 配置动画
|
|
232
|
-
|
|
233
|
-
### AnimatedValue.interpolate(inputRange: number[], outputRange: number[])
|
|
234
|
-
|
|
235
|
-
> 配置动画
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
### withContext(Component)
|
|
239
|
-
|
|
240
|
-
> 获取全局参数 clientWidth, clientHeight, pixelRatio, canvas
|
|
241
|
-
|
|
242
|
-
## CSS
|
|
243
|
-
|
|
244
|
-
| Category | Styles |
|
|
245
|
-
| -: | - |
|
|
246
|
-
| Flexible Layout | **width**, minWidth, maxWidth, **height**, minHeight, maxHeight, **padding**, paddingLeft, **margin**, marginLeft, position, left, top, **flex**, flexDirection, justifyContent, alignItems [...more](https://github.com/pinqy520/revas/blob/master/src/revas/core/yoga-layout/style.ts)|
|
|
247
|
-
| Box | borderRadius, borderWidth, borderColor, borderTopLeftRadius, shadowColor, shadowOffsetX, shadowOffsetY, shadowBlur, backgroundColor, overflow, opacity |
|
|
248
|
-
| Text | fontFamily, fontSize, fontWeight, color, lineHeight, textAlign, wordBreak, fontStyle, textBaseline, textShadowBlur, textShadowColor, textShadowOffsetX, textShadowOffsetY |
|
|
249
|
-
| Image | resizeMode |
|
|
250
|
-
| Transform | translateX, translateY, rotate, scale, scaleX, scaleY |
|
|
251
|
-
| Other | animated, path |
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
## 高级用法
|
|
255
|
-
|
|
256
|
-
> 参考DOM渲染函数的编写
|
|
257
|
-
|
|
258
|
-
### 渲染到自定义Canvas容器
|
|
259
|
-
|
|
260
|
-
#### 准备:配置离屏渲染函数
|
|
261
|
-
|
|
262
|
-
#### 第一步:生成RevasCanvas对象
|
|
263
|
-
|
|
264
|
-
#### 第二步:监听Canvas上手势
|
|
265
|
-
|
|
266
|
-
#### 第三部:渲染
|
package/public/favicon.ico
DELETED
|
Binary file
|