Skip to content

Commit

Permalink
Merge branch 'fix/skyline' into feat/4.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
yushijie1 committed Nov 19, 2024
2 parents 7029f3e + 52a7378 commit 4fbb58c
Show file tree
Hide file tree
Showing 63 changed files with 1,164 additions and 82 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>;
}
2 changes: 1 addition & 1 deletion packages/shared/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@ export const voidElements = new Set([
export const nestElements = new Map([
['view', -1],
['catch-view', -1],
['click-view', -1],
['cover-view', -1],
['static-view', -1],
['pure-view', -1],
['click-view', -1],
['block', -1],
['text', -1],
['static-text', 6],
Expand Down
9 changes: 7 additions & 2 deletions packages/shared/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,11 @@ export class BaseTemplate {
style: comp.style,
class: comp.class
}

result['click-view'] = {
style: comp.style,
class: comp.class,
bindtap: 'eh'
...this.getClickEvent()
}
}
}
Expand Down Expand Up @@ -412,9 +413,9 @@ export class BaseTemplate {
case 'slot':
case 'slot-view':
case 'catch-view':
case 'click-view':
case 'static-view':
case 'pure-view':
case 'click-view':
nodeName = 'view'
break
case 'static-text':
Expand Down Expand Up @@ -515,6 +516,10 @@ export class BaseTemplate {
return events
}

protected getClickEvent (): any {
return { bindtap: 'eh' }
}

protected getAttrValue (value: string, _key: string, _nodeName: string) {
return `{${value}}`
}
Expand Down
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-skyline
*/
onSizeUpdateWorklet?: CommonEventFunction
}

/**
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
* @supported weapp-skyline
* @default false
*/
fadeIn?: boolean
Expand Down
24 changes: 24 additions & 0 deletions packages/taro-components/types/Input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ interface InputProps extends StandardProps, FormItemProps {
* @supported weapp, alipay, swan, tt, qq, jd, rn, harmony
*/
cursor?: number
/** 光标颜色。iOS 下的格式为十六进制颜色值 #000000,安卓下的只支持 default 和 green,Skyline 下无限制
* @supported weapp
*/
cursorColor?: string
/** 光标起始位置,自动聚集时有效,需与selection-end搭配使用
* @default -1
* @supported weapp, alipay, swan, tt, qq, jd, rn
Expand Down Expand Up @@ -194,6 +198,26 @@ interface InputProps extends StandardProps, FormItemProps {
* @supported weapp
*/
onNickNameReview?: CommonEventFunction
/** 选区改变事件, {selectionStart, selectionEnd}
* @supported weapp-skyline
*/
onSelectionChange?: CommonEventFunction
/** 输入法开始新的输入时触发 (仅当输入法支持时触发)
* @supported weapp-skyline
*/
onKeyboardCompositionStart?: CommonEventFunction
/** 输入法输入字符时触发(仅当输入法支持时触发)
* @supported weapp-skyline
*/
onKeyboardCompositionUpdate?: CommonEventFunction
/** 输入法输入结束时触发(仅当输入法支持时触发)
* @supported weapp-skyline
*/
onKeyboardCompositionEnd?: CommonEventFunction
/** 键盘高度变化时触发。event.detail = {height: height, pageBottomPadding: pageBottomPadding}; height: 键盘高度,pageBottomPadding: 页面上推高度
* @supported weapp-skyline
*/
onKeyoardHeightChangeWorklet?: CommonEventFunction
}
declare namespace InputProps {
/** Input 类型 */
Expand Down
5 changes: 5 additions & 0 deletions packages/taro-components/types/RichText.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ interface RichTextProps extends StandardProps {
* @supported alipay
*/
onLongtap?: CommonEventFunction
/** 布局兼容模式
* @supported weapp-skyline
* @default default
*/
mode?: 'default' | 'compat' | 'aggressive' | 'inline-block' | 'web'
}
/** 节点类型
* > 现支持两种节点,通过type来区分,分别是元素节点和文本节点,默认是元素节点,在富文本区域里显示的HTML节点 元素节点:type = node*
Expand Down
24 changes: 24 additions & 0 deletions packages/taro-components/types/ScrollView.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ interface ScrollViewProps extends StandardProps {
* @default 'list'
*/
type?: 'list' | 'custom' | 'nested'
/** 关联的滚动容器
* draggable-sheet - 关联 draggable-sheet 组件 3.2.0
* nested-scroll-view - 关联 type=nested 嵌套模式 3.2.0
* pop-gesture - 关联 页面手势返回 3.4.0
* @supported weapp
* @default ''
*/
associativeContainer?: 'draggable-sheet' | 'nested-scroll-view' | 'pop-gesture'
/** 是否反向滚动。一般初始滚动位置是在顶部,反向滚动则是在底部。
* @supported weapp
* @default false
Expand Down Expand Up @@ -289,6 +297,22 @@ interface ScrollViewProps extends StandardProps {
* @supported alipay
*/
onTouchCancel?: CommonEventFunction
/** 同 bindscrollstart,但仅支持 worklet 作为回调
* @supported weapp-skyline
*/
onScrollStartWorklet?: CommonEventFunction
/** bindscroll ,但仅支持 worklet 作为回调
* @supported weapp-skyline
*/
onScrollUpdateWorklet?: CommonEventFunction
/** 同 bindscrollend,但仅支持 worklet 作为回调
* @supported weapp-skyline
*/
onScrollEndWorklet?: CommonEventFunction
/** 指定手指抬起时做惯性滚动的初速度。(velocity: number) => number
* @supported weapp-skyline
*/
adjustDecelerationVelocityWorklet?: TaroGeneral.TFunc
}
declare namespace ScrollViewProps {
interface onScrollDetail {
Expand Down
6 changes: 3 additions & 3 deletions packages/taro-components/types/ShareElement.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ interface ShareElementProps extends StandardProps {
| 'bounceIn'
| 'bounceOut'
| 'bounceInOut'
| 'cubic-bezier(x1,'
| 'cubic-bezier(x1, y1, x2, y2)'
/** 动画帧回调
* @supported weapp
* @supported weapp-skyline
*/
onFrame?: string
onFrameWorklet?: CommonEventFunction
}
/** 共享元素
*
Expand Down
6 changes: 6 additions & 0 deletions packages/taro-components/types/StickyHeader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ interface StickyHeaderProps extends StandardProps {
* @default [0, 0, 0, 0]
*/
padding?: [number, number, number, number]
/**
* 吸顶状态变化事件,仅支持非 worklet 的组件方法作为回调。event.detail = { isStickOnTop },当 sticky-header 吸顶时为 true,否则为 false。
* @supported weapp
* @version >=3.6.2
*/
onStickOnTopChange?: CommonEventFunction
}

/**
Expand Down
82 changes: 72 additions & 10 deletions packages/taro-components/types/Swiper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@ interface SwiperProps extends StandardProps {
* @supported swan
*/
disableTouchmove?: string
/** 改变 current 时使用动画过渡
* @supported weapp
* @default true
*/
scrollWithAnimation?: boolean
/** 缓存区域大小,值为 1 表示提前渲染上下各一屏区域(swiper 容器大小)
* @supported weapp
* @default 0
*/
cacheExtent?: number
/** swiper11 相关的动效参数,具体见文档 https://swiperjs.com/swiper-api#parameters
* @supported h5
*/
Expand All @@ -171,6 +161,78 @@ interface SwiperProps extends StandardProps {
* @supported alipay
*/
onAnimationEnd?: CommonEventFunction<SwiperProps.onCommonEventDetail>
/** 渲染模式
* @supported weapp-skyline
* @default normal
*/
layoutType?: 'normal' | 'stackLeft' | 'stackRight' | 'tinder' | 'transformer'
/** layout-type 为 transformer 时指定动画类型
* @supported weapp-skyline
* @default scaleAndFade
*/
transformerType?: 'scaleAndFade' | 'accordion' | 'threeD' | 'zoomIn' | 'zoomOut' | 'deepthPage'
/** 指示点动画类型
* @supported weapp-skyline
* @default normal
*/
indicatorType?: 'normal' | 'worm' | 'wormThin' | 'wormUnderground' | 'wormThinUnderground' | 'expand' | 'jump' | 'jumpWithOffset' | 'scroll' | 'scrollFixedCenter' | 'slide' | 'slideUnderground' | 'scale' | 'swap' | 'swapYRotation' | 'color'
/** 指示点四周边距
* @supported weapp-skyline
* @default 10
*/
indicatorMargin?: number
/** 指示点间距
* @supported weapp-skyline
* @default 4
*/
indicatorSpacing?: number
/** 指示点圆角大小
* @supported weapp-skyline
* @default 4
*/
indicatorRadius?: number
/** 指示点宽度
* @supported weapp-skyline
* @default 8
*/
indicatorWidth?: number
/** 指示点高度
* @supported weapp-skyline
* @default 8
*/
indicatorHeight?: number
/** 指示点的相对位置
* @supported weapp-skyline
* @default auto
*/
indicatorAlignment?: [number, number] | string
/** 指示点位置的偏移量
* @supported weapp-skyline
* @default [0, 0]
*/
indicatorOffset?: [number, number]
/** 改变 current 时使用动画过渡
* @supported weapp-skyline
* @default true
*/
scrollWithAnimation?: boolean
/** 缓存区域大小,值为 1 表示提前渲染上下各一屏区域(swiper 容器大小)
* @supported weapp-skyline
* @default 0
*/
cacheExtent?: number
/** 滑动开始时触发,仅支持 worklet 作为回调。event.detail = {dx: dx, dy: dy}
* @supported weapp-skyline
*/
onScrollStartWorklet?: CommonEventFunction
/** 滑动位置更新时触发,仅支持 worklet 作为回调。event.detail = {dx: dx, dy: dy}
* @supported weapp-skyline
*/
onScrollUpdateWorklet?: CommonEventFunction
/** 滑动结束时触发,仅支持 worklet 作为回调。event.detail = {dx: dx, dy: dy}
* @supported weapp-skyline
*/
onScrollEndWorklet?: CommonEventFunction
}
declare namespace SwiperProps {
/** 导致变更的原因 */
Expand Down
21 changes: 21 additions & 0 deletions packages/taro-components/types/Textarea.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,27 @@ interface TextareaProps extends StandardProps, FormItemProps {
* @supported weapp, tt, harmony
*/
onKeyboardHeightChange?: CommonEventFunction<TextareaProps.onKeyboardHeightChangeEventDetail>

/** 需传入对象,格式为 { fontSize: number, fontWeight: string, color: string }
* @supported weapp-skyline
*/
placeholderStyle?: string
/** 选区改变事件, {selectionStart, selectionEnd}
* @supported weapp-skyline
*/
onSelectionChange?: CommonEventFunction
/** 输入法开始新的输入时触发 (仅当输入法支持时触发)
* @supported weapp-skyline
*/
onKeyboardCompositionStart?: CommonEventFunction
/** 输入法输入字符时触发(仅当输入法支持时触发)
* @supported weapp-skyline
*/
onKeyboardCompositionUpdate?: CommonEventFunction
/** 输入法输入结束时触发(仅当输入法支持时触发)
* @supported weapp-skyline
*/
onKeyboardCompositionEnd?: CommonEventFunction
}
declare namespace TextareaProps {
interface onFocusEventDetail {
Expand Down
Loading

0 comments on commit 4fbb58c

Please sign in to comment.