From 6024ce942b450cb82637fed96237ff53926c2bb9 Mon Sep 17 00:00:00 2001 From: ykforerlang <1527997464@qq.com> Date: Mon, 16 Dec 2019 18:10:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(@areslabs/wx-react):=20=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E5=AF=B9=E5=A4=96=E6=9A=B4=E9=9C=B2=E7=9A=84=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E7=9B=B8=E5=BA=94=E7=9A=84=E5=A2=9E=E5=BC=BARNBaseCom?= =?UTF-8?q?ponent=20reactCompHelper=E7=9A=84=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/wx-react/package.json | 2 +- packages/wx-react/src/AllComponent.js | 22 +++++++++++ packages/wx-react/src/index.js | 3 +- packages/wx-react/src/reactCompHelper.js | 47 ++++++++++++++++++++++++ packages/wx-react/src/util.js | 31 ---------------- 5 files changed, 72 insertions(+), 33 deletions(-) create mode 100644 packages/wx-react/src/reactCompHelper.js diff --git a/packages/wx-react/package.json b/packages/wx-react/package.json index a3b3baf..7e613c2 100644 --- a/packages/wx-react/package.json +++ b/packages/wx-react/package.json @@ -1,6 +1,6 @@ { "name": "@areslabs/wx-react", - "version": "2.0.0", + "version": "2.0.1", "description": "微信版本的React", "files": [ "package.json", diff --git a/packages/wx-react/src/AllComponent.js b/packages/wx-react/src/AllComponent.js index 9ba3cca..008d7c9 100644 --- a/packages/wx-react/src/AllComponent.js +++ b/packages/wx-react/src/AllComponent.js @@ -7,6 +7,8 @@ */ import instanceManager from "./InstanceManager"; +import tackleWithStyleObj from './tackleWithStyleObj' +import { VIEW, SCROLL, OUTERTEXT}from './styleType' import shallowEqual from './shallowEqual' @@ -106,4 +108,24 @@ export class HocComponent extends Component { } export class RNBaseComponent { + + getWxInst() { + return instanceManager.getWxInstByUUID(this.__diuu__) + } + + transformViewStyle(style){ + return tackleWithStyleObj(style, VIEW) + } + + transformScrollViewStyle(style) { + return tackleWithStyleObj(style, SCROLL) + } + + transformTextStyle(style) { + return tackleWithStyleObj(style, OUTERTEXT) + } + + transformStyle(style) { + return tackleWithStyleObj(style) + } } diff --git a/packages/wx-react/src/index.js b/packages/wx-react/src/index.js index ca234af..39d6d11 100644 --- a/packages/wx-react/src/index.js +++ b/packages/wx-react/src/index.js @@ -12,7 +12,8 @@ import WxNormalComp from './WxNormalComp' import tackleWithStyleObj, {parseElement, flattenStyle} from './tackleWithStyleObj' import styleType from './styleType' import instanceManager from './InstanceManager' -import {getPropsMethod, reactCompHelper} from './util' +import {getPropsMethod} from './util' +import reactCompHelper from './reactCompHelper' import {unstable_batchedUpdates, renderPage, renderApp} from './UpdateStrategy' diff --git a/packages/wx-react/src/reactCompHelper.js b/packages/wx-react/src/reactCompHelper.js new file mode 100644 index 0000000..d6872eb --- /dev/null +++ b/packages/wx-react/src/reactCompHelper.js @@ -0,0 +1,47 @@ +import instanceManager from "./InstanceManager"; + +/** + * Copyright (c) Areslabs. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +export default function reactCompHelper(obj) { + obj.properties = { + ...obj.properties, + diuu: null, + } + + const rawAttached = obj.attached + obj.attached = function () { + const rawData = this.data + Object.defineProperty(this, 'data', { + get: function () { + const compInst = instanceManager.getCompInstByUUID(rawData.diuu); + return { + ...rawData, + ...compInst.props + } + }, + }) + rawAttached && rawAttached.call(this) + instanceManager.setWxCompInst(this.data.diuu, this) + } + + const rawDetached = obj.detached + obj.detached = function () { + rawDetached && rawDetached.call(this) + instanceManager.removeUUID(this.data.diuu) + } + + if (!obj.methods) { + obj.methods = {} + } + obj.methods.getReactComp = function () { + return instanceManager.getCompInstByUUID(this.data.diuu) + } + + return obj +} \ No newline at end of file diff --git a/packages/wx-react/src/util.js b/packages/wx-react/src/util.js index 3d69d9b..65bccee 100644 --- a/packages/wx-react/src/util.js +++ b/packages/wx-react/src/util.js @@ -132,35 +132,4 @@ export function cleanPageComp(pageComp) { invokeWillUnmount(allChildren) } -export function reactCompHelper(obj) { - obj.properties = { - ...obj.properties, - diuu: null, - } - - const rawAttached = obj.attached - obj.attached = function () { - const rawData = this.data - Object.defineProperty(this, 'data', { - get: function () { - const compInst = instanceManager.getCompInstByUUID(rawData.diuu); - return { - ...rawData, - ...compInst.props - } - }, - }) - rawAttached && rawAttached.call(this) - instanceManager.setWxCompInst(this.data.diuu, this) - } - - const rawDetached = obj.detached - obj.detached = function () { - rawDetached && rawDetached.call(this) - instanceManager.removeUUID(this.data.diuu) - } - - return obj -} -