Skip to content

Commit

Permalink
fix(skyline): 适配skyline worklet
Browse files Browse the repository at this point in the history
  • Loading branch information
yushijie1 committed Nov 21, 2024
1 parent def9cd8 commit 21ad34d
Show file tree
Hide file tree
Showing 61 changed files with 1,191 additions and 46 deletions.
1 change: 1 addition & 0 deletions crates/swc_plugin_compile_mode/src/tests/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test!(
<View onClick={handleViewClick}></View>
<View onAnimationStart={() => {}} id={myId}></View>
<Image onLoad={() => {}} id="myImg" />
<View nativeView="view" onScroll={() => {}} onScrollUpdateWorklet="onScrollUpdate" onGestureWorklet="onGesture" shouldResponseOnMoveWorklet="shouldResponseOnMoveCallBack"></View>
</View>
)
}
Expand Down
9 changes: 9 additions & 0 deletions crates/swc_plugin_compile_mode/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ impl TransformVisitor {
Some(jsx_attr_value) => {
match jsx_attr_value {
JSXAttrValue::Lit(Lit::Str(Str { value, .. })) => {
// 处理worklet事件
if is_event {
let event_name_str = event_name.unwrap();
if event_name_str.starts_with("worklet:") {
props.insert(event_name_str, value.to_string());
return false;
}
}

// 静态属性在 xml 中保留即可,jsx 中可以删除
if jsx_attr_name != COMPILE_MODE {
props.insert(miniapp_attr_name, value.to_string());
Expand Down
13 changes: 13 additions & 0 deletions crates/swc_plugin_compile_mode/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ pub fn check_is_event_attr(val: &str) -> bool {
}

pub fn identify_jsx_event_key(val: &str, platform: &str) -> Option<String> {

// 处理worklet事件及callback
// 事件: onScrollUpdateWorklet -> worklet:onscrollupdate
// callback:shouldResponseOnMoveWorklet -> worklet:should-response-on-move
if val.ends_with("Worklet") {
let worklet_name = val.trim_end_matches("Worklet");
if worklet_name.starts_with("on") {
return Some(format!("worklet:{}", worklet_name.to_lowercase()));
} else {
return Some(format!("worklet:{}", to_kebab_case(worklet_name)));
}
}

if check_is_event_attr(val) {
let event_name = val.get(2..).unwrap().to_lowercase();
let event_name = if event_name == "click" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
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>';
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>';
function Index() {
return <View compileMode="f0t0">

<View onClick={handleViewClick}></View>
<View onAnimationStart={() => {}} id={myId}></View>
<Image onLoad={() => {}} />
</View>

<View onAnimationStart={()=>{}} id={myId}></View>

<Image onLoad={()=>{}}/>

<View onScroll={()=>{}}></View>

</View>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taro-double-tap-gesture-handler-core



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ComponentInterface, h, Host } from '@stencil/core'

import { notSupport } from '../../utils'

@Component({
tag: 'taro-double-tap-gesture-handler-core'
})
export class DoubleTapGestureHandler implements ComponentInterface {
componentDidLoad () {
notSupport('DoubleTapGestureHandler', this)
}

render () {
return (
<Host />
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taro-force-press-gesture-handler-core



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ComponentInterface, h, Host } from '@stencil/core'

import { notSupport } from '../../utils'

@Component({
tag: 'taro-force-press-gesture-handler-core'
})
export class ForcePressGestureHandler implements ComponentInterface {
componentDidLoad () {
notSupport('ForcePressGestureHandler', this)
}

render () {
return (
<Host />
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taro-horizontal-drag-gesture-handler-core



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ComponentInterface, h, Host } from '@stencil/core'

import { notSupport } from '../../utils'

@Component({
tag: 'taro-horizontal-drag-gesture-handler-core'
})
export class HorizontalDragGestureHandler implements ComponentInterface {
componentDidLoad () {
notSupport('HorizontalDragGestureHandler', this)
}

render () {
return (
<Host />
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taro-long-press-gesture-handler-core



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ComponentInterface, h, Host } from '@stencil/core'

import { notSupport } from '../../utils'

@Component({
tag: 'taro-long-press-gesture-handler-core'
})
export class LongPressGestureHandler implements ComponentInterface {
componentDidLoad () {
notSupport('LongPressGestureHandler', this)
}

render () {
return (
<Host />
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taro-pan-gesture-handler-core



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ComponentInterface, h, Host } from '@stencil/core'

import { notSupport } from '../../utils'

@Component({
tag: 'taro-pan-gesture-handler-core'
})
export class PanGestureHandler implements ComponentInterface {
componentDidLoad () {
notSupport('PanGestureHandler', this)
}

render () {
return (
<Host />
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taro-scale-gesture-handler-core



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ComponentInterface, h, Host } from '@stencil/core'

import { notSupport } from '../../utils'

@Component({
tag: 'taro-scale-gesture-handler-core'
})
export class ScaleGestureHandler implements ComponentInterface {
componentDidLoad () {
notSupport('ScaleGestureHandler', this)
}

render () {
return (
<Host />
)
}
}
10 changes: 10 additions & 0 deletions packages/taro-components/src/components/script/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taro-script-core



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
18 changes: 18 additions & 0 deletions packages/taro-components/src/components/script/script.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ComponentInterface, h, Host } from '@stencil/core'

import { notSupport } from '../../utils'

@Component({
tag: 'taro-script-core'
})
export class Script implements ComponentInterface {
componentDidLoad () {
notSupport('Script', this)
}

render () {
return (
<Host />
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taro-tap-gesture-handler-core



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ComponentInterface, h, Host } from '@stencil/core'

import { notSupport } from '../../utils'

@Component({
tag: 'taro-tap-gesture-handler-core'
})
export class TapGestureHandler implements ComponentInterface {
componentDidLoad () {
notSupport('TapGestureHandler', this)
}

render () {
return (
<Host />
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taro-vertical-drag-gesture-handler-core



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ComponentInterface, h, Host } from '@stencil/core'

import { notSupport } from '../../utils'

@Component({
tag: 'taro-vertical-drag-gesture-handler-core'
})
export class VerticalDragGestureHandler implements ComponentInterface {
componentDidLoad () {
notSupport('VerticalDragGestureHandler', this)
}

render () {
return (
<Host />
)
}
}
5 changes: 5 additions & 0 deletions packages/taro-components/types/DraggableSheet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ interface DraggableSheetProps extends StandardProps {
* @default []
*/
snapSizes?: any[]
/**
* 尺寸发生变化时触发,仅支持 worklet 作为回调。event = {pixels, size}
* @supported weapp
*/
onSizeUpdateWorklet?: string
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components/types/Image.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface ImageProps extends StandardProps {
*/
ariaLabel?: string
/** 是否渐显
* @supported weapp-skyline
* @supported weapp
* @default false
*/
fadeIn?: boolean
Expand Down
12 changes: 8 additions & 4 deletions packages/taro-components/types/Input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,25 @@ interface InputProps extends StandardProps, FormItemProps {
*/
onNickNameReview?: CommonEventFunction
/** 选区改变事件, {selectionStart, selectionEnd}
* @supported weapp-skyline
* @supported weapp
*/
onSelectionChange?: CommonEventFunction
/** 输入法开始新的输入时触发 (仅当输入法支持时触发)
* @supported weapp-skyline
* @supported weapp
*/
onKeyboardCompositionStart?: CommonEventFunction
/** 输入法输入字符时触发(仅当输入法支持时触发)
* @supported weapp-skyline
* @supported weapp
*/
onKeyboardCompositionUpdate?: CommonEventFunction
/** 输入法输入结束时触发(仅当输入法支持时触发)
* @supported weapp-skyline
* @supported weapp
*/
onKeyboardCompositionEnd?: CommonEventFunction
/** 键盘高度变化时触发。event.detail = {height: height, pageBottomPadding: pageBottomPadding}; height: 键盘高度,pageBottomPadding: 页面上推高度
* @supported weapp
*/
onKeyoardHeightChangeWorklet?: string
}
declare namespace InputProps {
/** Input 类型 */
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components/types/RichText.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface RichTextProps extends StandardProps {
*/
onLongtap?: CommonEventFunction
/** 布局兼容模式
* @supported weapp-skyline
* @supported weapp
* @default default
*/
mode?: 'default' | 'compat' | 'aggressive' | 'inline-block' | 'web'
Expand Down
Loading

0 comments on commit 21ad34d

Please sign in to comment.