From ef592ce4159e0d291880a55681d8d1ff022b7484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=86=E8=91=B5?= Date: Wed, 25 Aug 2021 15:09:58 +0800 Subject: [PATCH 1/6] feat(miniapp): support flex in baidu and kuaishou --- packages/miniapp-render/src/constants.js | 13 ++- packages/miniapp-render/src/node/element.js | 2 + .../src/platforms/baidu.js | 85 ++++++------------- 3 files changed, 40 insertions(+), 60 deletions(-) diff --git a/packages/miniapp-render/src/constants.js b/packages/miniapp-render/src/constants.js index e75c7242..5513002d 100644 --- a/packages/miniapp-render/src/constants.js +++ b/packages/miniapp-render/src/constants.js @@ -1,3 +1,6 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { isBaiduSmartProgram } from 'universal-env'; + export const NATIVE_EVENTS_LIST = [ 'onBack', 'onKeyboardHeight', @@ -28,11 +31,15 @@ export const BODY_NODE_ID = 'e-body'; export const INDEX_PAGE = 'index-page'; -export const STATIC_COMPONENTS = new Set(['view', 'text', 'image']); // With no events components +/** + * In Baidu SmartProgram, view and h-element template are modified to support flex, so pure, static and catch elements are omitted + */ + +export const STATIC_COMPONENTS = new Set(isBaiduSmartProgram ? ['text', 'image'] : ['view', 'text', 'image']); // With no events components -export const PURE_COMPONENTS = new Set(['view', 'h-element']); // With no events or props && equal to TOUCH_COMPONENTS +export const PURE_COMPONENTS = new Set(isBaiduSmartProgram ? [] : ['view', 'h-element']); // With no events or props && equal to TOUCH_COMPONENTS -export const CATCH_COMPONENTS = new Set(['view', 'h-element']); // With catchTouchMove events +export const CATCH_COMPONENTS = new Set(isBaiduSmartProgram ? [] : ['view', 'h-element']); // With catchTouchMove events export const APPEAR_COMPONENT = 'view'; // Without appear event components diff --git a/packages/miniapp-render/src/node/element.js b/packages/miniapp-render/src/node/element.js index a44c4281..0c05b028 100755 --- a/packages/miniapp-render/src/node/element.js +++ b/packages/miniapp-render/src/node/element.js @@ -116,6 +116,8 @@ class Element extends Node { if (hasCatchTouchMoveFlag) { CATCH_COMPONENTS.has(this.__tmplName) && (nodeTypePrefix = 'catch-'); } + + // Fix scroll-view shake problem caused by scroll-left or scroll-top if (isWeChatMiniProgram && hasAnchorScrollFlag) { ANCHOR_COMPONENT === this.__tmplName && (nodeTypePrefix = 'anchor-'); } diff --git a/packages/rax-miniapp-runtime-webpack-plugin/src/platforms/baidu.js b/packages/rax-miniapp-runtime-webpack-plugin/src/platforms/baidu.js index 42af3052..64c79f4b 100644 --- a/packages/rax-miniapp-runtime-webpack-plugin/src/platforms/baidu.js +++ b/packages/rax-miniapp-runtime-webpack-plugin/src/platforms/baidu.js @@ -37,36 +37,6 @@ const View = { } }; -const CatchView = Object.assign({}, View); - -const StaticView = { - props: { - 'hover-class': addSingleQuote('none'), - 'hover-start-time': '50', - 'hover-stay-time': '400', - 'hover-stop-propagation': 'false', - animation: '' - } -}; - -const PureView = {}; - -const NoTouchView = { - props: { - 'hover-class': addSingleQuote('none'), - 'hover-start-time': '50', - 'hover-stay-time': '400', - 'hover-stop-propagation': 'false', - animation: '' - }, - events: { - ...animationEvents - }, - basicEvents: { - ...tapEvents - } -}; - const HElement = { props: { animation: '' @@ -77,19 +47,6 @@ const HElement = { } }; -const CatchHElement = Object.assign({}, HElement); - -const PureHElement = {}; - -const NoTouchHElement = { - props: { - animation: '' - }, - basicEvents: { - ...tapEvents - } -}; - const HComment = {}; const Swiper = { @@ -821,10 +778,6 @@ const OfficialAccount = { exports.internalComponents = { View, - CatchView, - StaticView, - PureView, - NoTouchView, Swiper, SwiperItem, ScrollView, @@ -865,20 +818,10 @@ exports.internalComponents = { LivePusher, OfficialAccount, HElement, - CatchHElement, - PureHElement, - NoTouchHElement, HComment }; exports.derivedComponents = new Map([ - ['CatchView', 'View'], - ['StaticView', 'View'], - ['PureView', 'View'], - ['NoTouchView', 'View'], - ['CatchHElement', 'View'], - ['PureHElement', 'View'], - ['NoTouchHElement', 'View'], ['HElement', 'View'], ['StaticText', 'Text'], ['StaticImage', 'Image'], @@ -945,7 +888,35 @@ exports.shouldNotGenerateTemplateComponents = new Set([ 'MovableView' ]); +const flattenViewLevel = 8; +function generateFlattenView(level, component) { + if (level === 0) { + return '