Skip to content

Commit 21ad34d

Browse files
author
yushijie1
committed
fix(skyline): 适配skyline worklet
1 parent def9cd8 commit 21ad34d

61 files changed

Lines changed: 1191 additions & 46 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/swc_plugin_compile_mode/src/tests/attributes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ test!(
4747
<View onClick={handleViewClick}></View>
4848
<View onAnimationStart={() => {}} id={myId}></View>
4949
<Image onLoad={() => {}} id="myImg" />
50+
<View nativeView="view" onScroll={() => {}} onScrollUpdateWorklet="onScrollUpdate" onGestureWorklet="onGesture" shouldResponseOnMoveWorklet="shouldResponseOnMoveCallBack"></View>
5051
</View>
5152
)
5253
}

crates/swc_plugin_compile_mode/src/transform.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ impl TransformVisitor {
342342
Some(jsx_attr_value) => {
343343
match jsx_attr_value {
344344
JSXAttrValue::Lit(Lit::Str(Str { value, .. })) => {
345+
// 处理worklet事件
346+
if is_event {
347+
let event_name_str = event_name.unwrap();
348+
if event_name_str.starts_with("worklet:") {
349+
props.insert(event_name_str, value.to_string());
350+
return false;
351+
}
352+
}
353+
345354
// 静态属性在 xml 中保留即可,jsx 中可以删除
346355
if jsx_attr_name != COMPILE_MODE {
347356
props.insert(miniapp_attr_name, value.to_string());

crates/swc_plugin_compile_mode/src/utils/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ pub fn check_is_event_attr(val: &str) -> bool {
8888
}
8989

9090
pub fn identify_jsx_event_key(val: &str, platform: &str) -> Option<String> {
91+
92+
// 处理worklet事件及callback
93+
// 事件: onScrollUpdateWorklet -> worklet:onscrollupdate
94+
// callback:shouldResponseOnMoveWorklet -> worklet:should-response-on-move
95+
if val.ends_with("Worklet") {
96+
let worklet_name = val.trim_end_matches("Worklet");
97+
if worklet_name.starts_with("on") {
98+
return Some(format!("worklet:{}", worklet_name.to_lowercase()));
99+
} else {
100+
return Some(format!("worklet:{}", to_kebab_case(worklet_name)));
101+
}
102+
}
103+
91104
if check_is_event_attr(val) {
92105
let event_name = val.get(2..).unwrap().to_lowercase();
93106
let event_name = if event_name == "click" {
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view bindtap="eh" data-sid="{{i.cn[0].sid}}" id="{{i.cn[0].sid}}"></view><view bindanimationstart="eh" data-sid="{{i.cn[1].sid}}" id="{{i.cn[1].uid}}"></view><image bindload="eh" data-sid="{{i.cn[2].sid}}" id="myImg"></image></view></template>';
1+
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view bindtap="eh" data-sid="{{i.cn[0].sid}}" id="{{i.cn[0].sid}}"></view><view bindanimationstart="eh" data-sid="{{i.cn[1].sid}}" id="{{i.cn[1].uid}}"></view><image bindload="eh" data-sid="{{i.cn[2].sid}}" id="myImg"></image><view bindscroll="eh" data-sid="{{i.cn[3].sid}}" id="{{i.cn[3].sid}}" native-view="view" worklet:ongesture="onGesture" worklet:onscrollupdate="onScrollUpdate" worklet:should-response-on-move="shouldResponseOnMoveCallBack"></view></view></template>';
22
function Index() {
33
return <View compileMode="f0t0">
4+
45
<View onClick={handleViewClick}></View>
5-
<View onAnimationStart={() => {}} id={myId}></View>
6-
<Image onLoad={() => {}} />
7-
</View>
6+
7+
<View onAnimationStart={()=>{}} id={myId}></View>
8+
9+
<Image onLoad={()=>{}}/>
10+
11+
<View onScroll={()=>{}}></View>
12+
13+
</View>;
814
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# taro-double-tap-gesture-handler-core
2+
3+
4+
5+
<!-- Auto Generated Below -->
6+
7+
8+
----------------------------------------------
9+
10+
*Built with [StencilJS](https://stenciljs.com/)*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component, ComponentInterface, h, Host } from '@stencil/core'
2+
3+
import { notSupport } from '../../utils'
4+
5+
@Component({
6+
tag: 'taro-double-tap-gesture-handler-core'
7+
})
8+
export class DoubleTapGestureHandler implements ComponentInterface {
9+
componentDidLoad () {
10+
notSupport('DoubleTapGestureHandler', this)
11+
}
12+
13+
render () {
14+
return (
15+
<Host />
16+
)
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# taro-force-press-gesture-handler-core
2+
3+
4+
5+
<!-- Auto Generated Below -->
6+
7+
8+
----------------------------------------------
9+
10+
*Built with [StencilJS](https://stenciljs.com/)*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component, ComponentInterface, h, Host } from '@stencil/core'
2+
3+
import { notSupport } from '../../utils'
4+
5+
@Component({
6+
tag: 'taro-force-press-gesture-handler-core'
7+
})
8+
export class ForcePressGestureHandler implements ComponentInterface {
9+
componentDidLoad () {
10+
notSupport('ForcePressGestureHandler', this)
11+
}
12+
13+
render () {
14+
return (
15+
<Host />
16+
)
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# taro-horizontal-drag-gesture-handler-core
2+
3+
4+
5+
<!-- Auto Generated Below -->
6+
7+
8+
----------------------------------------------
9+
10+
*Built with [StencilJS](https://stenciljs.com/)*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component, ComponentInterface, h, Host } from '@stencil/core'
2+
3+
import { notSupport } from '../../utils'
4+
5+
@Component({
6+
tag: 'taro-horizontal-drag-gesture-handler-core'
7+
})
8+
export class HorizontalDragGestureHandler implements ComponentInterface {
9+
componentDidLoad () {
10+
notSupport('HorizontalDragGestureHandler', this)
11+
}
12+
13+
render () {
14+
return (
15+
<Host />
16+
)
17+
}
18+
}

0 commit comments

Comments
 (0)