From 0175da5a0c519c2749f88a9939b453fa1d934786 Mon Sep 17 00:00:00 2001 From: WaterMan Date: Mon, 10 Jun 2019 18:39:45 +0800 Subject: [PATCH 001/158] =?UTF-8?q?fix(rn):=20this.$router=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0path=E5=B1=9E=E6=80=A7=EF=BC=8C=E4=B8=8E=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-rn/src/component.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/taro-rn/src/component.js b/packages/taro-rn/src/component.js index dc70b2dbd186..e3af282bf07d 100644 --- a/packages/taro-rn/src/component.js +++ b/packages/taro-rn/src/component.js @@ -7,7 +7,7 @@ class Component extends React.Component { constructor (props, context) { super(props, context) if (props.navigation) { - this.$router = {params: props.navigation.state.params || {}} + this.$router = {params: props.navigation.state.params || {}, path: props.navigation.routeName ? ('/' + props.navigation.routeName) : null} } } @@ -25,7 +25,7 @@ class PureComponent extends React.PureComponent { constructor (props, context) { super(props, context) if (props.navigation) { - this.$router = {params: props.navigation.state.params || {}} + this.$router = {params: props.navigation.state.params || {}, path: props.navigation.routeName ? ('/' + props.navigation.routeName) : null} } } @@ -39,5 +39,4 @@ class PureComponent extends React.PureComponent { } } - export { Component, PureComponent } From af0236e7a00468555895d19fb553bd79cbf9f9c9 Mon Sep 17 00:00:00 2001 From: WaterMan Date: Mon, 10 Jun 2019 19:22:17 +0800 Subject: [PATCH 002/158] =?UTF-8?q?fix(rn):=20this.$router=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0path=E5=B1=9E=E6=80=A7=EF=BC=8C=E4=B8=8E=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-rn/src/component.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/taro-rn/src/component.js b/packages/taro-rn/src/component.js index e3af282bf07d..c7f3c2c1b0e6 100644 --- a/packages/taro-rn/src/component.js +++ b/packages/taro-rn/src/component.js @@ -7,7 +7,7 @@ class Component extends React.Component { constructor (props, context) { super(props, context) if (props.navigation) { - this.$router = {params: props.navigation.state.params || {}, path: props.navigation.routeName ? ('/' + props.navigation.routeName) : null} + this.$router = {params: props.navigation.state.params || {}, path: props.navigation.state.routeName ? ('/' + props.navigation.state.routeName) : null} } } @@ -25,7 +25,7 @@ class PureComponent extends React.PureComponent { constructor (props, context) { super(props, context) if (props.navigation) { - this.$router = {params: props.navigation.state.params || {}, path: props.navigation.routeName ? ('/' + props.navigation.routeName) : null} + this.$router = {params: props.navigation.state.params || {}, path: props.navigation.state.routeName ? ('/' + props.navigation.state.routeName) : null} } } From bfcce24b830531be494865669fec0651c7c9c84d Mon Sep 17 00:00:00 2001 From: Pines-Cheng Date: Thu, 13 Jun 2019 21:07:30 +0800 Subject: [PATCH 003/158] =?UTF-8?q?docs(rn):=20=E6=9B=B4=E6=96=B0=20RN=20?= =?UTF-8?q?=E5=A4=96=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/react-native.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/react-native.md b/docs/react-native.md index 17b3ca2a9d97..e44930a7e136 100644 --- a/docs/react-native.md +++ b/docs/react-native.md @@ -290,7 +290,7 @@ rn_temp ### 启动应用 如果上一步的编译和 Metro Bundler Server 启动没问题,接下来就可以启动应用了。 -开发者可以自行整合 React Native (0.55.4) 到原生应用,同时为了方便大家开发和整合,Taro 将 React Native 工程中原生的部分剥离出来,单独放在一个工程里面 [NervJS/taro-native-shell](https://github.com/NervJS/taro-native-shell),你可以把它看成是 React Native iOS/Android 空应用的壳子。 +开发者可以自行[整合 React Native (0.55.4) 到原生应用](https://reactnative.cn/docs/0.55/integration-with-existing-apps/),同时为了方便大家开发和整合,Taro 将 React Native 工程中原生的部分剥离出来,单独放在一个工程里面 [NervJS/taro-native-shell](https://github.com/NervJS/taro-native-shell),你可以把它看成是 React Native iOS/Android 空应用的壳子。 首先将应用代码 clone 下来: From bc6bc47776c6947e14d2a5710d4143e10fbf6b74 Mon Sep 17 00:00:00 2001 From: yuche Date: Thu, 13 Jun 2019 16:44:58 +0800 Subject: [PATCH 004/158] =?UTF-8?q?feat(redux):=20=E6=94=AF=E6=8C=81=20use?= =?UTF-8?q?Selector,=20useDispatch,=20useStore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-redux/package.json | 1 + packages/taro-redux/rollup.config.js | 1 + packages/taro-redux/src/hooks/context.js | 3 + packages/taro-redux/src/hooks/use-dispatch.js | 29 +++++ .../taro-redux/src/hooks/use-redux-context.js | 24 ++++ packages/taro-redux/src/hooks/use-selector.js | 110 ++++++++++++++++++ packages/taro-redux/src/hooks/use-store.js | 21 ++++ packages/taro-redux/src/index.js | 16 ++- packages/taro-redux/src/utils/batch.js | 12 ++ packages/taro-redux/src/utils/invariant.js | 42 +++++++ packages/taro-redux/src/utils/subscription.js | 99 ++++++++++++++++ packages/taro-weapp/rollup.config.js | 2 +- 12 files changed, 357 insertions(+), 3 deletions(-) create mode 100644 packages/taro-redux/src/hooks/context.js create mode 100644 packages/taro-redux/src/hooks/use-dispatch.js create mode 100644 packages/taro-redux/src/hooks/use-redux-context.js create mode 100644 packages/taro-redux/src/hooks/use-selector.js create mode 100644 packages/taro-redux/src/hooks/use-store.js create mode 100644 packages/taro-redux/src/utils/batch.js create mode 100644 packages/taro-redux/src/utils/invariant.js create mode 100644 packages/taro-redux/src/utils/subscription.js diff --git a/packages/taro-redux/package.json b/packages/taro-redux/package.json index e16494b48e0e..954ca2714989 100644 --- a/packages/taro-redux/package.json +++ b/packages/taro-redux/package.json @@ -31,6 +31,7 @@ "jest": "^23.1.0" }, "dependencies": { + "@tarojs/taro": "^1.3.0", "@tarojs/utils": "1.3.0" } } diff --git a/packages/taro-redux/rollup.config.js b/packages/taro-redux/rollup.config.js index 891cb1b4aa5e..5a998789b80b 100644 --- a/packages/taro-redux/rollup.config.js +++ b/packages/taro-redux/rollup.config.js @@ -5,6 +5,7 @@ const alias = require('rollup-plugin-alias') const cwd = __dirname const baseConfig = { + external: ['@tarojs/taro'], input: join(cwd, 'src/index.js'), output: [ { diff --git a/packages/taro-redux/src/hooks/context.js b/packages/taro-redux/src/hooks/context.js new file mode 100644 index 000000000000..54b54ebbf672 --- /dev/null +++ b/packages/taro-redux/src/hooks/context.js @@ -0,0 +1,3 @@ +import Taro from '@tarojs/taro' + +export const ReduxContext = Taro.createContext(null) diff --git a/packages/taro-redux/src/hooks/use-dispatch.js b/packages/taro-redux/src/hooks/use-dispatch.js new file mode 100644 index 000000000000..6b7e0c7f953d --- /dev/null +++ b/packages/taro-redux/src/hooks/use-dispatch.js @@ -0,0 +1,29 @@ +import { useStore } from './use-store' + +/** + * A hook to access the redux `dispatch` function. Note that in most cases where you + * might want to use this hook it is recommended to use `useActions` instead to bind + * action creators to the `dispatch` function. + * + * @returns {any|function} redux store's `dispatch` function + * + * @example + * + * import React, { useCallback } from 'react' + * import { useReduxDispatch } from 'react-redux' + * + * export const CounterComponent = ({ value }) => { + * const dispatch = useDispatch() + * const increaseCounter = useCallback(() => dispatch({ type: 'increase-counter' }), []) + * return ( + *
+ * {value} + * + *
+ * ) + * } + */ +export function useDispatch () { + const store = useStore() + return store.dispatch +} diff --git a/packages/taro-redux/src/hooks/use-redux-context.js b/packages/taro-redux/src/hooks/use-redux-context.js new file mode 100644 index 000000000000..7e8099dc1d24 --- /dev/null +++ b/packages/taro-redux/src/hooks/use-redux-context.js @@ -0,0 +1,24 @@ +import { useContext } from '@tarojs/taro' +import { ReduxContext } from './context' + +/** + * A hook to access the value of the `ReactReduxContext`. This is a low-level + * hook that you should usually not need to call directly. + * + * @returns {any} the value of the `ReactReduxContext` + * + * @example + * + * import React from 'react' + * import { useReduxContext } from 'react-redux' + * + * export const CounterComponent = ({ value }) => { + * const { store } = useReduxContext() + * return
{store.getState()}
+ * } + */ +export function useReduxContext () { + const contextValue = useContext(ReduxContext) + + return contextValue +} diff --git a/packages/taro-redux/src/hooks/use-selector.js b/packages/taro-redux/src/hooks/use-selector.js new file mode 100644 index 000000000000..4cd33535858f --- /dev/null +++ b/packages/taro-redux/src/hooks/use-selector.js @@ -0,0 +1,110 @@ +import { useReducer, useRef, useMemo, useLayoutEffect } from '@tarojs/taro' +import { useReduxContext } from './use-redux-context' +import Subscription from '../utils/subscription' +import invariant from '../utils/invariant' + +const refEquality = (a, b) => a === b + +/** + * A hook to access the redux store's state. This hook takes a selector function + * as an argument. The selector is called with the store state. + * + * This hook takes an optional equality comparison function as the second parameter + * that allows you to customize the way the selected state is compared to determine + * whether the component needs to be re-rendered. + * + * @param {Function} selector the selector function + * @param {Function=} equalityFn the function that will be used to determine equality + * + * @returns {any} the selected state + * + * @example + * + * import React from 'react' + * import { useSelector } from 'react-redux' + * + * export const CounterComponent = () => { + * const counter = useSelector(state => state.counter) + * return
{counter}
+ * } + */ +export function useSelector (selector, equalityFn = refEquality) { + invariant(selector, `You must pass a selector to useSelectors`) + + const { store, subscription: contextSub } = useReduxContext() + const [, forceRender] = useReducer(s => s + 1, 0) + + const subscription = useMemo(() => new Subscription(store, contextSub), [ + store, + contextSub + ]) + + const latestSubscriptionCallbackError = useRef() + const latestSelector = useRef() + const latestSelectedState = useRef() + + let selectedState + + try { + if ( + selector !== latestSelector.current || + latestSubscriptionCallbackError.current + ) { + selectedState = selector(store.getState()) + } else { + selectedState = latestSelectedState.current + } + } catch (err) { + let errorMessage = `An error occured while selecting the store state: ${ + err.message + }.` + + if (latestSubscriptionCallbackError.current) { + errorMessage += `\nThe error may be correlated with this previous error:\n${ + latestSubscriptionCallbackError.current.stack + }\n\nOriginal stack trace:` + } + + throw new Error(errorMessage) + } + + useLayoutEffect(() => { + latestSelector.current = selector + latestSelectedState.current = selectedState + latestSubscriptionCallbackError.current = undefined + }) + + useLayoutEffect( + () => { + function checkForUpdates () { + try { + const newSelectedState = latestSelector.current(store.getState()) + + if (equalityFn(newSelectedState, latestSelectedState.current)) { + return + } + + latestSelectedState.current = newSelectedState + } catch (err) { + // we ignore all errors here, since when the component + // is re-rendered, the selectors are called again, and + // will throw again, if neither props nor store state + // changed + latestSubscriptionCallbackError.current = err + } + + forceRender({}) + } + + subscription.onStateChange = checkForUpdates + subscription.trySubscribe() + + checkForUpdates() + + return () => subscription.tryUnsubscribe() + }, + [store, subscription] + ) + + return selectedState +} diff --git a/packages/taro-redux/src/hooks/use-store.js b/packages/taro-redux/src/hooks/use-store.js new file mode 100644 index 000000000000..3f276bb88af1 --- /dev/null +++ b/packages/taro-redux/src/hooks/use-store.js @@ -0,0 +1,21 @@ +import { useReduxContext } from './use-redux-context' + +/** + * A hook to access the redux store. + * + * @returns {any} the redux store + * + * @example + * + * import React from 'react' + * import { useStore } from 'react-redux' + * + * export const ExampleComponent = () => { + * const store = useStore() + * return
{store.getState()}
+ * } + */ +export function useStore () { + const { store } = useReduxContext() + return store +} diff --git a/packages/taro-redux/src/index.js b/packages/taro-redux/src/index.js index 01143147c6df..e8beb0dba95c 100644 --- a/packages/taro-redux/src/index.js +++ b/packages/taro-redux/src/index.js @@ -1,17 +1,29 @@ import { getStore, setStore } from './utils/store' import connect from './connect/connect' import Provider from './connect/Provider' +import { useDispatch } from './hooks/use-dispatch' +import { useSelector } from './hooks/use-selector' +import { useStore } from './hooks/use-store' +import { ReduxContext } from './hooks/context' export default { connect, Provider, getStore, - setStore + setStore, + useDispatch, + useSelector, + useStore, + ReduxContext } export { connect, Provider, getStore, - setStore + setStore, + useDispatch, + useSelector, + useStore, + ReduxContext } diff --git a/packages/taro-redux/src/utils/batch.js b/packages/taro-redux/src/utils/batch.js new file mode 100644 index 000000000000..439a06d831c3 --- /dev/null +++ b/packages/taro-redux/src/utils/batch.js @@ -0,0 +1,12 @@ +// Default to a dummy "batch" implementation that just runs the callback +function defaultNoopBatch (callback) { + callback() +} + +let batch = defaultNoopBatch + +// Allow injecting another batching function later +export const setBatch = newBatch => (batch = newBatch) + +// Supply a getter just to skip dealing with ESM bindings +export const getBatch = () => batch diff --git a/packages/taro-redux/src/utils/invariant.js b/packages/taro-redux/src/utils/invariant.js new file mode 100644 index 000000000000..7afabca56ebd --- /dev/null +++ b/packages/taro-redux/src/utils/invariant.js @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +'use strict' +/** + * Use invariant() to assert state which your program assumes to be true. + * + * Provide sprintf-style format (only %s is supported) and arguments + * to provide information about what broke and what you were + * expecting. + * + * The invariant message will be stripped in production, but the invariant + * will remain to ensure logic does not differ in production. + */ + +export default function invariant (condition, format, a, b, c, d, e, f) { + if (!condition) { + var error + if (format === undefined) { + error = new Error( + 'Minified exception occurred; use the non-minified dev environment ' + + 'for the full error message and additional helpful warnings.' + ) + } else { + var args = [a, b, c, d, e, f] + var argIndex = 0 + error = new Error( + format.replace(/%s/g, function () { + return args[argIndex++] + }) + ) + error.name = 'Invariant Violation' + } + + error.framesToPop = 1 // we don't care about invariant's own frame + throw error + } +} diff --git a/packages/taro-redux/src/utils/subscription.js b/packages/taro-redux/src/utils/subscription.js new file mode 100644 index 000000000000..38628d3cfe3d --- /dev/null +++ b/packages/taro-redux/src/utils/subscription.js @@ -0,0 +1,99 @@ +import { getBatch } from './batch' + +// encapsulates the subscription logic for connecting a component to the redux store, as +// well as nesting subscriptions of descendant components, so that we can ensure the +// ancestor components re-render before descendants + +const CLEARED = null +const nullListeners = { notify () {} } + +function createListenerCollection () { + const batch = getBatch() + // the current/next pattern is copied from redux's createStore code. + // TODO: refactor+expose that code to be reusable here? + let current = [] + let next = [] + + return { + clear () { + next = CLEARED + current = CLEARED + }, + + notify () { + const listeners = (current = next) + batch(() => { + for (let i = 0; i < listeners.length; i++) { + listeners[i]() + } + }) + }, + + get () { + return next + }, + + subscribe (listener) { + let isSubscribed = true + if (next === current) next = current.slice() + next.push(listener) + + return function unsubscribe () { + if (!isSubscribed || current === CLEARED) return + isSubscribed = false + + if (next === current) next = current.slice() + next.splice(next.indexOf(listener), 1) + } + } + } +} + +export default class Subscription { + constructor (store, parentSub) { + this.store = store + this.parentSub = parentSub + this.unsubscribe = null + this.listeners = nullListeners + + this.handleChangeWrapper = this.handleChangeWrapper.bind(this) + } + + addNestedSub (listener) { + this.trySubscribe() + return this.listeners.subscribe(listener) + } + + notifyNestedSubs () { + this.listeners.notify() + } + + handleChangeWrapper () { + if (this.onStateChange) { + this.onStateChange() + } + } + + isSubscribed () { + return Boolean(this.unsubscribe) + } + + trySubscribe () { + if (!this.unsubscribe) { + this.unsubscribe = this.parentSub + ? this.parentSub.addNestedSub(this.handleChangeWrapper) + : this.store.subscribe(this.handleChangeWrapper) + + this.listeners = createListenerCollection() + } + } + + tryUnsubscribe () { + if (this.unsubscribe) { + this.unsubscribe() + this.unsubscribe = null + this.listeners.clear() + this.listeners = nullListeners + } + } +} diff --git a/packages/taro-weapp/rollup.config.js b/packages/taro-weapp/rollup.config.js index 4af44972956b..11641f2133a3 100644 --- a/packages/taro-weapp/rollup.config.js +++ b/packages/taro-weapp/rollup.config.js @@ -7,7 +7,7 @@ const cwd = __dirname const baseConfig = { input: join(cwd, 'src/index.js'), - external: ['nervjs'], + external: ['nervjs', '@tarojs/taro'], output: [ { file: join(cwd, 'dist/index.js'), From 7797bd7d30041001965aca74ff4239963db538d7 Mon Sep 17 00:00:00 2001 From: yuche Date: Thu, 13 Jun 2019 21:17:50 +0800 Subject: [PATCH 005/158] =?UTF-8?q?refactor(taro):=20=E6=8A=8A=20@tarojs/t?= =?UTF-8?q?aro=20=E5=8A=A0=E5=85=A5=E5=88=B0=E5=90=84=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=AB=AF=E7=9A=84=20external?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-alipay/rollup.config.js | 2 +- packages/taro-qq/rollup.config.js | 2 +- packages/taro-swan/rollup.config.js | 2 +- packages/taro-transformer-wx/src/index.ts | 20 +++++++++++++++++--- packages/taro-tt/rollup.config.js | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/taro-alipay/rollup.config.js b/packages/taro-alipay/rollup.config.js index 1d2142ee9754..47b837efc94c 100644 --- a/packages/taro-alipay/rollup.config.js +++ b/packages/taro-alipay/rollup.config.js @@ -7,7 +7,7 @@ const cwd = __dirname const baseConfig = { input: join(cwd, 'src/index.js'), - external: ['nervjs'], + external: ['nervjs', '@tarojs/taro'], output: [ { file: join(cwd, 'dist/index.js'), diff --git a/packages/taro-qq/rollup.config.js b/packages/taro-qq/rollup.config.js index 1b87286176ad..d9d0086e2d8c 100644 --- a/packages/taro-qq/rollup.config.js +++ b/packages/taro-qq/rollup.config.js @@ -7,7 +7,7 @@ const cwd = __dirname const baseConfig = { input: join(cwd, 'src/index.js'), - external: ['nervjs'], + external: ['nervjs', '@tarojs/taro'], output: [ { file: join(cwd, 'dist/index.js'), diff --git a/packages/taro-swan/rollup.config.js b/packages/taro-swan/rollup.config.js index d60eca2b7775..0c5d7b2d0576 100644 --- a/packages/taro-swan/rollup.config.js +++ b/packages/taro-swan/rollup.config.js @@ -7,7 +7,7 @@ const cwd = __dirname const baseConfig = { input: join(cwd, 'src/index.js'), - external: ['nervjs'], + external: ['nervjs', '@tarojs/taro'], output: [ { file: join(cwd, 'dist/index.js'), diff --git a/packages/taro-transformer-wx/src/index.ts b/packages/taro-transformer-wx/src/index.ts index d3ad4922f1ad..dfdd68bd8e2b 100644 --- a/packages/taro-transformer-wx/src/index.ts +++ b/packages/taro-transformer-wx/src/index.ts @@ -644,7 +644,8 @@ export default function transform (options: Options): TransformResult { if (s.local.name === 'Provider') { specs.splice(index, 1) specs.push( - t.importSpecifier(t.identifier('setStore'), t.identifier('setStore')) + t.importSpecifier(t.identifier('setStore'), t.identifier('setStore')), + t.importSpecifier(t.identifier('ReduxContext'), t.identifier('ReduxContext')) ) } }) @@ -691,14 +692,27 @@ export default function transform (options: Options): TransformResult { if (storeBinding) { const statementPath = storeBinding.path.getStatementParent() if (statementPath) { - ast.program.body.forEach((node, index, body) => { + ast.program.body.every((node, index, body) => { if (node === statementPath.node) { + const settingReduxProvider = t.expressionStatement( + t.callExpression(t.memberExpression(t.identifier('ReduxContext'), t.identifier('Provider')), [ + t.objectExpression([ + t.objectProperty(t.identifier('store'), t.identifier(storeName)) + ]) + ]) + ) + const ifStem = t.ifStatement(t.memberExpression(t.identifier('ReduxContext'), t.identifier('Provider')), t.blockStatement([ + settingReduxProvider, + settingReduxProvider // 第一次调用初始化,第二次赋值 + ])) body.splice(index + 1, 0, t.expressionStatement( t.callExpression(t.identifier('setStore'), [ t.identifier(storeName) ]) - )) + ), ifStem) + return false } + return true }) } } diff --git a/packages/taro-tt/rollup.config.js b/packages/taro-tt/rollup.config.js index f799916a5a6d..7e99cca186c4 100644 --- a/packages/taro-tt/rollup.config.js +++ b/packages/taro-tt/rollup.config.js @@ -7,7 +7,7 @@ const cwd = __dirname const baseConfig = { input: join(cwd, 'src/index.js'), - external: ['nervjs'], + external: ['nervjs', '@tarojs/taro'], output: [ { file: join(cwd, 'dist/index.js'), From dd18aa933c6dc30d04629aa7fb71e93758672625 Mon Sep 17 00:00:00 2001 From: yuche Date: Thu, 13 Jun 2019 21:57:54 +0800 Subject: [PATCH 006/158] feat(redux): useSelector, useStore, useDispatch typing --- packages/taro-redux/types/index.d.ts | 82 ++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/packages/taro-redux/types/index.d.ts b/packages/taro-redux/types/index.d.ts index ebeab1621443..d9618cea7673 100644 --- a/packages/taro-redux/types/index.d.ts +++ b/packages/taro-redux/types/index.d.ts @@ -62,3 +62,85 @@ export interface ProviderProps { } export class Provider extends Component, any> { } + + +/** + * A hook to access the redux store's state. This hook takes a selector function + * as an argument. The selector is called with the store state. + * + * This hook takes an optional equality comparison function as the second parameter + * that allows you to customize the way the selected state is compared to determine + * whether the component needs to be re-rendered. + * + * If you do not want to have to specify the root state type for whenever you use + * this hook with an inline selector you can use the `TypedUseSelectorHook` interface + * to create a version of this hook that is properly typed for your root state. + * + * @param selector the selector function + * @param equalityFn the function that will be used to determine equality + * + * @returns the selected state + * + * @example + * + * import React from 'react' + * import { useSelector } from 'react-redux' + * import { RootState } from './store' + * + * export const CounterComponent = () => { + * const counter = useSelector((state: RootState) => state.counter) + * return
{counter}
+ * } + */ +export function useSelector( + selector: (state: TState) => TSelected, + equalityFn?: (left: TSelected, right: TSelected) => boolean +): TSelected; + +/** + * A hook to access the redux store. + * + * @returns the redux store + * + * @example + * + * import React from 'react' + * import { useStore } from 'react-redux' + * + * export const ExampleComponent = () => { + * const store = useStore() + * return
{store.getState()}
+ * } + */ +export function useStore(): Store; + +/** + * A hook to access the redux `dispatch` function. + * + * Note for `redux-thunk` users: the return type of the returned `dispatch` functions for thunks is incorrect. + * However, it is possible to get a correctly typed `dispatch` function by creating your own custom hook typed + * from the store's dispatch function like this: `const useThunkDispatch = () => useDispatch();` + * + * @returns redux store's `dispatch` function + * + * @example + * + * import React, { useCallback } from 'react' + * import { useDispatch } from 'react-redux' + * + * export const CounterComponent = ({ value }) => { + * const dispatch = useDispatch() + * return ( + *
+ * {value} + * + *
+ * ) + * } + */ +// NOTE: the first overload below and note above can be removed if redux-thunk typings add an overload for +// the Dispatch function (see also this PR: https://github.com/reduxjs/redux-thunk/pull/247) +export function useDispatch>(): TDispatch; +export function useDispatch
(): Dispatch; From 2b420d0cc9d6ec8467fd5229936a6549bc8ae038 Mon Sep 17 00:00:00 2001 From: yuche Date: Fri, 14 Jun 2019 11:08:56 +0800 Subject: [PATCH 007/158] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E5=9C=A8=20r?= =?UTF-8?q?edux=20=E4=B8=AD=E4=BD=BF=E7=94=A8=20hooks=20=E7=9A=84=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/redux.md | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/docs/redux.md b/docs/redux.md index 74af439e75ff..b41f44057f78 100644 --- a/docs/redux.md +++ b/docs/redux.md @@ -205,3 +205,151 @@ export default Index - `mapStateToProps`,函数类型,接受最新的 `state` 作为参数,用于将 `state` 映射到组件的 `props` - `mapDispatchToProps`,函数类型,接收 `dispatch()` 方法并返回期望注入到展示组件的 `props` 中的回调方法 + +## Hooks + +### 在 Redux 中使用 Hooks + +使用 hooks 的基本设置和使用 `connect` 的设置是一样的,你需要设置你的 `store`,并把你的应用放在 `Provider` 组件中。 + +```jsx +const store = configreStore(rootReducer) + +class App extends Components { + render () { + return ( + + + + ) + } +} +``` + +在这样的情况下,你就可以使用 `taro-redux` 提供的 Hooks API 在函数式组件中使用。 + +### `useSelector` + +```javascript +const result : any = useSelector(selector : Function, equalityFn? : Function) +``` + +`useSelector` 允许你使用 selector 函数从一个 Redux Store 中获取数据。 + +Selector 函数大致相当于 `connect` 函数的 `mapStateToProps` 参数。Selector 会在组件每次渲染时调用。`useSelector` 同样会订阅 Redux store,在 Redux action 被 dispatch 时调用。 + +但 `useSelector` 还是和 `mapStateToProps` 有一些不同: + +* 不像 `mapStateToProps` 只返回对象一样,Selector 可能会返回任何值。 +* 当一个 action dispatch 时,`useSelector` 会把 selector 的前后返回值做一次浅对比,如果不同,组件会强制更新。 +* Selector 函数不接受 `ownProps` 参数。但 selector 可以通过闭包访问函数式组件传递下来的 props。 + + +#### 使用案例 + +基本使用: + +```jsx +import Taro, { Components } from '@tarojs/taro' +import { useSelector } from 'taro-redux' + +export const CounterComponent = () => { + const counter = useSelector(state => state.counter) + return {counter} +} +``` + +使用闭包决定如何 select 数据: + +```jsx +export const TodoListItem = props => { + const todo = useSelector(state => state.todos[props.id]) + return {todo.text} +} + +``` + +#### 进阶使用 + + 你还可以访问 [react-redux 文档](https://react-redux.js.org/api/hooks#using-memoizing-selectors) 了解如何使用 `reselect` 缓存 selector。 + + +### `useDispatch` + +```javascript +const dispatch = useDispatch() +``` + +这个 Hook 返回 Redux store 的 `dispatch` 引用。你可以使用它来 dispatch actions。 + +#### 使用案例 + +```jsx +import Taro, { Components } from '@tarojs/taro' +import { useDispatch } from 'taro-redux' + +export const CounterComponent = ({ value }) => { + const dispatch = useDispatch() + + return ( + + {value} + + + ) +} +``` + +当我们使用 `dispatch` 传递回调到一个子组件时,推荐使用 `useCallback` 把回调缓存起来,因为组件可能因为引用改变而重新渲染。 + +```jsx +// CounterComponent.js +export const CounterComponent = ({ value }) => { + const dispatch = useDispatch() + const incrementCounter = useCallback( + () => dispatch({ type: 'increment-counter' }), + [dispatch] + ) + + return ( + + {value} + + + ) +} + +// IncrementButton.js +const MyIncrementButton = ({ onIncrement }) => ( + +) + +export default Taro.memo(MyIncrementButton) +``` + +### `useStore` + +```js +const store = useStore() +``` + +`useStore` 返回一个 store 引用和 `Provider` 组件引用完全一致。 + +这个 hook 可能并不经常使用。`useSelector` 大部分情况是你的第一选择,如果需要替换 reducers 的情况下可能会使用到这个 API。 + +#### 使用案例 + +```jsx +import Taro, { Components } from '@tarojs/taro' +import { useStore } from 'taro-redux' + +export const CounterComponent = ({ value }) => { + const store = useStore() + + // EXAMPLE ONLY! Do not do this in a real app. + // The component will not automatically update if the store state changes + return
{store.getState()}
+} +``` From f23f506773ea24abd47fca4934da29eaf3cbdbce Mon Sep 17 00:00:00 2001 From: Pines Date: Fri, 14 Jun 2019 11:18:38 +0800 Subject: [PATCH 008/158] Update bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 934db8c12431..07aa7c9e5a01 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -9,6 +9,8 @@ assignees: '' > Feature Request 请提到 [FeatHub](https://feathub.com/NervJS/taro) +> Taro 使用上的问题请提到 [Taro 社区——让每一次交流被沉淀](https://taro-club.jd.com/) + 如果是提交 bug,请搜索文档和 issue,确认以下事项: * 该问题没有在其他 issue 和文档讨论到,不属于重复内容 From 247b0c0470a5cc1cbe1c27ed287b3db505744c6f Mon Sep 17 00:00:00 2001 From: luckyadam Date: Fri, 14 Jun 2019 14:43:06 +0800 Subject: [PATCH 009/158] =?UTF-8?q?fix(cli):=20=E4=BF=AE=E6=AD=A3=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=88=9B=E5=BB=BA=E6=97=B6=E9=A1=B5=E9=9D=A2=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=AD=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/create/creator.ts | 3 ++- packages/taro-cli/templates/default/index.js | 6 ++++-- packages/taro-cli/templates/default/pagejs | 6 +++--- packages/taro-cli/templates/mobx/index.js | 6 ++++-- packages/taro-cli/templates/mobx/pagejs | 10 +++++----- packages/taro-cli/templates/redux/index.js | 6 ++++-- packages/taro-cli/templates/redux/pagejs | 14 +++++++------- packages/taro-cli/templates/wxcloud/client/pagejs | 6 +++--- packages/taro-cli/templates/wxcloud/index.js | 6 ++++-- packages/taro-cli/templates/wxplugin/index.js | 6 ++++-- packages/taro-cli/templates/wxplugin/pagejs | 6 +++--- 11 files changed, 43 insertions(+), 32 deletions(-) diff --git a/packages/taro-cli/src/create/creator.ts b/packages/taro-cli/src/create/creator.ts index eef90a3cab4f..bc2a266fef5f 100644 --- a/packages/taro-cli/src/create/creator.ts +++ b/packages/taro-cli/src/create/creator.ts @@ -2,6 +2,7 @@ import * as path from 'path' import * as fs from 'fs-extra' import * as memFs from 'mem-fs' import * as editor from 'mem-fs-editor' +import * as _ from 'lodash' import { getRootPath @@ -103,7 +104,7 @@ export default class Creator { this.fs.copyTpl( this.templatePath(template, source), this.destinationPath(dest), - Object.assign({}, this, data), + Object.assign({ _ }, this, data), options ) return this diff --git a/packages/taro-cli/templates/default/index.js b/packages/taro-cli/templates/default/index.js index 0d6daa596b66..d148031fd57d 100644 --- a/packages/taro-cli/templates/default/index.js +++ b/packages/taro-cli/templates/default/index.js @@ -34,11 +34,13 @@ exports.createPage = function (creater, params, cb) { if (typescript) { creater.template(template, 'pagejs', path.join(sourceDir, 'pages', page, `${page}.tsx`), { css: currentStyleExt, - typescript: true + typescript: true, + pageName: page }) } else { creater.template(template, 'pagejs', path.join(sourceDir, 'pages', page, `${page}.js`), { - css: currentStyleExt + css: currentStyleExt, + pageName: page }) } creater.fs.commit(() => { diff --git a/packages/taro-cli/templates/default/pagejs b/packages/taro-cli/templates/default/pagejs index 0cb25dd047f5..bc36c488efcc 100644 --- a/packages/taro-cli/templates/default/pagejs +++ b/packages/taro-cli/templates/default/pagejs @@ -4,9 +4,9 @@ import Taro, { Component, Config } from '@tarojs/taro' import Taro, { Component } from '@tarojs/taro' <%}-%> import { View, Text } from '@tarojs/components' -import './index.<%= css %>' +import './<%= pageName %>.<%= css %>' -export default class Index extends Component { +export default class <%= _.capitalize(pageName) %> extends Component { <%if (locals.typescript) {-%> /** @@ -33,7 +33,7 @@ export default class Index extends Component { render () { return ( - + Hello world! ) diff --git a/packages/taro-cli/templates/mobx/index.js b/packages/taro-cli/templates/mobx/index.js index 4d7193e96d40..64bd72d016ee 100644 --- a/packages/taro-cli/templates/mobx/index.js +++ b/packages/taro-cli/templates/mobx/index.js @@ -34,11 +34,13 @@ exports.createPage = function (creater, params, cb) { if (typescript) { creater.template(template, 'pagejs', path.join(sourceDir, 'pages', page, `${page}.tsx`), { css: currentStyleExt, - typescript: true + typescript: true, + pageName: page }) } else { creater.template(template, 'pagejs', path.join(sourceDir, 'pages', page, `${page}.js`), { - css: currentStyleExt + css: currentStyleExt, + pageName: page }) } creater.fs.commit(() => { diff --git a/packages/taro-cli/templates/mobx/pagejs b/packages/taro-cli/templates/mobx/pagejs index fb6f5274b38a..47c6ab437d3b 100644 --- a/packages/taro-cli/templates/mobx/pagejs +++ b/packages/taro-cli/templates/mobx/pagejs @@ -7,7 +7,7 @@ import Taro, { Component } from '@tarojs/taro' import { View, Button, Text } from '@tarojs/components' import { observer, inject } from '@tarojs/mobx' -import './index.<%= css %>' +import './<%= pageName %>.<%= css %>' <%if (locals.typescript) {-%> type PageStateProps = { @@ -19,14 +19,14 @@ type PageStateProps = { } } -interface Index { +interface <%= _.capitalize(pageName) %> { props: PageStateProps; } <%}-%> @inject('counterStore') @observer -class Index extends Component { +class <%= _.capitalize(pageName) %> extends Component { <%if (locals.typescript) {-%> /** @@ -73,7 +73,7 @@ class Index extends Component { render () { const { counterStore: { counter } } = this.props return ( - + @@ -83,4 +83,4 @@ class Index extends Component { } } -export default Index <%if (locals.typescript) {%> as ComponentType<%}%> +export default <%= _.capitalize(pageName) %> <%if (locals.typescript) {%> as ComponentType<%}%> diff --git a/packages/taro-cli/templates/redux/index.js b/packages/taro-cli/templates/redux/index.js index e07465121fa8..da02fafbfb7e 100644 --- a/packages/taro-cli/templates/redux/index.js +++ b/packages/taro-cli/templates/redux/index.js @@ -34,11 +34,13 @@ exports.createPage = function (creater, params, cb) { if (typescript) { creater.template(template, 'pagejs', path.join(sourceDir, 'pages', page, `${page}.tsx`), { css: currentStyleExt, - typescript: true + typescript: true, + pageName: page }) } else { creater.template(template, 'pagejs', path.join(sourceDir, 'pages', page, `${page}.js`), { - css: currentStyleExt + css: currentStyleExt, + pageName: page }) } creater.fs.commit(() => { diff --git a/packages/taro-cli/templates/redux/pagejs b/packages/taro-cli/templates/redux/pagejs index 708bb11eac65..46656c757a3b 100644 --- a/packages/taro-cli/templates/redux/pagejs +++ b/packages/taro-cli/templates/redux/pagejs @@ -9,11 +9,11 @@ import { connect } from '@tarojs/redux' import { add, minus, asyncAdd } from '../../actions/counter' -import './index.<%= css %>' +import './<%= pageName %>.<%= css %>' <% if (locals.typescript) {-%> // #region 书写注意 -// +// // 目前 typescript 版本还无法在装饰器模式下将 Props 注入到 Taro.Component 中的 props 属性 // 需要显示声明 connect 的参数类型并通过 interface 的方式指定 Taro.Component 子类的 props // 这样才能完成类型检查和 IDE 的自动提示 @@ -40,7 +40,7 @@ type PageState = {} type IProps = PageStateProps & PageDispatchProps & PageOwnProps -interface Index { +interface <%= _.capitalize(pageName) %> { props: IProps; } <%}-%> @@ -58,7 +58,7 @@ interface Index { dispatch(asyncAdd()) } })) -class Index extends Component { +class <%= _.capitalize(pageName) %> extends Component { <%if (locals.typescript) {-%> /** @@ -85,7 +85,7 @@ class Index extends Component { render () { return ( - + @@ -104,7 +104,7 @@ class Index extends Component { // // #endregion -export default Index as ComponentClass +export default <%= _.capitalize(pageName) %> as ComponentClass <%} else {-%> -export default Index +export default <%= _.capitalize(pageName) %> <%}-%> diff --git a/packages/taro-cli/templates/wxcloud/client/pagejs b/packages/taro-cli/templates/wxcloud/client/pagejs index 543dbfd36ce6..8d9fbf80e51d 100644 --- a/packages/taro-cli/templates/wxcloud/client/pagejs +++ b/packages/taro-cli/templates/wxcloud/client/pagejs @@ -4,11 +4,11 @@ import Taro, { Component, Config } from '@tarojs/taro' import Taro, { Component } from '@tarojs/taro' <%}-%> import { View, Text } from '@tarojs/components' -import './index.<%= css %>' +import './<%= pageName %>.<%= css %>' import Login from '../../components/login/index' -export default class Index extends Component { +export default class <%= _.capitalize(pageName) %> extends Component { <%if (locals.typescript) {-%> /** @@ -35,7 +35,7 @@ export default class Index extends Component { render () { return ( - + ) diff --git a/packages/taro-cli/templates/wxcloud/index.js b/packages/taro-cli/templates/wxcloud/index.js index a670a4b77a6d..5cc2b0c7ccb1 100644 --- a/packages/taro-cli/templates/wxcloud/index.js +++ b/packages/taro-cli/templates/wxcloud/index.js @@ -38,11 +38,13 @@ exports.createPage = function (creater, params, cb) { if (typescript) { creater.template(template, path.join(clientDirName, 'pagejs'), path.join(sourceDir, 'pages', page, `${page}.tsx`), { css: currentStyleExt, - typescript: true + typescript: true, + pageName: page }) } else { creater.template(template, path.join(clientDirName, 'pagejs'), path.join(sourceDir, 'pages', page, `${page}.js`), { - css: currentStyleExt + css: currentStyleExt, + pageName: page }) } creater.fs.commit(() => { diff --git a/packages/taro-cli/templates/wxplugin/index.js b/packages/taro-cli/templates/wxplugin/index.js index 2a2c32a38b3d..595500111a88 100644 --- a/packages/taro-cli/templates/wxplugin/index.js +++ b/packages/taro-cli/templates/wxplugin/index.js @@ -34,11 +34,13 @@ exports.createPage = function (creater, params, cb) { if (typescript) { creater.template(template, 'pagejs', path.join(sourceDir, 'pages', page, `${page}.tsx`), { css: currentStyleExt, - typescript: true + typescript: true, + pageName: page }) } else { creater.template(template, 'pagejs', path.join(sourceDir, 'pages', page, `${page}.js`), { - css: currentStyleExt + css: currentStyleExt, + pageName: page }) } creater.fs.commit(() => { diff --git a/packages/taro-cli/templates/wxplugin/pagejs b/packages/taro-cli/templates/wxplugin/pagejs index 1ed4550aa0f7..8e8450527873 100644 --- a/packages/taro-cli/templates/wxplugin/pagejs +++ b/packages/taro-cli/templates/wxplugin/pagejs @@ -4,11 +4,11 @@ import Taro, { Component, Config } from '@tarojs/taro' import Taro, { Component } from '@tarojs/taro' <%}-%> import { View, Text, Navigator } from '@tarojs/components' -import './index.<%= css %>' +import './<%= pageName %>.<%= css %>' const myPluginInterface = Taro.requirePlugin('myPlugin') -export default class Index extends Component { +export default class <%= _.capitalize(pageName) %> extends Component { <%if (locals.typescript) {-%> /** @@ -42,7 +42,7 @@ export default class Index extends Component { render () { return ( - + Hello world! From d29436a777019c944d1997b83d2f007738521c76 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Fri, 14 Jun 2019 15:19:32 +0800 Subject: [PATCH 010/158] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/hooks.md | 29 +++++++++++++++++++++++++++++ docs/project-config.md | 12 ++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/docs/hooks.md b/docs/hooks.md index 9543e136932a..559ad60f6dc4 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -361,3 +361,32 @@ const value = useContext(MyContext) > 如果你在接触 Hook 前已经对 context API 比较熟悉,那应该可以理解,`useContext(MyContext)` 相当于 class 组件中的 `static contextType = MyContext` 或者 。 > `useContext(MyContext)` 只是让你能够读取 context 的值以及订阅 context 的变化。你仍然需要在上层组件树中使用 来为下层组件提供 context。 +## 页面及组件中相关属性设置 + +在 Taro 中,你可以为页面及组件设置一些属性来达到一些特殊的目的,例如 `config` 设置配置等等,在前面章节你已经学会如何在类中进行相关设置,同样的,使用 Hooks 时你也可以进行相关设置来达到和使用类一样的效果。 + +不同于使用类的写法,使用 Hooks 时,你需要将 `config` 或 `options` 等配置直接挂载在 Hooks 函数上,即可以达到想要的效果,例如 + +为页面设置 `config` + +```jsx +export default function Index () { + return +} + +Index.config = { + navigationBarTitleText: '首页' +} +``` + +为组件设置 `options` + +```jsx +export default function Com () { + return +} + +Com.options = { + addGlobalClass: true +} +``` diff --git a/docs/project-config.md b/docs/project-config.md index 64134ffc2cbb..1264bb6b9bb2 100644 --- a/docs/project-config.md +++ b/docs/project-config.md @@ -8,13 +8,17 @@ title: 项目配置 * 百度智能小程序,[project.swan.json](https://smartprogram.baidu.com/docs/develop/devtools/projectconfig/) * 头条小程序,project.config.json,文档暂无,大部分字段与微信小程序一致 * 支付宝小程序,暂无发现 +* 快应用,[manifest.json](https://doc.quickapp.cn/framework/manifest.html) 为了能够适配到各个小程序平台,满足不同小程序平台配置文件不同的情况,在 Taro 支持为各个小程序平台添加不同的项目配置文件。 通过 Taro 模板创建的项目都会默认拥有 `project.config.json` 这一项目配置文件,这个文件 **只能用于微信小程序**,若要兼容到其他小程序平台,请按如下对应规则来增加相应平台的配置文件,其配置与各自小程序平台要求的一致 -| 小程序平台 | 添加配置文件 | +| 小程序平台 | 添加配置文件 | 说明 | | - | - | -| 微信小程序 | project.config.json | -| 百度智能小程序 | project.swan.json | -| 头条小程序 | project.tt.json | +| 微信小程序 | project.config.json | | +| 百度智能小程序 | project.swan.json | | +| 头条小程序 | project.tt.json | | +| 快应用 | project.quickapp.json | 配置文件中请勿配置 `router` 与 `display`,这两个配置将由 Taro 生成 | + +> 注意:快应用的 `project.quickapp.json` 配置请参考[文件](https://github.com/NervJS/taro/blob/master/packages/taro-cli/src/config/manifest.default.json) From 44b730afdaf3fed50817f22bce2a2008a8c60f41 Mon Sep 17 00:00:00 2001 From: itsonglei <190835837@qq.com> Date: Fri, 14 Jun 2019 16:13:33 +0800 Subject: [PATCH 011/158] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96h5=20=E4=B8=8B?= =?UTF-8?q?=20ScrollView=20=E6=A0=87=E7=AD=BE=EF=BC=8C=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=20onTouchMove=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/scroll-view/index.js | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/taro-components/src/components/scroll-view/index.js b/packages/taro-components/src/components/scroll-view/index.js index 9e4011bae60f..330a208cea07 100644 --- a/packages/taro-components/src/components/scroll-view/index.js +++ b/packages/taro-components/src/components/scroll-view/index.js @@ -4,19 +4,19 @@ import omit from 'omit.js' import classNames from 'classnames' import './style/index.scss' -function easeOutScroll (from, to, callback) { +function easeOutScroll(from, to, callback) { if (from === to || typeof from !== 'number') { return } let change = to - from const dur = 500 const sTime = +new Date() - function linear (t, b, c, d) { + function linear(t, b, c, d) { return c * t / d + b } const isLarger = to >= from - function step () { + function step() { from = linear(+new Date() - sTime, from, change, dur) if ((isLarger && from >= to) || (!isLarger && to >= from)) { callback(to) @@ -27,7 +27,7 @@ function easeOutScroll (from, to, callback) { } step() } -function throttle (fn, delay) { +function throttle(fn, delay) { let timer = null return function () { clearTimeout(timer) @@ -37,15 +37,15 @@ function throttle (fn, delay) { } } class ScrollView extends Nerv.Component { - constructor () { + constructor() { super(...arguments) } onTouchMove = e => { - e.stopPropagation() + e.stopPropagation(); } - componentDidMount () { + componentDidMount() { setTimeout(() => { const props = this.props if (props.scrollY && typeof props.scrollTop === 'number') { @@ -71,7 +71,7 @@ class ScrollView extends Nerv.Component { }, 10) } - componentWillReceiveProps (nextProps) { + componentWillReceiveProps(nextProps) { const props = this.props // Y 轴滚动 if ( @@ -105,12 +105,13 @@ class ScrollView extends Nerv.Component { } } - render () { + render() { const { className, onScroll, onScrollToUpper, onScrollToLower, + onTouchMove, scrollX, scrollY } = this.props @@ -170,15 +171,22 @@ class ScrollView extends Nerv.Component { uperAndLowerThrottle() onScroll && onScroll(e) } + const _onTouchMove = e => { + onTouchMove ? onTouchMove(e) : this.onTouchMove + } return (
{ this.container = container }} - {...omit(this.props, ['className', 'scrollTop', 'scrollLeft'])} + { + ...omit(this.props, ['className', 'scrollTop', 'scrollLeft']) + } className={cls} onScroll={_onScroll} - onTouchMove={this.onTouchMove}> + onTouchMove={ + _onTouchMove + } > {this.props.children}
) From a9b8fa72bd7d8ec3d923f2c64e126061af5b3331 Mon Sep 17 00:00:00 2001 From: Pines-Cheng Date: Fri, 14 Jun 2019 17:36:29 +0800 Subject: [PATCH 012/158] =?UTF-8?q?fix(rn):=20[RN]Taro.getCurrentPages?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=B8=8D=E5=AD=98=E5=9C=A8=20close=20#3224?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-router-rn/src/TaroProvider.js | 25 +++++++++++++------ .../taro-router-rn/src/getWrappedScreen.js | 15 +++++++---- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/packages/taro-router-rn/src/TaroProvider.js b/packages/taro-router-rn/src/TaroProvider.js index 16827c8648f2..46847f0555ad 100644 --- a/packages/taro-router-rn/src/TaroProvider.js +++ b/packages/taro-router-rn/src/TaroProvider.js @@ -10,22 +10,31 @@ class TaroProvider extends React.Component { this.refreshProviderRef = React.createRef() } - componentDidMount () { + navigationMethodInit () { let {Taro} = this.props + Taro.navigateTo = this.wxNavigateTo.bind(this) + Taro.redirectTo = this.wxRedirectTo.bind(this) + Taro.navigateBack = this.wxNavigateBack.bind(this) + Taro.switchTab = this.wxSwitchTab.bind(this) + Taro.getCurrentPages = this.wxGetCurrentPages.bind(this) + Taro.showTabBar = this.showTabBar.bind(this) + Taro.hideTabBar = this.hideTabBar.bind(this) + } + + componentWillMount () { + this.navigationMethodInit() // didFocus this.didFocusSubscription = this.props.navigation.addListener( 'didFocus', payload => { // 页面进入后回退并不会调用 React 生命周期,需要在路由生命周期中绑定 this - Taro.navigateTo = this.wxNavigateTo.bind(this) - Taro.redirectTo = this.wxRedirectTo.bind(this) - Taro.navigateBack = this.wxNavigateBack.bind(this) - Taro.switchTab = this.wxSwitchTab.bind(this) - Taro.getCurrentPages = this.wxGetCurrentPages.bind(this) - Taro.showTabBar = this.showTabBar.bind(this) - Taro.hideTabBar = this.hideTabBar.bind(this) + this.navigationMethodInit() } ) + } + + componentDidMount () { + let {Taro} = this.props try { Taro.startPullDownRefresh = this.refreshProviderRef.current && this.refreshProviderRef.current.handlePullDownRefresh Taro.stopPullDownRefresh = this.refreshProviderRef.current && this.refreshProviderRef.current.stopPullDownRefresh diff --git a/packages/taro-router-rn/src/getWrappedScreen.js b/packages/taro-router-rn/src/getWrappedScreen.js index 390e0c7bede8..c2e54dc6de94 100644 --- a/packages/taro-router-rn/src/getWrappedScreen.js +++ b/packages/taro-router-rn/src/getWrappedScreen.js @@ -116,16 +116,21 @@ function getWrappedScreen (Screen, Taro, globalNavigationOptions = {}) { } } - componentDidMount () { + navigationMethodInit () { + Taro.setNavigationBarTitle = this.setNavigationBarTitle.bind(this) + Taro.setNavigationBarColor = this.setNavigationBarColor.bind(this) + Taro.showNavigationBarLoading = this.showNavigationBarLoading.bind(this) + Taro.hideNavigationBarLoading = this.hideNavigationBarLoading.bind(this) + } + + componentWillMount () { + this.navigationMethodInit() // didFocus this.didFocusSubscription = this.props.navigation.addListener( 'didFocus', payload => { // 页面进入后回退并不会调用 React 生命周期,需要在路由生命周期中绑定 this - Taro.setNavigationBarTitle = this.setNavigationBarTitle.bind(this) - Taro.setNavigationBarColor = this.setNavigationBarColor.bind(this) - Taro.showNavigationBarLoading = this.showNavigationBarLoading.bind(this) - Taro.hideNavigationBarLoading = this.hideNavigationBarLoading.bind(this) + this.navigationMethodInit() // 页面聚焦时,调用 componentDidShow this.getScreenInstance().componentDidShow && this.getScreenInstance().componentDidShow() } From 487add60e08362c6118b7b055408f02da38b9b22 Mon Sep 17 00:00:00 2001 From: itsonglei <190835837@qq.com> Date: Fri, 14 Jun 2019 17:38:03 +0800 Subject: [PATCH 013/158] =?UTF-8?q?fiex:=20=E4=BF=AE=E5=A4=8D=20onTouchMov?= =?UTF-8?q?e=20=E6=97=A0=E6=B3=95=E8=B0=83=E7=94=A8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-components/src/components/scroll-view/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-components/src/components/scroll-view/index.js b/packages/taro-components/src/components/scroll-view/index.js index 330a208cea07..97a35484a78a 100644 --- a/packages/taro-components/src/components/scroll-view/index.js +++ b/packages/taro-components/src/components/scroll-view/index.js @@ -172,7 +172,7 @@ class ScrollView extends Nerv.Component { onScroll && onScroll(e) } const _onTouchMove = e => { - onTouchMove ? onTouchMove(e) : this.onTouchMove + onTouchMove ? onTouchMove(e) : this.onTouchMove(e) } return (
Date: Sun, 16 Jun 2019 20:36:21 +0800 Subject: [PATCH 014/158] chore(release): publish v1.3.1 --- lerna.json | 2 +- .../package.json | 2 +- .../package.json | 4 ++-- packages/css-to-react-native/package.json | 2 +- packages/eslint-config-taro/package.json | 4 ++-- packages/eslint-plugin-taro/package.json | 2 +- .../postcss-plugin-constparse/package.json | 2 +- packages/postcss-pxtransform/package.json | 2 +- packages/postcss-unit-transform/package.json | 2 +- .../stylelint-config-taro-rn/package.json | 4 ++-- packages/stylelint-taro-rn/package.json | 2 +- packages/taro-alipay/package.json | 6 ++--- packages/taro-async-await/package.json | 2 +- packages/taro-cli/package.json | 22 +++++++++---------- packages/taro-components-qa/package.json | 2 +- packages/taro-components-rn/package.json | 2 +- packages/taro-components/package.json | 6 ++--- packages/taro-h5/package.json | 6 ++--- packages/taro-mobx-common/package.json | 2 +- packages/taro-mobx-h5/package.json | 4 ++-- packages/taro-mobx-rn/package.json | 4 ++-- packages/taro-mobx/package.json | 4 ++-- packages/taro-plugin-babel/package.json | 2 +- packages/taro-plugin-csso/package.json | 2 +- packages/taro-plugin-less/package.json | 2 +- packages/taro-plugin-sass/package.json | 2 +- packages/taro-plugin-stylus/package.json | 2 +- packages/taro-plugin-typescript/package.json | 2 +- packages/taro-plugin-uglifyjs/package.json | 2 +- packages/taro-qq/package.json | 6 ++--- packages/taro-quickapp/package.json | 6 ++--- packages/taro-redux-h5/package.json | 4 ++-- packages/taro-redux-rn/package.json | 2 +- packages/taro-redux/package.json | 6 ++--- packages/taro-rn-runner/package.json | 2 +- packages/taro-rn/package.json | 4 ++-- packages/taro-router-rn/package.json | 2 +- packages/taro-router/package.json | 4 ++-- packages/taro-swan/package.json | 6 ++--- packages/taro-transformer-wx/package.json | 6 ++--- packages/taro-tt/package.json | 6 ++--- packages/taro-utils/package.json | 2 +- packages/taro-weapp/package.json | 6 ++--- packages/taro-webpack-runner/package.json | 10 ++++----- packages/taro-with-weapp/package.json | 4 ++-- packages/taro/package.json | 2 +- packages/taroize/package.json | 2 +- 47 files changed, 91 insertions(+), 91 deletions(-) diff --git a/lerna.json b/lerna.json index db822ef45f97..60a7b98ca9bc 100644 --- a/lerna.json +++ b/lerna.json @@ -53,6 +53,6 @@ "message": "chore(release): publish %s" } }, - "version": "1.3.0", + "version": "1.3.1", "npmClient": "npm" } diff --git a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json index b62c49abd565..f15f8aacba2b 100644 --- a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json +++ b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-jsx-to-stylesheet", - "version": "1.3.0", + "version": "1.3.1", "description": "Transform stylesheet selector to style in JSX Elements.", "license": "MIT", "main": "src/index.js", diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json index f0587c8d61f4..9bde7fac277d 100644 --- a/packages/babel-plugin-transform-taroapi/package.json +++ b/packages/babel-plugin-transform-taroapi/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-taroapi", - "version": "1.3.0", + "version": "1.3.1", "main": "dist/index.js", "license": "MIT", "scripts": { @@ -10,7 +10,7 @@ "test": "jest" }, "devDependencies": { - "@tarojs/taro-h5": "1.3.0", + "@tarojs/taro-h5": "1.3.1", "@types/babel-core": "^6.25.5", "@types/babel-traverse": "^6.25.4", "@types/babel-types": "^7.0.4", diff --git a/packages/css-to-react-native/package.json b/packages/css-to-react-native/package.json index dd49d0e2b05d..5ae7241bd226 100644 --- a/packages/css-to-react-native/package.json +++ b/packages/css-to-react-native/package.json @@ -1,7 +1,7 @@ { "name": "taro-css-to-react-native", "description": "Convert CSS text to a React Native stylesheet object", - "version": "1.3.0", + "version": "1.3.1", "main": "dist/index.js", "license": "MIT", "scripts": { diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json index 89c14f011837..c2bfaf9501de 100644 --- a/packages/eslint-config-taro/package.json +++ b/packages/eslint-config-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-taro", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro specific linting rules for ESLint", "main": "index.js", "files": [ @@ -27,6 +27,6 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "eslint-plugin-taro": "1.3.0" + "eslint-plugin-taro": "1.3.1" } } diff --git a/packages/eslint-plugin-taro/package.json b/packages/eslint-plugin-taro/package.json index 14877634b7e6..f63ffa8e868f 100644 --- a/packages/eslint-plugin-taro/package.json +++ b/packages/eslint-plugin-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-taro", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro specific linting plugin for ESLint", "main": "index.js", "files": [ diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json index 91847d46d509..b3536507ee1a 100644 --- a/packages/postcss-plugin-constparse/package.json +++ b/packages/postcss-plugin-constparse/package.json @@ -1,6 +1,6 @@ { "name": "postcss-plugin-constparse", - "version": "1.3.0", + "version": "1.3.1", "description": "parse constants defined in config", "main": "index.js", "author": "Simba", diff --git a/packages/postcss-pxtransform/package.json b/packages/postcss-pxtransform/package.json index 513383d63311..6c4c3e4a2646 100644 --- a/packages/postcss-pxtransform/package.json +++ b/packages/postcss-pxtransform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-pxtransform", - "version": "1.3.0", + "version": "1.3.1", "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位", "keywords": [ "postcss", diff --git a/packages/postcss-unit-transform/package.json b/packages/postcss-unit-transform/package.json index af1528117b87..414181ce828a 100644 --- a/packages/postcss-unit-transform/package.json +++ b/packages/postcss-unit-transform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-taro-unit-transform", - "version": "1.3.0", + "version": "1.3.1", "description": "小程序单位转换", "main": "index.js", "scripts": { diff --git a/packages/stylelint-config-taro-rn/package.json b/packages/stylelint-config-taro-rn/package.json index fb5b35500ebb..c34b80a4ce93 100644 --- a/packages/stylelint-config-taro-rn/package.json +++ b/packages/stylelint-config-taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-config-taro-rn", - "version": "1.3.0", + "version": "1.3.1", "description": "Shareable stylelint config for React Native CSS modules", "main": "index.js", "files": [ @@ -28,6 +28,6 @@ "jest": "^23.6.0", "npmpub": "^4.1.0", "stylelint": "9.3.0", - "stylelint-taro-rn": "1.3.0" + "stylelint-taro-rn": "1.3.1" } } diff --git a/packages/stylelint-taro-rn/package.json b/packages/stylelint-taro-rn/package.json index 3148cc2d9ad2..5a2c3b494db4 100644 --- a/packages/stylelint-taro-rn/package.json +++ b/packages/stylelint-taro-rn/package.json @@ -1,7 +1,7 @@ { "name": "stylelint-taro-rn", "description": "A collection of React Native specific rules for stylelint", - "version": "1.3.0", + "version": "1.3.1", "main": "dist/index.js", "babel": { "presets": [ diff --git a/packages/taro-alipay/package.json b/packages/taro-alipay/package.json index 7477ae83baa1..bf18d70b8b03 100644 --- a/packages/taro-alipay/package.json +++ b/packages/taro-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-alipay", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro alipay framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.0", - "@tarojs/utils": "1.3.0", + "@tarojs/taro": "1.3.1", + "@tarojs/utils": "1.3.1", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-async-await/package.json b/packages/taro-async-await/package.json index fbbb89a29fc0..d25f1b57475d 100644 --- a/packages/taro-async-await/package.json +++ b/packages/taro-async-await/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/async-await", - "version": "1.3.0", + "version": "1.3.1", "description": "taro async await", "main": "index.js", "scripts": { diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json index 77961b88ea6a..03edaabefc88 100644 --- a/packages/taro-cli/package.json +++ b/packages/taro-cli/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/cli", - "version": "1.3.0", + "version": "1.3.1", "description": "cli tool for taro", "main": "index.js", "scripts": { @@ -30,8 +30,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taroize": "1.3.0", - "@tarojs/transformer-wx": "1.3.0", + "@tarojs/taroize": "1.3.1", + "@tarojs/transformer-wx": "1.3.1", "@types/request": "^2.48.1", "autoprefixer": "^8.4.1", "babel-core": "^6.26.3", @@ -41,7 +41,7 @@ "babel-plugin-remove-dead-code": "^1.3.2", "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-define": "^1.3.0", - "babel-plugin-transform-jsx-to-stylesheet": "1.3.0", + "babel-plugin-transform-jsx-to-stylesheet": "1.3.1", "babel-plugin-transform-react-jsx": "^6.24.1", "babel-template": "^6.26.0", "babel-traverse": "^6.26.0", @@ -56,10 +56,10 @@ "ejs": "^2.6.1", "envinfo": "^6.0.1", "eslint": "^4.15.0", - "eslint-config-taro": "1.3.0", + "eslint-config-taro": "1.3.1", "eslint-plugin-import": "^2.8.0", "eslint-plugin-react": "^7.4.0", - "eslint-plugin-taro": "1.3.0", + "eslint-plugin-taro": "1.3.1", "eslint-plugin-typescript": "^0.12.0", "fbjs": "^1.0.0", "fs-extra": "^5.0.0", @@ -81,7 +81,7 @@ "postcss-modules-resolve-imports": "^1.3.0", "postcss-modules-scope": "^1.1.0", "postcss-modules-values": "^1.3.0", - "postcss-pxtransform": "1.3.0", + "postcss-pxtransform": "1.3.1", "postcss-reporter": "^6.0.1", "postcss-taro-unit-transform": "1.2.15", "postcss-url": "^7.3.2", @@ -92,16 +92,16 @@ "semver": "^5.5.0", "shelljs": "^0.8.1", "stylelint": "9.3.0", - "stylelint-config-taro-rn": "1.3.0", - "stylelint-taro-rn": "1.3.0", - "taro-css-to-react-native": "1.3.0", + "stylelint-config-taro-rn": "1.3.1", + "stylelint-taro-rn": "1.3.1", + "taro-css-to-react-native": "1.3.1", "through2": "^2.0.3", "vinyl": "^2.1.0", "vinyl-fs": "^3.0.2", "yauzl": "2.10.0" }, "devDependencies": { - "@tarojs/taro": "1.3.0", + "@tarojs/taro": "1.3.1", "@types/autoprefixer": "^9.1.1", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.2", diff --git a/packages/taro-components-qa/package.json b/packages/taro-components-qa/package.json index d5be2b013e39..4852f823afad 100644 --- a/packages/taro-components-qa/package.json +++ b/packages/taro-components-qa/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-qa", - "version": "1.3.0", + "version": "1.3.1", "description": "多端解决方案基础组件(快应用)", "main": "./index.js", "files": [ diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index 664057d9f2aa..ec8224c916b3 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-rn", - "version": "1.3.0", + "version": "1.3.1", "description": "多端解决方案基础组件(RN)", "main": "./dist/index.js", "scripts": { diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json index befc57b9242d..24d7af8d10d3 100644 --- a/packages/taro-components/package.json +++ b/packages/taro-components/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components", - "version": "1.3.0", + "version": "1.3.1", "description": "", "main:h5": "src/index.js", "main": "dist/index.js", @@ -49,14 +49,14 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0", "@babel/plugin-transform-react-jsx": "^7.0.0", "@babel/preset-env": "^7.1.5", - "@tarojs/taro-h5": "1.3.0", + "@tarojs/taro-h5": "1.3.1", "@types/react": "^16.4.6", "@types/urijs": "^1.15.38", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "10.0.1", "babel-jest": "^22.4.4", "babel-loader": "^8.0.5", - "babel-plugin-transform-taroapi": "1.3.0", + "babel-plugin-transform-taroapi": "1.3.1", "css-loader": "^2.1.1", "file-loader": "^3.0.1", "jest": "^22.4.4", diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json index 692f0ad743b4..ffd25483a3ab 100644 --- a/packages/taro-h5/package.json +++ b/packages/taro-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-h5", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro h5 framework", "main:h5": "src/index.js", "main": "dist/index.js", @@ -43,8 +43,8 @@ "@babel/plugin-proposal-object-rest-spread": "^7.3.4", "@babel/plugin-transform-react-jsx": "^7.2.2", "@babel/preset-env": "^7.3.4", - "@tarojs/components": "1.3.0", - "@tarojs/taro": "1.3.0", + "@tarojs/components": "1.3.1", + "@tarojs/taro": "1.3.1", "babel-core": "7.0.0-bridge.0", "babel-jest": "24.4.0", "eslint": "^4.18.2", diff --git a/packages/taro-mobx-common/package.json b/packages/taro-mobx-common/package.json index 597de8d3d2b4..111bb4247d42 100644 --- a/packages/taro-mobx-common/package.json +++ b/packages/taro-mobx-common/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-common", - "version": "1.3.0", + "version": "1.3.1", "description": "mobx library for taro", "keywords": [ "mobx", diff --git a/packages/taro-mobx-h5/package.json b/packages/taro-mobx-h5/package.json index 988be96cd11f..e0be7ec6f5d2 100644 --- a/packages/taro-mobx-h5/package.json +++ b/packages/taro-mobx-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-h5", - "version": "1.3.0", + "version": "1.3.1", "description": "mobx-h5 for taro", "keywords": [ "mobx", @@ -29,7 +29,7 @@ "nervjs": "^1.4.0" }, "dependencies": { - "@tarojs/mobx-common": "1.3.0" + "@tarojs/mobx-common": "1.3.1" }, "devDependencies": { "rimraf": "^2.6.2", diff --git a/packages/taro-mobx-rn/package.json b/packages/taro-mobx-rn/package.json index 09c5004009c0..08ace1f23aec 100644 --- a/packages/taro-mobx-rn/package.json +++ b/packages/taro-mobx-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-rn", - "version": "1.3.0", + "version": "1.3.1", "description": "mobx-rn for taro", "keywords": [ "mobx", @@ -18,7 +18,7 @@ "src" ], "dependencies": { - "@tarojs/mobx-common": "1.3.0", + "@tarojs/mobx-common": "1.3.1", "@tarojs/taro-rn": "1.1.7" } } diff --git a/packages/taro-mobx/package.json b/packages/taro-mobx/package.json index 644ae677b9e6..979d178ec352 100644 --- a/packages/taro-mobx/package.json +++ b/packages/taro-mobx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx", - "version": "1.3.0", + "version": "1.3.1", "description": "mobx for taro", "keywords": [ "mobx", @@ -22,7 +22,7 @@ "clear": "rimraf dist" }, "dependencies": { - "@tarojs/mobx-common": "1.3.0" + "@tarojs/mobx-common": "1.3.1" }, "peerDependencies": { "mobx": "4.8.0" diff --git a/packages/taro-plugin-babel/package.json b/packages/taro-plugin-babel/package.json index 6fceb92e1895..10a906d41a00 100644 --- a/packages/taro-plugin-babel/package.json +++ b/packages/taro-plugin-babel/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-babel", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro babel编译", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-csso/package.json b/packages/taro-plugin-csso/package.json index 7ddc89984ef3..6f5157eebb61 100644 --- a/packages/taro-plugin-csso/package.json +++ b/packages/taro-plugin-csso/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-csso", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro压缩CSS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-less/package.json b/packages/taro-plugin-less/package.json index 17c0164a038b..514a67d25109 100644 --- a/packages/taro-plugin-less/package.json +++ b/packages/taro-plugin-less/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-less", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro 编译 less 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-sass/package.json b/packages/taro-plugin-sass/package.json index 9ec4c8598a92..9e5f4b68893e 100644 --- a/packages/taro-plugin-sass/package.json +++ b/packages/taro-plugin-sass/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-sass", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro编译sass文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-stylus/package.json b/packages/taro-plugin-stylus/package.json index f4839d5ad852..4b027424901f 100644 --- a/packages/taro-plugin-stylus/package.json +++ b/packages/taro-plugin-stylus/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-stylus", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro 编译 stylus 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-typescript/package.json b/packages/taro-plugin-typescript/package.json index 6ecfd3a2146f..aed90c7e3479 100644 --- a/packages/taro-plugin-typescript/package.json +++ b/packages/taro-plugin-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-typescript", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro TypeScript 编译插件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-uglifyjs/package.json b/packages/taro-plugin-uglifyjs/package.json index 66d5d431a4b9..fc83df62eeb1 100644 --- a/packages/taro-plugin-uglifyjs/package.json +++ b/packages/taro-plugin-uglifyjs/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-uglifyjs", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro压缩JS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-qq/package.json b/packages/taro-qq/package.json index 8bd6deeab2b5..dbbb83de42fb 100644 --- a/packages/taro-qq/package.json +++ b/packages/taro-qq/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-qq", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro qq framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.0", - "@tarojs/utils": "1.3.0", + "@tarojs/taro": "1.3.1", + "@tarojs/utils": "1.3.1", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-quickapp/package.json b/packages/taro-quickapp/package.json index d4315928791f..4da97d825ca5 100644 --- a/packages/taro-quickapp/package.json +++ b/packages/taro-quickapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-quickapp", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro quickapp framework", "main": "index.js", "files": [ @@ -23,8 +23,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.0", - "@tarojs/utils": "1.3.0", + "@tarojs/taro": "1.3.1", + "@tarojs/utils": "1.3.1", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-redux-h5/package.json b/packages/taro-redux-h5/package.json index 666dbd3b9127..329c79ee88dc 100644 --- a/packages/taro-redux-h5/package.json +++ b/packages/taro-redux-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux-h5", - "version": "1.3.0", + "version": "1.3.1", "description": "Forked react-redux for taro", "keywords": [ "react", @@ -46,7 +46,7 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.49", "@babel/plugin-transform-react-jsx": "^7.0.0-beta.49", "@babel/preset-env": "^7.0.0-beta.49", - "@tarojs/taro-h5": "1.3.0", + "@tarojs/taro-h5": "1.3.1", "babel-plugin-transform-react-remove-prop-types": "^0.4.13", "redux": "^4.0.0", "rimraf": "^2.6.2", diff --git a/packages/taro-redux-rn/package.json b/packages/taro-redux-rn/package.json index 3e8612c9736c..a7b90f012c0f 100644 --- a/packages/taro-redux-rn/package.json +++ b/packages/taro-redux-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-redux-rn", - "version": "1.3.0", + "version": "1.3.1", "description": "taro-redux-rn", "main": "./src/index.js", "files": [ diff --git a/packages/taro-redux/package.json b/packages/taro-redux/package.json index 954ca2714989..70675e38eeee 100644 --- a/packages/taro-redux/package.json +++ b/packages/taro-redux/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux", - "version": "1.3.0", + "version": "1.3.1", "description": "Redux for Taro", "main": "index.js", "typings": "types/index.d.ts", @@ -31,7 +31,7 @@ "jest": "^23.1.0" }, "dependencies": { - "@tarojs/taro": "^1.3.0", - "@tarojs/utils": "1.3.0" + "@tarojs/taro": "1.3.1", + "@tarojs/utils": "1.3.1" } } diff --git a/packages/taro-rn-runner/package.json b/packages/taro-rn-runner/package.json index fdfd17171740..260af06bf05c 100644 --- a/packages/taro-rn-runner/package.json +++ b/packages/taro-rn-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-runner", - "version": "1.3.0", + "version": "1.3.1", "description": "ReactNative build tool for taro", "main": "index.js", "scripts": { diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json index 84cc37a2a837..9240bf5c2c8d 100644 --- a/packages/taro-rn/package.json +++ b/packages/taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-rn", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro RN framework", "main": "./index.js", "files": [ @@ -27,7 +27,7 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.0", + "@tarojs/taro": "1.3.1", "base64-js": "^1.3.0", "react-native-image-crop-picker": "^0.23.1", "react-native-image-zoom-viewer": "^2.2.13", diff --git a/packages/taro-router-rn/package.json b/packages/taro-router-rn/package.json index bfdd69501897..2ce7327aa0c3 100644 --- a/packages/taro-router-rn/package.json +++ b/packages/taro-router-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-router-rn", - "version": "1.3.0", + "version": "1.3.1", "description": "taro-router-rn", "main": "./index.js", "files": [ diff --git a/packages/taro-router/package.json b/packages/taro-router/package.json index 21583fd936b5..72f1ccf6e51e 100644 --- a/packages/taro-router/package.json +++ b/packages/taro-router/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/router", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro-router", "main:h5": "dist/index.esm.js", "main": "index.js", @@ -41,7 +41,7 @@ "@babel/plugin-syntax-dynamic-import": "7.0.0", "@babel/plugin-transform-react-jsx": "7.0.0", "@babel/preset-env": "7.1.5", - "@tarojs/taro-h5": "1.3.0", + "@tarojs/taro-h5": "1.3.1", "@types/history": "4.7.2", "@types/jasmine": "2.8.11", "@types/jest": "23.3.9", diff --git a/packages/taro-swan/package.json b/packages/taro-swan/package.json index 904b86e987ba..ae386e38624d 100644 --- a/packages/taro-swan/package.json +++ b/packages/taro-swan/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-swan", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro swan framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.0", - "@tarojs/utils": "1.3.0", + "@tarojs/taro": "1.3.1", + "@tarojs/utils": "1.3.1", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-transformer-wx/package.json b/packages/taro-transformer-wx/package.json index 7243f24e4f5b..9887e87e605c 100644 --- a/packages/taro-transformer-wx/package.json +++ b/packages/taro-transformer-wx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/transformer-wx", - "version": "1.3.0", + "version": "1.3.1", "description": "Transfrom Nerv Component to Wechat mini program.", "repository": { "type": "git", @@ -62,14 +62,14 @@ "babel-types": "^6.26.0", "eslint": "^4.15.0", "eslint-plugin-react": "7.10.0", - "eslint-plugin-taro": "1.3.0", + "eslint-plugin-taro": "1.3.1", "html": "^1.0.0", "lodash": "^4.17.5", "prettier": "^1.14.2", "typescript": "^3.2.2" }, "devDependencies": { - "@tarojs/taro": "1.3.0", + "@tarojs/taro": "1.3.1", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.1", "@types/babel-template": "^6.25.0", diff --git a/packages/taro-tt/package.json b/packages/taro-tt/package.json index 105054f24e2b..4eea5b07124e 100644 --- a/packages/taro-tt/package.json +++ b/packages/taro-tt/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-tt", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro toutiao framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.0", - "@tarojs/utils": "1.3.0", + "@tarojs/taro": "1.3.1", + "@tarojs/utils": "1.3.1", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-utils/package.json b/packages/taro-utils/package.json index d5feae82d6ec..68c5b76e9cb1 100644 --- a/packages/taro-utils/package.json +++ b/packages/taro-utils/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/utils", - "version": "1.3.0", + "version": "1.3.1", "description": "Utils for Taro", "main": "index.js", "scripts": { diff --git a/packages/taro-weapp/package.json b/packages/taro-weapp/package.json index d94a028f6155..2014783e6e2a 100644 --- a/packages/taro-weapp/package.json +++ b/packages/taro-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-weapp", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro weapp framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.0", - "@tarojs/utils": "1.3.0", + "@tarojs/taro": "1.3.1", + "@tarojs/utils": "1.3.1", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json index cec29418a962..ff5e9e3ef5fc 100644 --- a/packages/taro-webpack-runner/package.json +++ b/packages/taro-webpack-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/webpack-runner", - "version": "1.3.0", + "version": "1.3.1", "description": "webpack runner for taro", "main": "index.js", "scripts": { @@ -32,13 +32,13 @@ }, "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { - "@tarojs/taro-h5": "1.3.0", + "@tarojs/taro-h5": "1.3.1", "autoprefixer": "8.6.4", "babel-core": "6.26.0", "babel-loader": "7.1.4", "babel-plugin-syntax-dynamic-import": "6.18.0", "babel-plugin-transform-react-jsx": "6.24.1", - "babel-plugin-transform-taroapi": "1.3.0", + "babel-plugin-transform-taroapi": "1.3.1", "babel-types": "6.26.0", "chalk": "2.4.2", "copy-webpack-plugin": "^5.0.3", @@ -55,8 +55,8 @@ "opn": "5.3.0", "ora": "2.1.0", "postcss-loader": "2.1.6", - "postcss-plugin-constparse": "1.3.0", - "postcss-pxtransform": "1.3.0", + "postcss-plugin-constparse": "1.3.1", + "postcss-pxtransform": "1.3.1", "resolve": "1.8.1", "resolve-url-loader": "2.3.0", "sass-loader": "7.1.0", diff --git a/packages/taro-with-weapp/package.json b/packages/taro-with-weapp/package.json index a042137f9c67..32f196b9eb37 100644 --- a/packages/taro-with-weapp/package.json +++ b/packages/taro-with-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/with-weapp", - "version": "1.3.0", + "version": "1.3.1", "description": "taroize 之后的运行时", "main": "index.js", "scripts": { @@ -22,7 +22,7 @@ "author": "yuche", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.0", + "@tarojs/taro": "1.3.1", "lodash": "^4.17.11" }, "devDependencies": { diff --git a/packages/taro/package.json b/packages/taro/package.json index c993d47471d1..2f17a2b00084 100644 --- a/packages/taro/package.json +++ b/packages/taro/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro", - "version": "1.3.0", + "version": "1.3.1", "description": "Taro framework", "module": "dist/index.esm.js", "main": "index.js", diff --git a/packages/taroize/package.json b/packages/taroize/package.json index 188e55579075..ca56c9512a5e 100644 --- a/packages/taroize/package.json +++ b/packages/taroize/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taroize", - "version": "1.3.0", + "version": "1.3.1", "description": "转换原生微信小程序代码为 Taro 代码", "main": "index.js", "files": [ From a7d22bf76cd76672c603ab280d8707d07824c199 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Sun, 16 Jun 2019 21:06:25 +0800 Subject: [PATCH 015/158] chore: changelog --- CHANGELOG.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e4108d0e3c0..3e365f8a7bb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,34 @@ -# [](https://github.com/NervJS/taro/compare/v1.3.0...v) (2019-06-11) +# [](https://github.com/NervJS/taro/compare/v1.3.1...v) (2019-06-16) + + + + +## [1.3.1](https://github.com/NervJS/taro/compare/v1.3.0...v1.3.1) (2019-06-16) + + +### Bug Fixes + +* **cli:** 修正页面创建时页面命名等问题 ([247b0c0](https://github.com/NervJS/taro/commit/247b0c0)) +* **mobx-h5:** 修复inject组件的componentDidShow内获取不到组件this的问题, fix [#3333](https://github.com/NervJS/taro/issues/3333) ([322f258](https://github.com/NervJS/taro/commit/322f258)) +* **rn:** [RN]Taro.getCurrentPages方法不存在 close [#3224](https://github.com/NervJS/taro/issues/3224) ([a9b8fa7](https://github.com/NervJS/taro/commit/a9b8fa7)) +* **taro-tt:** 修复头条小程序事件不带 type 参数的问题,fix [#3382](https://github.com/NervJS/taro/issues/3382) ([1977062](https://github.com/NervJS/taro/commit/1977062)) +* **transformer:**   在第一个直接时会被无视, close [#3406](https://github.com/NervJS/taro/issues/3406) ([4d14dd7](https://github.com/NervJS/taro/commit/4d14dd7)) +* **transformer:** 在类函数的 JSX循环无法使用 this.state 来循环 ([0401fd0](https://github.com/NervJS/taro/commit/0401fd0)) +* **transformer:** 多个 if block 有同名变量编译错误,close [#3388](https://github.com/NervJS/taro/issues/3388) ([6df5d8d](https://github.com/NervJS/taro/commit/6df5d8d)) +* **transformer:** 循环中的 wx:else 也需要用 block 包裹 ([b2ba05d](https://github.com/NervJS/taro/commit/b2ba05d)), closes [#3410](https://github.com/NervJS/taro/issues/3410) + + +### Features + +* **components-rn:** [@ant-design](https://github.com/ant-design)/react-native 按需引入 ([d24b5f6](https://github.com/NervJS/taro/commit/d24b5f6)) +* **components-rn:** ScrollView 允许传入部分 RN 自己的参数 ([4116344](https://github.com/NervJS/taro/commit/4116344)) +* **redux:** useSelector, useStore, useDispatch typing ([dd18aa9](https://github.com/NervJS/taro/commit/dd18aa9)) +* **redux:** 支持 useSelector, useDispatch, useStore ([bc6bc47](https://github.com/NervJS/taro/commit/bc6bc47)) +* **rn:** rn 的 router 和 API 添加构建,API 改造TS ([93388cc](https://github.com/NervJS/taro/commit/93388cc)) +* **taro:** 增加 createRef 的 typings ([e9b74ef](https://github.com/NervJS/taro/commit/e9b74ef)) +* **transformer:** 可以找到普通函数是否阻止冒泡, close [#3379](https://github.com/NervJS/taro/issues/3379) ([dfcf62b](https://github.com/NervJS/taro/commit/dfcf62b)) +* **transformer:** 支持导出匿名函数声明组件 ([caf66df](https://github.com/NervJS/taro/commit/caf66df)) @@ -13,6 +42,8 @@ * **cli:** 修复 taro convert 报错问题 ([d9b3d0c](https://github.com/NervJS/taro/commit/d9b3d0c)) * **h5:** 修复showLoading显示上一个showToast内容的问题, fix [#3367](https://github.com/NervJS/taro/issues/3367) ([897c2eb](https://github.com/NervJS/taro/commit/897c2eb)) * **mobx:** close [#3218](https://github.com/NervJS/taro/issues/3218) ([c2e08c4](https://github.com/NervJS/taro/commit/c2e08c4)) +* **rn:** this.$router增加path属性,与形式小程序同步 ([af0236e](https://github.com/NervJS/taro/commit/af0236e)) +* **rn:** this.$router增加path属性,与形式小程序同步 ([0175da5](https://github.com/NervJS/taro/commit/0175da5)) * **taro:** 添加百度 setPageInfo api, close [#3206](https://github.com/NervJS/taro/issues/3206) ([2ef11ff](https://github.com/NervJS/taro/commit/2ef11ff)) * **taro-h5:** 去掉 es6 方法调用 ([3282707](https://github.com/NervJS/taro/commit/3282707)) From 6666f408f7c3d5969e2f7a3788ae7ee40405822e Mon Sep 17 00:00:00 2001 From: JinJinJin <709899428@qq.com> Date: Mon, 17 Jun 2019 09:56:29 +0800 Subject: [PATCH 016/158] =?UTF-8?q?feat(taro):=20=E6=96=B0=E5=A2=9E=20defi?= =?UTF-8?q?neProperties=20polyfill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro/src/polyfill.js | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/packages/taro/src/polyfill.js b/packages/taro/src/polyfill.js index 16bc86dff07b..9f087cc2254d 100644 --- a/packages/taro/src/polyfill.js +++ b/packages/taro/src/polyfill.js @@ -22,3 +22,59 @@ if (typeof Object.assign !== 'function') { return to } } + +if (typeof Object.defineProperties !== 'function') { + Object.defineProperties = function (obj, properties) { + function convertToDescriptor (desc) { + function hasProperty (obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop) + } + + function isCallable (v) { + // NB: modify as necessary if other values than functions are callable. + return typeof v === 'function' + } + + if (typeof desc !== 'object' || desc === null) { throw new TypeError('bad desc') } + + var d = {} + + if (hasProperty(desc, 'enumerable')) d.enumerable = !!desc.enumerable + if (hasProperty(desc, 'configurable')) { d.configurable = !!desc.configurable } + if (hasProperty(desc, 'value')) d.value = desc.value + if (hasProperty(desc, 'writable')) d.writable = !!desc.writable + if (hasProperty(desc, 'get')) { + var g = desc.get + + if (!isCallable(g) && typeof g !== 'undefined') { throw new TypeError('bad get') } + d.get = g + } + if (hasProperty(desc, 'set')) { + var s = desc.set + if (!isCallable(s) && typeof s !== 'undefined') { throw new TypeError('bad set') } + d.set = s + } + + if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d)) { throw new TypeError('identity-confused descriptor') } + + return d + } + + if (typeof obj !== 'object' || obj === null) throw new TypeError('bad obj') + + properties = Object(properties) + + var keys = Object.keys(properties) + var descs = [] + + for (var i = 0; i < keys.length; i++) { + descs.push([keys[i], convertToDescriptor(properties[keys[i]])]) + } + + for (var i = 0; i < descs.length; i++) { + Object.defineProperty(obj, descs[i][0], descs[i][1]) + } + + return obj + } +} From bf85def08e3a3b66e575691bce10b2c3fc047f16 Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 17 Jun 2019 11:02:49 +0800 Subject: [PATCH 017/158] =?UTF-8?q?fix(transformer):=20=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20spread=20props=20=E5=AF=BC=E8=87=B4=E6=8A=A5=E9=94=99?= =?UTF-8?q?=EF=BC=8Cclose=20#3439?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-transformer-wx/src/utils.ts b/packages/taro-transformer-wx/src/utils.ts index c39385230036..edc564917322 100644 --- a/packages/taro-transformer-wx/src/utils.ts +++ b/packages/taro-transformer-wx/src/utils.ts @@ -177,7 +177,7 @@ export function setParentCondition (jsx: NodePath, expr: t.Expression, a Adapter.if, Adapter.else ]) - const logicalJSX = jsx.findParent(p => p.isJSXElement() && p.node.openingElement.attributes.some(a => ifAttrSet.has(a.name.name as string))) as NodePath + const logicalJSX = jsx.findParent(p => p.isJSXElement() && p.node.openingElement.attributes.some(a => t.isJSXIdentifier(a.name) && ifAttrSet.has(a.name.name))) as NodePath if (logicalJSX) { const attr = logicalJSX.node.openingElement.attributes.find(a => ifAttrSet.has(a.name.name as string)) if (attr) { From f38e13b80aea280ead7236739709630ef96d4562 Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 17 Jun 2019 13:16:33 +0800 Subject: [PATCH 018/158] =?UTF-8?q?fix(transformer):=20=E8=AF=AF=E6=8A=A5?= =?UTF-8?q?=E8=A7=A3=E6=9E=84=E8=AD=A6=E5=91=8A=EF=BC=8Cclose=20#3450?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/render.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index b1f46b3b8d1e..582a5dabe5e6 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -1429,7 +1429,7 @@ export class RenderParser { } } - if (t.isThisExpression(object) && t.isIdentifier(property)) { + if (t.isThisExpression(object) && t.isIdentifier(property) && /^render[A-Z]/.test(this.renderMethodName)) { const s = new Set(['state', 'props']) if (s.has(property.name) && path.parentPath.isMemberExpression()) { const p = path.parentPath.node.property From 8d99a2bacb1624b12de1f10c9b3fec2df75ff31f Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 17 Jun 2019 15:05:38 +0800 Subject: [PATCH 019/158] =?UTF-8?q?fix(transformer):=20mobx=20=E4=B8=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81=20import=20ReduxContext,=20close=20#3453?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/taro-transformer-wx/src/index.ts b/packages/taro-transformer-wx/src/index.ts index dfdd68bd8e2b..182eb9ec0bfd 100644 --- a/packages/taro-transformer-wx/src/index.ts +++ b/packages/taro-transformer-wx/src/index.ts @@ -644,9 +644,13 @@ export default function transform (options: Options): TransformResult { if (s.local.name === 'Provider') { specs.splice(index, 1) specs.push( - t.importSpecifier(t.identifier('setStore'), t.identifier('setStore')), - t.importSpecifier(t.identifier('ReduxContext'), t.identifier('ReduxContext')) + t.importSpecifier(t.identifier('setStore'), t.identifier('setStore')) ) + if (source === REDUX_PACKAGE_NAME) { + specs.push( + t.importSpecifier(t.identifier('ReduxContext'), t.identifier('ReduxContext')) + ) + } } }) } @@ -709,7 +713,7 @@ export default function transform (options: Options): TransformResult { t.callExpression(t.identifier('setStore'), [ t.identifier(storeName) ]) - ), ifStem) + ), mainClass.scope.getBinding('ReduxContext') ? ifStem : t.emptyStatement()) return false } return true From 91a27e0a8b631528217bd4944b630b6ed22c03ce Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Thu, 13 Jun 2019 20:42:07 +0800 Subject: [PATCH 020/158] =?UTF-8?q?feat(components-rn):=20=E5=B0=86=20reac?= =?UTF-8?q?t-native-swiper=20=E5=86=85=E5=B5=8C=E5=88=B0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Swiper/index.tsx | 3 +- .../src/lib/react-native-swiper/PropsType.tsx | 121 ++++ .../src/lib/react-native-swiper/index.tsx | 650 ++++++++++++++++++ .../src/lib/react-native-swiper/styles.tsx | 83 +++ 4 files changed, 856 insertions(+), 1 deletion(-) create mode 100644 packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx create mode 100644 packages/taro-components-rn/src/lib/react-native-swiper/index.tsx create mode 100644 packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx diff --git a/packages/taro-components-rn/src/components/Swiper/index.tsx b/packages/taro-components-rn/src/components/Swiper/index.tsx index 357c268decae..d3997ddb1ea6 100644 --- a/packages/taro-components-rn/src/components/Swiper/index.tsx +++ b/packages/taro-components-rn/src/components/Swiper/index.tsx @@ -52,7 +52,8 @@ import { StyleSheet, ViewStyle } from 'react-native' -import Swiper from 'react-native-swiper' +// import Swiper from 'react-native-swiper' +import Swiper from '../../lib/react-native-swiper' import { noop } from '../../utils' import { SwiperProps } from './PropsType' diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx new file mode 100644 index 000000000000..163107cb2326 --- /dev/null +++ b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx @@ -0,0 +1,121 @@ +import { StyleProp, ViewStyle } from 'react-native'; + +export interface ReactNativeSwiperProps { + children: any; + + // Basic + // If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column. + horizontal?: boolean; + // If no specify default enable fullscreen mode by flex: 1. + loop?: boolean; + // Set to false to disable continuous loop mode. + autoplay?: boolean; + // Set to true make control buttons visible. + showsButtons?: boolean; + // Index number of initial slide. + index?: number; + // Called with the new index when the user swiped + onIndexChanged?: (index: number) => void; + + // Custom basic style & content + // Set to true enable auto play mode. + width?: number; + // If no specify default fullscreen mode by flex: 1. + height?: number; + // See default style in source. + style?: StyleProp; + // Only load current index slide , loadMinimalSize slides before and after. + loadMinimal?: boolean; + // see loadMinimal + loadMinimalSize?: number; + // Custom loader to display when slides aren't loaded + loadMinimalLoader?: React.ReactNode; + + // Pagination + // Set to true make pagination visible. + showsPagination?: boolean; + // Custom styles will merge with the default styles. + paginationStyle?: ViewStyle; + // Complete control how to render pagination with three params (index, total, context) ref to this.state.index / this.state.total / this, For example: show numbers instead of dots. + renderPagination?: (index: number, total: number, swiper: any) => JSX.Element; + // Allow custom the dot element. + dot?: any; + // Allow custom the active-dot element. + activeDot?: any; + // Allow custom the active-dot element. + dotStyle?: StyleProp; + // Allow custom the active-dot element. + dotColor?: string; + // Allow custom the active-dot element. + activeDotColor?: string; + // Allow custom the active-dot element. + activeDotStyle?: StyleProp; + + // Autoplay + // Delay between auto play transitions (in second). + autoplayTimeout?: number; + // Cycle direction control. + autoplayDirection?: boolean; + + // Control buttons + // Set to true make control buttons visible. + buttonWrapperStyle?: any; + // Allow custom the next button. + nextButton?: JSX.Element; + // Allow custom the prev button. + prevButton?: JSX.Element; + + // Supported ScrollResponder + // When animation begins after letting up + onScrollBeginDrag?: any; + // Makes no sense why this occurs first during bounce + onMomentumScrollEnd?: any; + // Immediately after onMomentumScrollEnd + onTouchStartCapture?: any; + // Same, but bubble phase + onTouchStart?: any; + // You could hold the touch start for a long time + onTouchEnd?: any; + // When lifting up - you could pause forever before * lifting + onResponderRelease?: any; + + // If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for + // horizontal pagination. + pagingEnabled?: boolean; + // Set to true if you want to show horizontal scroll bar. + showsHorizontalScrollIndicator?: boolean + // Set to true if you want to show vertical scroll bar. + showsVerticalScrollIndicator?: boolean + // If true, the scroll view bounces when it reaches the end of the content if the content is larger then the + // scroll view along the axis of the scroll direction. If false, it disables all bouncing even if the + // alwaysBounce* props are true. + bounces?: boolean + // If true, the scroll view scrolls to top when the status bar is tapped. + scrollsToTop?: boolean + // If true, offscreen child views (whose overflow value is hidden) are removed from their native backing + // superview when offscreen. This canimprove scrolling performance on long lists. + removeClippedSubviews?: boolean + // Set to true if you need adjust content insets automation. + automaticallyAdjustContentInsets?: boolean + // Enables/Disables swiping + scrollEnabled?: boolean + + containerStyle?: StyleProp; + scrollViewStyle?: StyleProp; + disableNextButton?: boolean; +} + +export interface ReactNativeSwiperState { + width: number; + height: number; + offset: Partial<{ + x: number; + y: number; + }>, + autoplayEnd?: boolean; + loopJump?: boolean; + total: number; + index: number; + dir: 'x' | 'y'; + pIndex: number; +} diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx new file mode 100644 index 000000000000..e12135a975ac --- /dev/null +++ b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx @@ -0,0 +1,650 @@ +/** + * react-native-swiper + * + * 组件由 `react-native-swiper` 修改而来 + * + * @author leecade + * @author Manjiz + */ + +import React, { Component } from 'react' +import { + Text, + View, + ScrollView, + Dimensions, + TouchableOpacity, + ViewPagerAndroid, + Platform, + ActivityIndicator, + LayoutChangeEvent, + NativeSyntheticEvent, + NativeScrollEvent, + ViewPagerAndroidOnPageSelectedEventData +} from 'react-native' +import { ReactNativeSwiperProps, ReactNativeSwiperState } from './PropsType' +import styles from './styles' + +export default class extends Component { + /** + * @see http://facebook.github.io/react-native/docs/scrollview.html + */ + static defaultProps = { + horizontal: true, + pagingEnabled: true, + removeClippedSubviews: true, + showsPagination: true, + loop: true, + loadMinimalSize: 1, + autoplayTimeout: 2.5, + autoplayDirection: true, + index: 0, + onIndexChanged: () => null + } + + static getDerivedStateFromProps (props: ReactNativeSwiperProps, state: ReactNativeSwiperState) { + // return state.snapScrollTop !== props.scrollTop || state.snapScrollLeft !== props.scrollLeft ? { + // snapScrollTop: props.scrollTop, + // snapScrollLeft: props.scrollLeft + // } : null + const initState: any = { + autoplayEnd: false, + loopJump: false, + offset: {} + } + + initState.total = props.children ? props.children.length || 1 : 0 + + const updateIndex = state.pIndex !== props.index + + if (state.total === initState.total && !updateIndex) { + // retain the index + initState.index = state.index + } else { + initState.index = initState.total > 1 ? Math.min(props.index as number, initState.total - 1) : 0 + initState.pIndex = props.index as number + } + + const { width, height } = Dimensions.get('window') + + initState.dir = !props.horizontal ? 'y' : 'x' + + if (props.width) { + initState.width = props.width + } else if (state.width){ + initState.width = state.width + } else { + initState.width = width + } + + if (props.height) { + initState.height = props.height + } else if (state.height){ + initState.height = state.height + } else { + initState.height = height; + } + + initState.offset[initState.dir] = (initState.dir === 'y' ? height : width) * (props.index as number) + + // this.internals = { + // ...this.internals, + // isScrolling: false + // } + + return initState + } + + state: ReactNativeSwiperState = { + width: 0, + height: 0, + offset: { x: 0, y: 0 }, + total: 0, + pIndex: 0, + index: 0, + dir: 'y' + } + + /** + * Initial render flag + */ + initialRender: boolean = true + + /** + * autoplay timer + */ + autoplayTimer: any + loopJumpTimer: any + + internals: { + isScrolling: boolean; + offset: Partial<{ + x: number; + y: number; + }> + } = { + isScrolling: false, + offset: { + x: 0, + y: 0 + } + } + + $scrollView: any = React.createRef() + + getSnapshotBeforeUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState) { + return { + shouldClearAutoPlay: !this.props.autoplay && this.autoplayTimer, + ifIndexChange: prevProps.index !== this.props.index + } + } + + componentDidUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState, snapshot: { shouldClearAutoPlay: boolean; ifIndexChange: boolean; }) { + if (snapshot.shouldClearAutoPlay) { + clearTimeout(this.autoplayTimer as number) + } + // If the index has changed, we notify the parent via the onIndexChanged callback + if (snapshot.ifIndexChange) { + const { index, onIndexChanged } = this.props + onIndexChanged && onIndexChanged(index as number) + } + } + + componentDidMount () { + this.autoplay() + } + + componentWillUnmount () { + this.autoplayTimer && clearTimeout(this.autoplayTimer) + this.loopJumpTimer && clearTimeout(this.loopJumpTimer) + } + + // include internals with state + fullState () { + return Object.assign({}, this.state, this.internals) + } + + onLayout = (event: LayoutChangeEvent) => { + const { width, height } = event.nativeEvent.layout + const offset: Partial<{ x: number; y: number; }> = this.internals.offset = {} + const state: any = { width, height } + + if (this.state.total > 1) { + let setup = this.state.index + if (this.props.loop) { + setup++ + } + offset[this.state.dir] = this.state.dir === 'y' + ? height * setup + : width * setup + } + + // only update the offset in state if needed, updating offset while swiping + // causes some bad jumping / stuttering + if (!this.state.offset || width !== this.state.width || height !== this.state.height) { + state.offset = offset + } + + // related to https://github.com/leecade/react-native-swiper/issues/570 + // contentOffset is not working in react 0.48.x so we need to use scrollTo + // to emulate offset. + if (Platform.OS === 'ios') { + if (this.initialRender && this.state.total > 1) { + const node = this.$scrollView.current + node && (node as ScrollView).scrollTo({...offset, animated: false}) + this.initialRender = false; + } + } + + this.setState(state) + } + + loopJump = () => { + if (!this.state.loopJump) return + const i = this.state.index + (this.props.loop ? 1 : 0) + const node = this.$scrollView.current + if (node) { + this.loopJumpTimer = setTimeout(() => (node as ViewPagerAndroid).setPageWithoutAnimation && (node as ViewPagerAndroid).setPageWithoutAnimation(i), 50) + } + } + + /** + * Automatic rolling + */ + autoplay = () => { + if (!Array.isArray(this.props.children) || + !this.props.autoplay || + this.internals.isScrolling || + this.state.autoplayEnd) return + + this.autoplayTimer && clearTimeout(this.autoplayTimer) + this.autoplayTimer = setTimeout(() => { + if (!this.props.loop && ( + this.props.autoplayDirection + ? this.state.index === this.state.total - 1 + : this.state.index === 0 + ) + ) return this.setState({ autoplayEnd: true }) + + this.scrollBy(this.props.autoplayDirection ? 1 : -1) + }, (this.props.autoplayTimeout as number) * 1000) + } + + /** + * Scroll begin handle + * @param {object} e native event + */ + onScrollBegin = (e?: NativeSyntheticEvent) => { + const { + onScrollBeginDrag + } = this.props + // update scroll state + this.internals.isScrolling = true + onScrollBeginDrag && onScrollBeginDrag(e, this.fullState(), this) + } + + /** + * Scroll end handle + * @param {object} e native event + */ + onScrollEnd = (e: NativeSyntheticEvent|Partial>) => { + const { + onMomentumScrollEnd + } = this.props + + // update scroll state + this.internals.isScrolling = false + + let contentOffset + // making our events coming from android compatible to updateIndex logic + if (!(e as NativeSyntheticEvent).nativeEvent.contentOffset) { + if (this.state.dir === 'x') { + contentOffset = { x: (e as NativeSyntheticEvent).nativeEvent.position * this.state.width } + } else { + contentOffset = { y: (e as NativeSyntheticEvent).nativeEvent.position * this.state.height } + } + } else { + contentOffset = (e as NativeSyntheticEvent).nativeEvent.contentOffset + } + + this.updateIndex(contentOffset, this.state.dir, () => { + this.autoplay() + this.loopJump() + + // if `onMomentumScrollEnd` registered will be called here + onMomentumScrollEnd && onMomentumScrollEnd(e, this.fullState(), this) + }) + } + + /* + * Drag end handle + * @param {object} e native event + */ + onScrollEndDrag = (e: NativeSyntheticEvent) => { + const { contentOffset } = e.nativeEvent + const { horizontal, children } = this.props + const { index } = this.state + const { offset } = this.internals + const previousOffset = horizontal ? offset.x : offset.y + const newOffset = horizontal ? contentOffset.x : contentOffset.y + + if (previousOffset === newOffset && + (index === 0 || index === children.length - 1)) { + this.internals.isScrolling = false + } + } + + /** + * Update index after scroll + * @param {object} offset content offset + * @param {string} dir 'x' || 'y' + */ + updateIndex = (offset: { x?: number; y?: number }, dir: 'x'|'y', cb: any) => { + const state = this.state + let index: number = state.index + if (!this.internals.offset) // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582 + this.internals.offset = {} + const diff = (offset[dir] || 0) - (this.internals.offset[dir] || 0) + const step = dir === 'x' ? state.width : state.height + let loopJump = false + + // Do nothing if offset no change. + if (!diff) return + + // Note: if touch very very quickly and continuous, + // the variation of `index` more than 1. + // parseInt() ensures it's always an integer + index = parseInt(index + Math.round(diff / step) + '') + + if (this.props.loop) { + if (index <= -1) { + index = state.total - 1 + offset[dir] = step * state.total + loopJump = true + } else if (index >= state.total) { + index = 0 + offset[dir] = step + loopJump = true + } + } + + const newState: any = {} + newState.index = index + newState.loopJump = loopJump + + this.internals.offset = offset + + // only update offset in state if loopJump is true + if (loopJump) { + // when swiping to the beginning of a looping set for the third time, + // the new offset will be the same as the last one set in state. + // Setting the offset to the same thing will not do anything, + // so we increment it by 1 then immediately set it to what it should be, + // after render. + if (offset[dir] === this.internals.offset[dir]) { + newState.offset = { x: 0, y: 0 } + newState.offset[dir] = (offset[dir] || 0)+ 1 + this.setState(newState, () => { + this.setState({ offset: offset }, cb) + }) + } else { + newState.offset = offset + this.setState(newState, cb) + } + } else { + this.setState(newState, cb) + } + } + + /** + * Scroll by index + * @param {number} index offset index + * @param {bool} animated + */ + + scrollBy = (index: number, animated: boolean = true) => { + if (this.internals.isScrolling || this.state.total < 2) return + const state = this.state + const diff = (this.props.loop ? 1 : 0) + index + this.state.index + let x = 0 + let y = 0 + if (state.dir === 'x') x = diff * state.width + if (state.dir === 'y') y = diff * state.height + + const node = this.$scrollView.current + if (Platform.OS !== 'ios') { + node && (node as ViewPagerAndroid)[animated ? 'setPage' : 'setPageWithoutAnimation'](diff) + } else { + node && (node as ScrollView).scrollTo({ x, y, animated }) + } + + // update scroll state + this.internals.isScrolling = true + this.setState({ + autoplayEnd: false + }) + + // trigger onScrollEnd manually in android + if (!animated || Platform.OS !== 'ios') { + setImmediate(() => { + this.onScrollEnd({ + nativeEvent: { + position: diff + } + }) + }) + } + } + + scrollViewPropOverrides = () => { + const props = this.props + let overrides: any = {} + + /* + const scrollResponders = [ + 'onMomentumScrollBegin', + 'onTouchStartCapture', + 'onTouchStart', + 'onTouchEnd', + 'onResponderRelease', + ] + */ + + for (let prop in props) { + // if(~scrollResponders.indexOf(prop) + if (typeof props[prop as keyof ReactNativeSwiperProps] === 'function' && + prop !== 'onMomentumScrollEnd' && + prop !== 'renderPagination' && + prop !== 'onScrollBeginDrag' + ) { + let originResponder = props[prop as keyof ReactNativeSwiperProps] + overrides[prop] = (e: any) => originResponder(e, this.fullState(), this) + } + } + + return overrides + } + + /** + * Render pagination + * @return {object} react-dom + */ + renderPagination = () => { + // By default, dots only show when `total` >= 2 + if (this.state.total <= 1) return null + + let dots = [] + const ActiveDot = this.props.activeDot || + const Dot = this.props.dot || + for (let i = 0; i < this.state.total; i++) { + dots.push(i === this.state.index + ? React.cloneElement(ActiveDot, {key: i}) + : React.cloneElement(Dot, {key: i}) + ) + } + + return ( + + {dots} + + ) + } + + renderTitle = () => { + const child: any = this.props.children[this.state.index] + const title = child && child.props && child.props.title + return title + ? ( + {(this.props.children[this.state.index] as any).props.title} + ) + : null + } + + renderNextButton = () => { + let button: any = null + + if (this.props.loop || + this.state.index !== this.state.total - 1) { + button = this.props.nextButton || + } + + return ( + button !== null && this.scrollBy(1)} + disabled={this.props.disableNextButton} + > + + {button} + + + ) + } + + renderPrevButton = () => { + let button: any = null + + if (this.props.loop || this.state.index !== 0) { + button = this.props.prevButton || + } + + return ( + button !== null && this.scrollBy(-1)}> + + {button} + + + ) + } + + renderButtons = () => { + return ( + + {this.renderPrevButton()} + {this.renderNextButton()} + + ) + } + + onPageScrollStateChanged = (state: 'Idle' | 'Dragging' | 'Settling') => { + switch (state) { + case 'Dragging': + return this.onScrollBegin() + case 'Idle': + case 'Settling': + this.props.onTouchEnd && this.props.onTouchEnd() + } + } + + renderScrollView = (pages: any) => { + if (Platform.OS === 'ios') { + return ( + + {pages} + + ) + } + return ( + + {pages} + + ) + } + + /** + * Default render + * @return {object} react-dom + */ + render () { + const state = this.state + const props = this.props + const { + index, + total, + width, + height + } = this.state; + const { + children, + containerStyle, + loop, + loadMinimal, + loadMinimalSize, + loadMinimalLoader, + renderPagination, + showsButtons, + showsPagination, + } = this.props; + // let dir = state.dir + // let key = 0 + const loopVal = loop ? 1 : 0 + let pages: Element[] | Element = [] + + const pageStyle = [{width: width, height: height}, styles.slide] + const pageStyleLoading: any = { + width, + height, + flex: 1, + justifyContent: 'center', + alignItems: 'center' + } + + // For make infinite at least total > 1 + if (total > 1) { + // Re-design a loop model for avoid img flickering + const pagesKeys = Object.keys(children) + if (loop) { + pagesKeys.unshift(total - 1 + '') + pagesKeys.push('0') + } + + pages = pagesKeys.map((page: string, i: number) => { + if (loadMinimal) { + if (i >= (index + loopVal - (loadMinimalSize as number)) && + i <= (index + loopVal + (loadMinimalSize as number))) { + return {children[parseInt(page)]} + } else { + return ( + + {loadMinimalLoader ? loadMinimalLoader : } + + ) + } + } else { + return {children[parseInt(page)]} + } + }) + } else { + pages = {children} + } + + return ( + + {this.renderScrollView(pages)} + {showsPagination && (renderPagination + ? renderPagination(index, total, this) + : this.renderPagination())} + {this.renderTitle()} + {showsButtons && this.renderButtons()} + + ) + } +} diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx new file mode 100644 index 000000000000..035ff81a2667 --- /dev/null +++ b/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx @@ -0,0 +1,83 @@ +/** + * Default styles + * @type {StyleSheetPropType} + */ + +import { + StyleSheet +} from 'react-native' + +export default StyleSheet.create({ + container: { + backgroundColor: 'transparent', + position: 'relative', + flex: 1 + }, + + wrapperIOS: { + backgroundColor: 'transparent', + }, + + wrapperAndroid: { + backgroundColor: 'transparent', + flex: 1 + }, + + slide: { + backgroundColor: 'transparent', + }, + + pagination_x: { + position: 'absolute', + bottom: 25, + left: 0, + right: 0, + flexDirection: 'row', + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: 'transparent' + }, + + pagination_y: { + position: 'absolute', + right: 15, + top: 0, + bottom: 0, + flexDirection: 'column', + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: 'transparent' + }, + + title: { + height: 30, + justifyContent: 'center', + position: 'absolute', + paddingLeft: 10, + bottom: -30, + left: 0, + flexWrap: 'nowrap', + width: 250, + backgroundColor: 'transparent' + }, + + buttonWrapper: { + backgroundColor: 'transparent', + flexDirection: 'row', + position: 'absolute', + top: 0, + left: 0, + flex: 1, + paddingHorizontal: 10, + paddingVertical: 10, + justifyContent: 'space-between', + alignItems: 'center' + }, + + buttonText: { + fontSize: 50, + color: '#007aff' + } +}) From 7494c4105d6a27508b2621dcd7a09d31636b2266 Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Fri, 14 Jun 2019 11:05:36 +0800 Subject: [PATCH 021/158] =?UTF-8?q?fix(components-rn):=20react-native-swip?= =?UTF-8?q?er=20=E4=BF=AE=E5=A4=8D=E5=B9=B6=E6=9B=B4=E6=96=B0=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit onChange 不触发 -> 判断 state.index --- .../taro-components-rn/TCRNExample/App.js | 6 + .../TCRNExample/example/EXSwiper.js | 2 +- .../src/lib/react-native-swiper/PropsType.tsx | 45 ++- .../src/lib/react-native-swiper/index.tsx | 309 ++++++++---------- 4 files changed, 169 insertions(+), 193 deletions(-) diff --git a/packages/taro-components-rn/TCRNExample/App.js b/packages/taro-components-rn/TCRNExample/App.js index 6919e38a8feb..d93da9aba2e9 100644 --- a/packages/taro-components-rn/TCRNExample/App.js +++ b/packages/taro-components-rn/TCRNExample/App.js @@ -45,6 +45,12 @@ export default class App extends Component { console.log('view touchend') } + componentDidMount () { + // setTimeout(() => { + // this.setState({ scrollTop: 1800 }) + // }, 0) + } + render () { return ( diff --git a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js index f1824b3a7476..edcaae4535c4 100644 --- a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js +++ b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js @@ -14,7 +14,7 @@ export default class EXSwiper extends Component { interval={6000} circular={true} vertical={false} - onChange={() => null} + onChange={() => { console.log('Swiper: onChange') }} onAnimationFinish={() => null} style={{ backgroundColor: 'black' diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx index 163107cb2326..681ed5de313d 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx @@ -1,6 +1,16 @@ -import { StyleProp, ViewStyle } from 'react-native'; +import { + StyleProp, + ViewStyle, + ScrollViewProps, + ViewPagerAndroidProps, + NativeSyntheticEvent, + NativeScrollEvent +} from 'react-native'; -export interface ReactNativeSwiperProps { +export interface ReactNativeSwiperProps extends + Pick>, + Pick> +{ children: any; // Basic @@ -79,30 +89,19 @@ export interface ReactNativeSwiperProps { // When lifting up - you could pause forever before * lifting onResponderRelease?: any; - // If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for - // horizontal pagination. - pagingEnabled?: boolean; - // Set to true if you want to show horizontal scroll bar. - showsHorizontalScrollIndicator?: boolean - // Set to true if you want to show vertical scroll bar. - showsVerticalScrollIndicator?: boolean - // If true, the scroll view bounces when it reaches the end of the content if the content is larger then the - // scroll view along the axis of the scroll direction. If false, it disables all bouncing even if the - // alwaysBounce* props are true. - bounces?: boolean - // If true, the scroll view scrolls to top when the status bar is tapped. - scrollsToTop?: boolean - // If true, offscreen child views (whose overflow value is hidden) are removed from their native backing - // superview when offscreen. This canimprove scrolling performance on long lists. - removeClippedSubviews?: boolean - // Set to true if you need adjust content insets automation. - automaticallyAdjustContentInsets?: boolean - // Enables/Disables swiping - scrollEnabled?: boolean - containerStyle?: StyleProp; scrollViewStyle?: StyleProp; disableNextButton?: boolean; + + // ...ScrollViewProps + // pagingEnabled?: boolean; + // showsHorizontalScrollIndicator?: boolean; + // showsVerticalScrollIndicator?: boolean; + // bounces?: boolean; + // scrollsToTop?: boolean; + // removeClippedSubviews?: boolean; + // automaticallyAdjustContentInsets?: boolean; + // scrollEnabled?: boolean; } export interface ReactNativeSwiperState { diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx index e12135a975ac..0d1a51ed9270 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx @@ -23,6 +23,7 @@ import { ViewPagerAndroidOnPageSelectedEventData } from 'react-native' import { ReactNativeSwiperProps, ReactNativeSwiperState } from './PropsType' +import { noop } from '../../utils' import styles from './styles' export default class extends Component { @@ -39,14 +40,15 @@ export default class extends Component null + + showsHorizontalScrollIndicator: false, + showsVerticalScrollIndicator: false, + bounces: false, + scrollsToTop: false, + automaticallyAdjustContentInsets: false, } static getDerivedStateFromProps (props: ReactNativeSwiperProps, state: ReactNativeSwiperState) { - // return state.snapScrollTop !== props.scrollTop || state.snapScrollLeft !== props.scrollLeft ? { - // snapScrollTop: props.scrollTop, - // snapScrollLeft: props.scrollLeft - // } : null const initState: any = { autoplayEnd: false, loopJump: false, @@ -67,31 +69,13 @@ export default class extends Component() getSnapshotBeforeUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState) { + this.internals.isScrolling = false return { shouldClearAutoPlay: !this.props.autoplay && this.autoplayTimer, - ifIndexChange: prevProps.index !== this.props.index + ifIndexChange: prevState.index !== this.state.index } } @@ -145,8 +120,8 @@ export default class extends Component { - const { width, height } = event.nativeEvent.layout - const offset: Partial<{ x: number; y: number; }> = this.internals.offset = {} - const state: any = { width, height } - - if (this.state.total > 1) { - let setup = this.state.index - if (this.props.loop) { - setup++ - } - offset[this.state.dir] = this.state.dir === 'y' - ? height * setup - : width * setup + const { loop } = this.props + const { + index, + total, + dir, + width, + height, + offset + } = this.state + const { width: layoutWidth, height: layoutHeight } = event.nativeEvent.layout + const offsetWouldBeSet: { x?: number; y?: number; } = this.internals.offset = {} + const stateWouldBeSet: any = { width: layoutWidth, height: layoutHeight } + + if (total > 1) { + let setup = index + loop && setup++ + offsetWouldBeSet[dir] = dir === 'y' ? layoutHeight * setup : layoutWidth * setup } // only update the offset in state if needed, updating offset while swiping // causes some bad jumping / stuttering - if (!this.state.offset || width !== this.state.width || height !== this.state.height) { - state.offset = offset + if (!offset || layoutWidth !== width || layoutHeight !== height) { + stateWouldBeSet.offset = offsetWouldBeSet } // related to https://github.com/leecade/react-native-swiper/issues/570 // contentOffset is not working in react 0.48.x so we need to use scrollTo // to emulate offset. - if (Platform.OS === 'ios') { - if (this.initialRender && this.state.total > 1) { - const node = this.$scrollView.current - node && (node as ScrollView).scrollTo({...offset, animated: false}) - this.initialRender = false; - } + if (Platform.OS === 'ios' && this.initialRender && total > 1) { + const node = this.$scrollView.current + node && (node as ScrollView).scrollTo({ ...offsetWouldBeSet, animated: false }) + this.initialRender = false } - this.setState(state) + this.setState(stateWouldBeSet) } loopJump = () => { @@ -212,45 +192,42 @@ export default class extends Component { - if (!Array.isArray(this.props.children) || - !this.props.autoplay || - this.internals.isScrolling || - this.state.autoplayEnd) return + const { + children, + autoplay, + autoplayTimeout, + loop, + autoplayDirection + } = this.props + const { index, total, autoplayEnd } = this.state + if (!Array.isArray(children) || !autoplay || this.internals.isScrolling || autoplayEnd) return this.autoplayTimer && clearTimeout(this.autoplayTimer) this.autoplayTimer = setTimeout(() => { - if (!this.props.loop && ( - this.props.autoplayDirection - ? this.state.index === this.state.total - 1 - : this.state.index === 0 - ) - ) return this.setState({ autoplayEnd: true }) - - this.scrollBy(this.props.autoplayDirection ? 1 : -1) - }, (this.props.autoplayTimeout as number) * 1000) + if (!loop && (autoplayDirection ? index === total - 1 : index === 0)) { + return this.setState({ autoplayEnd: true }) + } + + this.scrollBy(autoplayDirection ? 1 : -1) + }, (autoplayTimeout as number) * 1000) } /** * Scroll begin handle - * @param {object} e native event */ onScrollBegin = (e?: NativeSyntheticEvent) => { - const { - onScrollBeginDrag - } = this.props + const { onScrollBeginDrag = noop } = this.props // update scroll state this.internals.isScrolling = true - onScrollBeginDrag && onScrollBeginDrag(e, this.fullState(), this) + onScrollBeginDrag(e, this.fullState(), this) } /** * Scroll end handle - * @param {object} e native event */ onScrollEnd = (e: NativeSyntheticEvent|Partial>) => { - const { - onMomentumScrollEnd - } = this.props + const { onMomentumScrollEnd = noop } = this.props + const { dir, width, height } = this.state // update scroll state this.internals.isScrolling = false @@ -258,54 +235,54 @@ export default class extends Component).nativeEvent.contentOffset) { - if (this.state.dir === 'x') { - contentOffset = { x: (e as NativeSyntheticEvent).nativeEvent.position * this.state.width } + if (dir === 'x') { + contentOffset = { x: (e as NativeSyntheticEvent).nativeEvent.position * width } } else { - contentOffset = { y: (e as NativeSyntheticEvent).nativeEvent.position * this.state.height } + contentOffset = { y: (e as NativeSyntheticEvent).nativeEvent.position * height } } } else { contentOffset = (e as NativeSyntheticEvent).nativeEvent.contentOffset } - this.updateIndex(contentOffset, this.state.dir, () => { + this.updateIndex(contentOffset, dir, () => { this.autoplay() this.loopJump() // if `onMomentumScrollEnd` registered will be called here - onMomentumScrollEnd && onMomentumScrollEnd(e, this.fullState(), this) + onMomentumScrollEnd(e, this.fullState(), this) }) } /* * Drag end handle - * @param {object} e native event */ onScrollEndDrag = (e: NativeSyntheticEvent) => { - const { contentOffset } = e.nativeEvent const { horizontal, children } = this.props const { index } = this.state + const { contentOffset } = e.nativeEvent const { offset } = this.internals const previousOffset = horizontal ? offset.x : offset.y const newOffset = horizontal ? contentOffset.x : contentOffset.y - if (previousOffset === newOffset && - (index === 0 || index === children.length - 1)) { + if (previousOffset === newOffset && (index === 0 || index === children.length - 1)) { this.internals.isScrolling = false } } /** * Update index after scroll - * @param {object} offset content offset - * @param {string} dir 'x' || 'y' */ updateIndex = (offset: { x?: number; y?: number }, dir: 'x'|'y', cb: any) => { - const state = this.state - let index: number = state.index - if (!this.internals.offset) // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582 + const { loop } = this.props + let { index, width, height, total } = this.state + + // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582 + if (!this.internals.offset) { this.internals.offset = {} + } + const diff = (offset[dir] || 0) - (this.internals.offset[dir] || 0) - const step = dir === 'x' ? state.width : state.height + const step = dir === 'x' ? width : height let loopJump = false // Do nothing if offset no change. @@ -316,21 +293,22 @@ export default class extends Component= state.total) { + } else if (index >= total) { index = 0 offset[dir] = step loopJump = true } } - const newState: any = {} - newState.index = index - newState.loopJump = loopJump + const stateWouldBeSet: any = { + index, + loopJump + } this.internals.offset = offset @@ -342,34 +320,33 @@ export default class extends Component { + stateWouldBeSet.offset = { x: 0, y: 0 } + stateWouldBeSet.offset[dir] = (offset[dir] || 0)+ 1 + this.setState(stateWouldBeSet, () => { this.setState({ offset: offset }, cb) }) } else { - newState.offset = offset - this.setState(newState, cb) + stateWouldBeSet.offset = offset + this.setState(stateWouldBeSet, cb) } } else { - this.setState(newState, cb) + this.setState(stateWouldBeSet, cb) } } /** * Scroll by index - * @param {number} index offset index - * @param {bool} animated */ + scrollBy = (step: number, animated: boolean = true) => { + const { loop } = this.props + const { dir, width, height, index, total } = this.state + if (this.internals.isScrolling || total < 2) return - scrollBy = (index: number, animated: boolean = true) => { - if (this.internals.isScrolling || this.state.total < 2) return - const state = this.state - const diff = (this.props.loop ? 1 : 0) + index + this.state.index + const diff = (loop ? 1 : 0) + step + index let x = 0 let y = 0 - if (state.dir === 'x') x = diff * state.width - if (state.dir === 'y') y = diff * state.height + if (dir === 'x') x = diff * width + if (dir === 'y') y = diff * height const node = this.$scrollView.current if (Platform.OS !== 'ios') { @@ -380,44 +357,34 @@ export default class extends Component { - this.onScrollEnd({ - nativeEvent: { - position: diff - } - }) - }) + setImmediate(() => this.onScrollEnd({ nativeEvent: { position: diff } })) } } scrollViewPropOverrides = () => { - const props = this.props - let overrides: any = {} - - /* - const scrollResponders = [ - 'onMomentumScrollBegin', - 'onTouchStartCapture', - 'onTouchStart', - 'onTouchEnd', - 'onResponderRelease', - ] - */ - - for (let prop in props) { + const overrides: any = {} + + // const scrollResponders = [ + // 'onMomentumScrollBegin', + // 'onTouchStartCapture', + // 'onTouchStart', + // 'onTouchEnd', + // 'onResponderRelease', + // ] + + for (let prop in this.props) { // if(~scrollResponders.indexOf(prop) - if (typeof props[prop as keyof ReactNativeSwiperProps] === 'function' && + if (typeof this.props[prop as keyof ReactNativeSwiperProps] === 'function' && prop !== 'onMomentumScrollEnd' && prop !== 'renderPagination' && prop !== 'onScrollBeginDrag' ) { - let originResponder = props[prop as keyof ReactNativeSwiperProps] + const originResponder = this.props[prop as keyof ReactNativeSwiperProps] || noop overrides[prop] = (e: any) => originResponder(e, this.fullState(), this) } } @@ -427,13 +394,12 @@ export default class extends Component= 2 */ - renderPagination = () => { - // By default, dots only show when `total` >= 2 + renderPagination = (): React.ReactNode => { if (this.state.total <= 1) return null - let dots = [] + const dots = [] const ActiveDot = this.props.activeDot || - const Dot = this.props.dot || + + const Dot = this.props.dot || ( + + ) + for (let i = 0; i < this.state.total; i++) { dots.push(i === this.state.index ? React.cloneElement(ActiveDot, {key: i}) @@ -489,7 +461,7 @@ export default class extends Component button !== null && this.scrollBy(1)} - disabled={this.props.disableNextButton} + disabled={!!this.props.disableNextButton} > {button} @@ -540,17 +512,16 @@ export default class extends Component + style={this.props.scrollViewStyle} + ref={this.$scrollView} + > {pages} ) @@ -571,11 +542,8 @@ export default class extends Component + {this.renderScrollView(pages)} {showsPagination && (renderPagination ? renderPagination(index, total, this) From ddd83f12b78fadfd44163180841875badb693bb1 Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Fri, 14 Jun 2019 15:03:06 +0800 Subject: [PATCH 022/158] =?UTF-8?q?style(components-rn):=20Swiper=20?= =?UTF-8?q?=E7=9A=84=E7=A4=BA=E4=BE=8B=E5=B1=9E=E6=80=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-components-rn/TCRNExample/example/EXSwiper.js | 2 +- packages/taro-components-rn/src/components/Swiper/index.tsx | 2 +- .../src/lib/react-native-swiper/PropsType.tsx | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js index edcaae4535c4..5019b5c0a78f 100644 --- a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js +++ b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js @@ -6,7 +6,7 @@ export default class EXSwiper extends Component { return ( Date: Fri, 14 Jun 2019 18:13:14 +0800 Subject: [PATCH 023/158] =?UTF-8?q?fix(components-rn):=20Clickable=20andro?= =?UTF-8?q?id,=20=E7=BB=91=E5=AE=9A=20onClick=20=E7=9A=84=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E8=AE=A9=20ScrollView=20=E6=97=A0=E6=B3=95=E6=BB=91?= =?UTF-8?q?=E5=8A=A8=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/ClickableSimplified/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/taro-components-rn/src/components/ClickableSimplified/index.tsx b/packages/taro-components-rn/src/components/ClickableSimplified/index.tsx index 2ae72d3e0712..9ba834885411 100644 --- a/packages/taro-components-rn/src/components/ClickableSimplified/index.tsx +++ b/packages/taro-components-rn/src/components/ClickableSimplified/index.tsx @@ -47,6 +47,7 @@ export default function (WrappedComponent: React.ComponentType) { } = this.props return !!(hoverStyle || onClick || onLongPress || onTouchstart || onTouchend) }, + onShouldBlockNativeResponder: () => false, // onMoveShouldSetPanResponder: (evt: GestureResponderEvent, gestureState) => { // const { onTouchmove, onTouchcancel, onTouchend } = this.props // return !!(onTouchmove || onTouchcancel || onTouchend) From e48ccdaf6a571d91f765ec18a616ab289b623364 Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Mon, 17 Jun 2019 10:31:40 +0800 Subject: [PATCH 024/158] =?UTF-8?q?refactor(components-rn):=20react-native?= =?UTF-8?q?-swiper,=20=E5=AE=89=E5=8D=93=E4=B8=8B=E5=8E=BB=E6=8E=89=20View?= =?UTF-8?q?PagerView,=20=E7=94=A8=20ScrollView=20=E4=BB=A3=E6=9B=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TCRNExample/example/EXSwiper.js | 5 +- .../src/lib/react-native-swiper/PropsType.tsx | 6 +- .../src/lib/react-native-swiper/index.tsx | 88 ++++++------------- 3 files changed, 33 insertions(+), 66 deletions(-) diff --git a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js index 5019b5c0a78f..48c20b106285 100644 --- a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js +++ b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js @@ -20,7 +20,10 @@ export default class EXSwiper extends Component { backgroundColor: 'black' }} > - { alert('click item') }} style={{ backgroundColor: 'red' }}> + { console.log('click item') }} + style={{ backgroundColor: 'red' }} + > Hello Swiper diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx index 808307fea494..cef5f4f1e296 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx @@ -2,13 +2,9 @@ import { StyleProp, ViewStyle, ScrollViewProps, - ViewPagerAndroidProps, } from 'react-native'; -export interface ReactNativeSwiperProps extends - Pick>, - Pick> -{ +export interface ReactNativeSwiperProps extends ScrollViewProps { children: any; // Basic diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx index 0d1a51ed9270..13702969ff43 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx @@ -14,13 +14,11 @@ import { ScrollView, Dimensions, TouchableOpacity, - ViewPagerAndroid, - Platform, ActivityIndicator, LayoutChangeEvent, NativeSyntheticEvent, NativeScrollEvent, - ViewPagerAndroidOnPageSelectedEventData + Platform, } from 'react-native' import { ReactNativeSwiperProps, ReactNativeSwiperState } from './PropsType' import { noop } from '../../utils' @@ -104,7 +102,7 @@ export default class extends Component() + $scrollView: any = React.createRef() getSnapshotBeforeUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState) { this.internals.isScrolling = false @@ -120,8 +118,8 @@ export default class extends Component 1) { + if (this.initialRender && total > 1) { const node = this.$scrollView.current node && (node as ScrollView).scrollTo({ ...offsetWouldBeSet, animated: false }) this.initialRender = false @@ -180,11 +178,12 @@ export default class extends Component { - if (!this.state.loopJump) return - const i = this.state.index + (this.props.loop ? 1 : 0) - const node = this.$scrollView.current - if (node) { - this.loopJumpTimer = setTimeout(() => (node as ViewPagerAndroid).setPageWithoutAnimation && (node as ViewPagerAndroid).setPageWithoutAnimation(i), 50) + // Android doesn't support contentOffset, So... + if (Platform.OS === 'android' && this.props.loop) { + const { index, total } = this.state + if (index !== 0 && index !== total - 1) return + const node = this.$scrollView.current + node && node.scrollTo(this.internals.offset) } } @@ -225,7 +224,7 @@ export default class extends Component|Partial>) => { + onScrollEnd = (e: NativeSyntheticEvent) => { const { onMomentumScrollEnd = noop } = this.props const { dir, width, height } = this.state @@ -234,15 +233,7 @@ export default class extends Component).nativeEvent.contentOffset) { - if (dir === 'x') { - contentOffset = { x: (e as NativeSyntheticEvent).nativeEvent.position * width } - } else { - contentOffset = { y: (e as NativeSyntheticEvent).nativeEvent.position * height } - } - } else { - contentOffset = (e as NativeSyntheticEvent).nativeEvent.contentOffset - } + contentOffset = (e as NativeSyntheticEvent).nativeEvent.contentOffset this.updateIndex(contentOffset, dir, () => { this.autoplay() @@ -349,21 +340,12 @@ export default class extends Component this.onScrollEnd({ nativeEvent: { position: diff } })) - } } scrollViewPropOverrides = () => { @@ -509,34 +491,20 @@ export default class extends Component { - if (Platform.OS === 'ios') { - return ( - - {pages} - - ) - } return ( - + {...this.scrollViewPropOverrides()} + contentContainerStyle={[styles.wrapperIOS, this.props.style]} + contentOffset={this.state.offset} + onScrollBeginDrag={this.onScrollBegin} + onMomentumScrollEnd={this.onScrollEnd} + onScrollEndDrag={this.onScrollEndDrag} + style={this.props.scrollViewStyle} + ref={this.$scrollView} + > {pages} - + ) } @@ -584,11 +552,11 @@ export default class extends Component { + pages = pagesKeys.map((pageIdx: string, i: number) => { if (loadMinimal) { if (i >= (index + loopVal - (loadMinimalSize as number)) && i <= (index + loopVal + (loadMinimalSize as number))) { - return {children[parseInt(page)]} + return {children[parseInt(pageIdx)]} } else { return ( @@ -597,7 +565,7 @@ export default class extends Component{children[parseInt(page)]} + return {children[parseInt(pageIdx)]} } }) } else { From 42e78c6d4ba86bb73e328cbdc24a99857eaa2767 Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Mon, 17 Jun 2019 14:21:14 +0800 Subject: [PATCH 025/158] =?UTF-8?q?refactor(components-rn):=20react-native?= =?UTF-8?q?-swiper,=20=E5=8E=BB=E6=8E=89=20renderTitle,=20=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=8F=AF=E8=87=AA=E8=A1=8C=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/lib/react-native-swiper/PropsType.tsx | 25 ++-- .../src/lib/react-native-swiper/index.tsx | 113 ++++++++---------- .../src/lib/react-native-swiper/styles.tsx | 12 -- 3 files changed, 59 insertions(+), 91 deletions(-) diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx index cef5f4f1e296..116c28e802e9 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx @@ -7,6 +7,18 @@ import { export interface ReactNativeSwiperProps extends ScrollViewProps { children: any; + containerStyle?: StyleProp; + scrollViewStyle?: StyleProp; + style?: StyleProp; + // Custom styles will merge with the default styles. + paginationStyle?: ViewStyle; + // Allow custom the active-dot element. + dotStyle?: StyleProp; + // Allow custom the active-dot element. + activeDotStyle?: StyleProp; + // Set to true make control buttons visible. + buttonWrapperStyle?: any; + // Basic // If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column. horizontal?: boolean; @@ -22,12 +34,9 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { onIndexChanged?: (index: number) => void; // Custom basic style & content - // Set to true enable auto play mode. width?: number; // If no specify default fullscreen mode by flex: 1. height?: number; - // See default style in source. - style?: StyleProp; // Only load current index slide , loadMinimalSize slides before and after. loadMinimal?: boolean; // see loadMinimal @@ -38,8 +47,6 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { // Pagination // Set to true make pagination visible. showsPagination?: boolean; - // Custom styles will merge with the default styles. - paginationStyle?: ViewStyle; // Complete control how to render pagination with three params (index, total, context) ref to this.state.index / this.state.total / this, For example: show numbers instead of dots. renderPagination?: (index: number, total: number, swiper: any) => JSX.Element; // Allow custom the dot element. @@ -47,13 +54,9 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { // Allow custom the active-dot element. activeDot?: any; // Allow custom the active-dot element. - dotStyle?: StyleProp; - // Allow custom the active-dot element. dotColor?: string; // Allow custom the active-dot element. activeDotColor?: string; - // Allow custom the active-dot element. - activeDotStyle?: StyleProp; // Autoplay // Delay between auto play transitions (in second). @@ -62,8 +65,6 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { autoplayDirection?: boolean; // Control buttons - // Set to true make control buttons visible. - buttonWrapperStyle?: any; // Allow custom the next button. nextButton?: JSX.Element; // Allow custom the prev button. @@ -83,8 +84,6 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { // When lifting up - you could pause forever before * lifting onResponderRelease?: any; - containerStyle?: StyleProp; - scrollViewStyle?: StyleProp; disableNextButton?: boolean; // ...ScrollViewProps diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx index 13702969ff43..2d3965d33eff 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx @@ -136,7 +136,7 @@ export default class extends Component { @@ -226,7 +226,7 @@ export default class extends Component) => { const { onMomentumScrollEnd = noop } = this.props - const { dir, width, height } = this.state + const { dir } = this.state // update scroll state this.internals.isScrolling = false @@ -296,10 +296,7 @@ export default class extends Component { - this.setState({ offset: offset }, cb) + this.setState({ offset }, cb) }) } else { stateWouldBeSet.offset = offset @@ -361,10 +358,11 @@ export default class extends Component originResponder(e, this.fullState(), this) @@ -382,36 +380,40 @@ export default class extends Component + const ActiveDot = this.props.activeDot || ( + + ) const Dot = this.props.dot || ( ) for (let i = 0; i < this.state.total; i++) { dots.push(i === this.state.index - ? React.cloneElement(ActiveDot, {key: i}) - : React.cloneElement(Dot, {key: i}) + ? React.cloneElement(ActiveDot, { key: i }) + : React.cloneElement(Dot, { key: i }) ) } @@ -422,21 +424,10 @@ export default class extends Component { - const child: any = this.props.children[this.state.index] - const title = child && child.props && child.props.title - return title - ? ( - {(this.props.children[this.state.index] as any).props.title} - ) - : null - } - renderNextButton = () => { let button: any = null - if (this.props.loop || - this.state.index !== this.state.total - 1) { + if (this.props.loop || this.state.index !== this.state.total - 1) { button = this.props.nextButton || } @@ -470,26 +461,19 @@ export default class extends Component { return ( - + {this.renderPrevButton()} {this.renderNextButton()} ) } - onPageScrollStateChanged = (state: 'Idle' | 'Dragging' | 'Settling') => { - switch (state) { - case 'Dragging': - return this.onScrollBegin() - case 'Idle': - case 'Settling': - this.props.onTouchEnd && this.props.onTouchEnd() - } - } - renderScrollView = (pages: any) => { return ( {this.renderScrollView(pages)} - {showsPagination && (renderPagination - ? renderPagination(index, total, this) - : this.renderPagination())} - {this.renderTitle()} + {showsPagination && (renderPagination ? renderPagination(index, total, this) : this.renderPagination())} {showsButtons && this.renderButtons()} ) diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx index 035ff81a2667..e29751d919d3 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx @@ -51,18 +51,6 @@ export default StyleSheet.create({ backgroundColor: 'transparent' }, - title: { - height: 30, - justifyContent: 'center', - position: 'absolute', - paddingLeft: 10, - bottom: -30, - left: 0, - flexWrap: 'nowrap', - width: 250, - backgroundColor: 'transparent' - }, - buttonWrapper: { backgroundColor: 'transparent', flexDirection: 'row', From 69aea23bcc44af4e2806e5592e893a29b26d91bc Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Mon, 17 Jun 2019 14:28:07 +0800 Subject: [PATCH 026/158] =?UTF-8?q?refactor(components-rn):=20react-native?= =?UTF-8?q?-swiper,=20=E5=8E=BB=E6=8E=89=20renderButton,=20=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=8F=AF=E8=87=AA=E8=A1=8C=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/lib/react-native-swiper/PropsType.tsx | 12 ----- .../src/lib/react-native-swiper/index.tsx | 54 ------------------- .../src/lib/react-native-swiper/styles.tsx | 18 ------- 3 files changed, 84 deletions(-) diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx index 116c28e802e9..23d23934ae7e 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx @@ -16,8 +16,6 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { dotStyle?: StyleProp; // Allow custom the active-dot element. activeDotStyle?: StyleProp; - // Set to true make control buttons visible. - buttonWrapperStyle?: any; // Basic // If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column. @@ -26,8 +24,6 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { loop?: boolean; // Set to false to disable continuous loop mode. autoplay?: boolean; - // Set to true make control buttons visible. - showsButtons?: boolean; // Index number of initial slide. index?: number; // Called with the new index when the user swiped @@ -64,12 +60,6 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { // Cycle direction control. autoplayDirection?: boolean; - // Control buttons - // Allow custom the next button. - nextButton?: JSX.Element; - // Allow custom the prev button. - prevButton?: JSX.Element; - // Supported ScrollResponder // When animation begins after letting up onScrollBeginDrag?: any; @@ -84,8 +74,6 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { // When lifting up - you could pause forever before * lifting onResponderRelease?: any; - disableNextButton?: boolean; - // ...ScrollViewProps // pagingEnabled?: boolean; // showsHorizontalScrollIndicator?: boolean; diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx index 2d3965d33eff..76e99d53ca77 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx @@ -9,11 +9,9 @@ import React, { Component } from 'react' import { - Text, View, ScrollView, Dimensions, - TouchableOpacity, ActivityIndicator, LayoutChangeEvent, NativeSyntheticEvent, @@ -424,56 +422,6 @@ export default class extends Component { - let button: any = null - - if (this.props.loop || this.state.index !== this.state.total - 1) { - button = this.props.nextButton || - } - - return ( - button !== null && this.scrollBy(1)} - disabled={!!this.props.disableNextButton} - > - - {button} - - - ) - } - - renderPrevButton = () => { - let button: any = null - - if (this.props.loop || this.state.index !== 0) { - button = this.props.prevButton || - } - - return ( - button !== null && this.scrollBy(-1)}> - - {button} - - - ) - } - - renderButtons = () => { - return ( - - {this.renderPrevButton()} - {this.renderNextButton()} - - ) - } - renderScrollView = (pages: any) => { return ( {this.renderScrollView(pages)} {showsPagination && (renderPagination ? renderPagination(index, total, this) : this.renderPagination())} - {showsButtons && this.renderButtons()} ) } diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx index e29751d919d3..484fcba5e5d9 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx @@ -49,23 +49,5 @@ export default StyleSheet.create({ justifyContent: 'center', alignItems: 'center', backgroundColor: 'transparent' - }, - - buttonWrapper: { - backgroundColor: 'transparent', - flexDirection: 'row', - position: 'absolute', - top: 0, - left: 0, - flex: 1, - paddingHorizontal: 10, - paddingVertical: 10, - justifyContent: 'space-between', - alignItems: 'center' - }, - - buttonText: { - fontSize: 50, - color: '#007aff' } }) From 3646ec888bf97e6161d1b27115095796e7cbf88c Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Mon, 17 Jun 2019 16:04:03 +0800 Subject: [PATCH 027/158] =?UTF-8?q?feat(components-rn):=20Swiper,=20?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=9B=B4=E6=8E=A5=E4=BB=8E=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E4=BC=A0=E5=85=A5=20width,=20height=20=E5=92=8C=20margin*,?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E9=9C=80=E8=A6=81=E5=A5=97=20View,=20margin*?= =?UTF-8?q?=20=E4=BD=9C=E7=94=A8=E5=9C=A8=E5=86=85=E5=B1=82=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=A0=B7=E5=BC=8F=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TCRNExample/example/EXSwiper.js | 5 ++++- .../src/components/Swiper/index.tsx | 16 ++++++++++++---- .../src/lib/react-native-swiper/PropsType.tsx | 1 + .../src/lib/react-native-swiper/index.tsx | 2 +- .../src/lib/react-native-swiper/styles.tsx | 7 +------ 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js index 48c20b106285..c84ba49bc158 100644 --- a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js +++ b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js @@ -4,7 +4,7 @@ import { View, Text, Swiper, SwiperItem, Image } from '../../dist' export default class EXSwiper extends Component { render () { return ( - + { console.log('Swiper: onChange') }} onAnimationFinish={() => null} style={{ + marginTop: 30, + width: 280, + height: 200, backgroundColor: 'black' }} > diff --git a/packages/taro-components-rn/src/components/Swiper/index.tsx b/packages/taro-components-rn/src/components/Swiper/index.tsx index d40c2606a6f3..6733ff29c441 100644 --- a/packages/taro-components-rn/src/components/Swiper/index.tsx +++ b/packages/taro-components-rn/src/components/Swiper/index.tsx @@ -92,13 +92,21 @@ class _Swiper extends React.Component { vertical, } = this.props - let styleHeight: number | undefined + // 从样式中取出部分常用样式 let formattedStyle: ViewStyle | undefined + const containerStyle: { [key: string]: any } = {} if (style) { const flattenStyle: ViewStyle = StyleSheet.flatten(style) if (flattenStyle) { - styleHeight = flattenStyle.height as number - delete flattenStyle.height + for (let key in flattenStyle) { + if (/width|height|margin.*/.test(key)) { + containerStyle[key] = flattenStyle[key as keyof ViewStyle] + delete flattenStyle[key as keyof ViewStyle] + } + } + if (containerStyle.width || containerStyle.height) { + containerStyle.flex = 0 + } formattedStyle = flattenStyle } } @@ -115,7 +123,7 @@ class _Swiper extends React.Component { horizontal={!vertical} onIndexChanged={this.onIndexChanged} onMomentumScrollEnd={this.onMomentumScrollEnd} - height={styleHeight} + containerStyle={containerStyle} style={formattedStyle || style} > {children} diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx index 23d23934ae7e..ce4d2453b73b 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx @@ -9,6 +9,7 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { containerStyle?: StyleProp; scrollViewStyle?: StyleProp; + // -> ScrollView.contentContainerStyle style?: StyleProp; // Custom styles will merge with the default styles. paginationStyle?: ViewStyle; diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx index 76e99d53ca77..c6f178b74028 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx @@ -427,7 +427,7 @@ export default class extends Component Date: Mon, 17 Jun 2019 16:59:55 +0800 Subject: [PATCH 028/158] =?UTF-8?q?feat(components):=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=20=20Image=20=E6=96=B0=E5=A2=9E=20lazyLoad=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/image/index.js | 146 +++++++++++++++++- .../src/components/image/style/index.scss | 3 + 2 files changed, 142 insertions(+), 7 deletions(-) diff --git a/packages/taro-components/src/components/image/index.js b/packages/taro-components/src/components/image/index.js index be721bbe6c3a..6e23925eab74 100644 --- a/packages/taro-components/src/components/image/index.js +++ b/packages/taro-components/src/components/image/index.js @@ -6,20 +6,152 @@ import './style/index.scss' class Image extends Nerv.Component { constructor () { super(...arguments) + this.state = { + isLoaded: false + } + this._handleScroll = this._handleScroll.bind(this) + this.handleScroll = this.throttle(this._handleScroll, 100) + } + + componentDidMount () { + if (this.props.lazyLoad) { + window.addEventListener('scroll', this.handleScroll) + window.addEventListener('resize', this.handleScroll) + this._handleScroll() + } + } + + componentWillUnMount () { + if (this.props.lazyLoad) { + window.removeEventListener('scroll', this.handleScroll) + window.removeEventListener('resize', this.handleScroll) + } + } + + getClientHeight () { + let clientHeight = 0 + if (document.body.clientHeight && document.documentElement.clientHeight) { + clientHeight = Math.min( + document.body.clientHeight, + document.documentElement.clientHeight + ) + } else { + clientHeight = Math.max( + document.body.clientHeight, + document.documentElement.clientHeight + ) + } + return clientHeight + } + + getScrollTop () { + let scrollTop = 0 + if (document.documentElement && document.documentElement.scrollTop) { + scrollTop = document.documentElement.scrollTop + } else if (document.body) { + scrollTop = document.body.scrollTop + } else { + scrollTop = window.scrollY || window.pageYOffset + } + + return scrollTop + } + + throttle (fn, delay) { + let timer = null + + return function () { + let context = this + let args = arguments + clearTimeout(timer) + timer = setTimeout(function () { + fn.apply(context, args) + }, delay) + } + } + + _handleScroll () { + const { offset = 0 } = this.props // 偏移量 + + const { nodeTop, nodeBottom } = this.getNodeTop() + + const viewTop = this.getScrollTop() + const viewBottom = viewTop + this.getClientHeight() + + // 当图片出现在视野范围内,设置真正的图片,同时移除监听 + if (nodeBottom + offset >= viewTop && nodeTop - offset <= viewBottom) { + this.setState( + { + isLoaded: true + }, + () => { + Nerv.findDOMNode(this).children[0].src = this.props.src + } + ) + window.removeEventListener('scroll', this.handleScroll) + window.removeEventListener('resize', this.handleScroll) + } + } + + getNodeTop () { + const viewTop = this.getScrollTop() + + const img = Nerv.findDOMNode(this) // 当前节点 + const nodeTop = img.getBoundingClientRect().top + viewTop + const nodeBottom = nodeTop + img.offsetHeight + return { + nodeTop: nodeTop, + nodeBottom: nodeBottom + } } render () { - const { className, src, style, mode, onLoad, onError, ...reset } = this.props - const cls = classNames('taro-img', { - 'taro-img__widthfix': mode === 'widthFix' - }, className) - const imgCls = + const { + className, + src, + style, + mode, + onLoad, + onError, + lazyLoad, + ...reset + } = this.props + const cls = classNames( + 'taro-img', + { + 'taro-img__widthfix': mode === 'widthFix' + }, + className + ) + const imgCls = classNames( 'taro-img__mode-' + - (mode || 'scaleToFill').toLowerCase().replace(/\s/g, '') + (mode || 'scaleToFill').toLowerCase().replace(/\s/g, '') + ) + + let currenSrc = src + + if (lazyLoad) { + const { isLoaded } = this.state + currenSrc = isLoaded ? src : '' + } return (
- + {lazyLoad ? ( + + ) : ( + + )}
) } diff --git a/packages/taro-components/src/components/image/style/index.scss b/packages/taro-components/src/components/image/style/index.scss index d4e86dd7f368..0d64e943571e 100644 --- a/packages/taro-components/src/components/image/style/index.scss +++ b/packages/taro-components/src/components/image/style/index.scss @@ -1,3 +1,6 @@ +img[src=""] { + opacity: 0; +} .taro-img { display: inline-block; overflow: hidden; From 1ab61236b8349b5c9289bbd6fe854528b96c5cc0 Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 17 Jun 2019 18:54:35 +0800 Subject: [PATCH 029/158] =?UTF-8?q?fix(transformer):=20=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E8=AE=A2=E9=98=85=20redux=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20close=20#3456=20useLayoutEffect=20=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=97=B6=E6=9C=BA=E5=A4=AA=E6=97=A9=EF=BC=8C?= =?UTF-8?q?=E8=80=8C=20taro-redux=20=E7=9A=84dispatch=20=E6=98=AF=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E8=B0=83=E7=94=A8=E3=80=82=20=E4=B8=8D=E5=83=8F=20rea?= =?UTF-8?q?ct=20=E4=B8=80=E6=A0=B7=E6=9C=89=E4=B8=80=E4=B8=AA=20batch=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=94=BE=E5=88=B0=E4=B8=8B=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=20eventloop,=20=E6=89=80=E4=BB=A5=E4=BC=9A=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=A4=B1=E8=B4=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-redux/src/hooks/use-selector.js | 6 +++--- packages/taro-transformer-wx/src/index.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/taro-redux/src/hooks/use-selector.js b/packages/taro-redux/src/hooks/use-selector.js index 4cd33535858f..9f4092cd4133 100644 --- a/packages/taro-redux/src/hooks/use-selector.js +++ b/packages/taro-redux/src/hooks/use-selector.js @@ -1,4 +1,4 @@ -import { useReducer, useRef, useMemo, useLayoutEffect } from '@tarojs/taro' +import { useReducer, useRef, useMemo, useEffect } from '@tarojs/taro' import { useReduxContext } from './use-redux-context' import Subscription from '../utils/subscription' import invariant from '../utils/invariant' @@ -68,13 +68,13 @@ export function useSelector (selector, equalityFn = refEquality) { throw new Error(errorMessage) } - useLayoutEffect(() => { + useEffect(() => { latestSelector.current = selector latestSelectedState.current = selectedState latestSubscriptionCallbackError.current = undefined }) - useLayoutEffect( + useEffect( () => { function checkForUpdates () { try { diff --git a/packages/taro-transformer-wx/src/index.ts b/packages/taro-transformer-wx/src/index.ts index 182eb9ec0bfd..8f2dacaf5dd9 100644 --- a/packages/taro-transformer-wx/src/index.ts +++ b/packages/taro-transformer-wx/src/index.ts @@ -222,6 +222,7 @@ export default function transform (options: Options): TransformResult { options.env = Object.assign({ 'process.env.TARO_ENV': options.adapter || 'weapp' }, options.env || {}) setTransformOptions(options) setting.sourceCode = code + let hasReduxBinding = false // babel-traverse 无法生成 Hub // 导致 Path#getSource|buildCodeFrameError 都无法直接使用 // 原因大概是 babylon.parse 没有生成 File 实例导致 scope 和 path 原型上都没有 `file` @@ -647,6 +648,7 @@ export default function transform (options: Options): TransformResult { t.importSpecifier(t.identifier('setStore'), t.identifier('setStore')) ) if (source === REDUX_PACKAGE_NAME) { + hasReduxBinding = true specs.push( t.importSpecifier(t.identifier('ReduxContext'), t.identifier('ReduxContext')) ) @@ -713,7 +715,7 @@ export default function transform (options: Options): TransformResult { t.callExpression(t.identifier('setStore'), [ t.identifier(storeName) ]) - ), mainClass.scope.getBinding('ReduxContext') ? ifStem : t.emptyStatement()) + ), hasReduxBinding ? ifStem : t.emptyStatement()) return false } return true From 6af6e2cf412d0627050d4cfe1bb95a4f67093d90 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 17 Jun 2019 22:29:58 +0800 Subject: [PATCH 030/158] chore(release): publish v1.3.2 --- lerna.json | 2 +- .../package.json | 2 +- .../package.json | 4 ++-- packages/css-to-react-native/package.json | 2 +- packages/eslint-config-taro/package.json | 4 ++-- packages/eslint-plugin-taro/package.json | 2 +- .../postcss-plugin-constparse/package.json | 2 +- packages/postcss-pxtransform/package.json | 2 +- packages/postcss-unit-transform/package.json | 2 +- .../stylelint-config-taro-rn/package.json | 4 ++-- packages/stylelint-taro-rn/package.json | 2 +- packages/taro-alipay/package.json | 6 ++--- packages/taro-async-await/package.json | 2 +- packages/taro-cli/package.json | 22 +++++++++---------- packages/taro-components-qa/package.json | 2 +- packages/taro-components-rn/package.json | 2 +- packages/taro-components/package.json | 6 ++--- packages/taro-h5/package.json | 6 ++--- packages/taro-mobx-common/package.json | 2 +- packages/taro-mobx-h5/package.json | 4 ++-- packages/taro-mobx-rn/package.json | 4 ++-- packages/taro-mobx/package.json | 4 ++-- packages/taro-plugin-babel/package.json | 2 +- packages/taro-plugin-csso/package.json | 2 +- packages/taro-plugin-less/package.json | 2 +- packages/taro-plugin-sass/package.json | 2 +- packages/taro-plugin-stylus/package.json | 2 +- packages/taro-plugin-typescript/package.json | 2 +- packages/taro-plugin-uglifyjs/package.json | 2 +- packages/taro-qq/package.json | 6 ++--- packages/taro-quickapp/package.json | 6 ++--- packages/taro-redux-h5/package.json | 4 ++-- packages/taro-redux-rn/package.json | 2 +- packages/taro-redux/package.json | 6 ++--- packages/taro-rn-runner/package.json | 2 +- packages/taro-rn/package.json | 4 ++-- packages/taro-router-rn/package.json | 2 +- packages/taro-router/package.json | 4 ++-- packages/taro-swan/package.json | 6 ++--- packages/taro-transformer-wx/package.json | 6 ++--- packages/taro-tt/package.json | 6 ++--- packages/taro-utils/package.json | 2 +- packages/taro-weapp/package.json | 6 ++--- packages/taro-webpack-runner/package.json | 10 ++++----- packages/taro-with-weapp/package.json | 4 ++-- packages/taro/package.json | 2 +- packages/taroize/package.json | 2 +- 47 files changed, 91 insertions(+), 91 deletions(-) diff --git a/lerna.json b/lerna.json index 60a7b98ca9bc..4ca7478c21bb 100644 --- a/lerna.json +++ b/lerna.json @@ -53,6 +53,6 @@ "message": "chore(release): publish %s" } }, - "version": "1.3.1", + "version": "1.3.2", "npmClient": "npm" } diff --git a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json index f15f8aacba2b..513da8db622d 100644 --- a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json +++ b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-jsx-to-stylesheet", - "version": "1.3.1", + "version": "1.3.2", "description": "Transform stylesheet selector to style in JSX Elements.", "license": "MIT", "main": "src/index.js", diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json index 9bde7fac277d..f9bc023af016 100644 --- a/packages/babel-plugin-transform-taroapi/package.json +++ b/packages/babel-plugin-transform-taroapi/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-taroapi", - "version": "1.3.1", + "version": "1.3.2", "main": "dist/index.js", "license": "MIT", "scripts": { @@ -10,7 +10,7 @@ "test": "jest" }, "devDependencies": { - "@tarojs/taro-h5": "1.3.1", + "@tarojs/taro-h5": "1.3.2", "@types/babel-core": "^6.25.5", "@types/babel-traverse": "^6.25.4", "@types/babel-types": "^7.0.4", diff --git a/packages/css-to-react-native/package.json b/packages/css-to-react-native/package.json index 5ae7241bd226..32066324bf31 100644 --- a/packages/css-to-react-native/package.json +++ b/packages/css-to-react-native/package.json @@ -1,7 +1,7 @@ { "name": "taro-css-to-react-native", "description": "Convert CSS text to a React Native stylesheet object", - "version": "1.3.1", + "version": "1.3.2", "main": "dist/index.js", "license": "MIT", "scripts": { diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json index c2bfaf9501de..0ac71ee6271c 100644 --- a/packages/eslint-config-taro/package.json +++ b/packages/eslint-config-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-taro", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro specific linting rules for ESLint", "main": "index.js", "files": [ @@ -27,6 +27,6 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "eslint-plugin-taro": "1.3.1" + "eslint-plugin-taro": "1.3.2" } } diff --git a/packages/eslint-plugin-taro/package.json b/packages/eslint-plugin-taro/package.json index f63ffa8e868f..338f7a6d9920 100644 --- a/packages/eslint-plugin-taro/package.json +++ b/packages/eslint-plugin-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-taro", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro specific linting plugin for ESLint", "main": "index.js", "files": [ diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json index b3536507ee1a..a2681ad294a8 100644 --- a/packages/postcss-plugin-constparse/package.json +++ b/packages/postcss-plugin-constparse/package.json @@ -1,6 +1,6 @@ { "name": "postcss-plugin-constparse", - "version": "1.3.1", + "version": "1.3.2", "description": "parse constants defined in config", "main": "index.js", "author": "Simba", diff --git a/packages/postcss-pxtransform/package.json b/packages/postcss-pxtransform/package.json index 6c4c3e4a2646..bfb3d6bb3fe9 100644 --- a/packages/postcss-pxtransform/package.json +++ b/packages/postcss-pxtransform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-pxtransform", - "version": "1.3.1", + "version": "1.3.2", "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位", "keywords": [ "postcss", diff --git a/packages/postcss-unit-transform/package.json b/packages/postcss-unit-transform/package.json index 414181ce828a..c06c6db5d6ac 100644 --- a/packages/postcss-unit-transform/package.json +++ b/packages/postcss-unit-transform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-taro-unit-transform", - "version": "1.3.1", + "version": "1.3.2", "description": "小程序单位转换", "main": "index.js", "scripts": { diff --git a/packages/stylelint-config-taro-rn/package.json b/packages/stylelint-config-taro-rn/package.json index c34b80a4ce93..4ce2a24274ca 100644 --- a/packages/stylelint-config-taro-rn/package.json +++ b/packages/stylelint-config-taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-config-taro-rn", - "version": "1.3.1", + "version": "1.3.2", "description": "Shareable stylelint config for React Native CSS modules", "main": "index.js", "files": [ @@ -28,6 +28,6 @@ "jest": "^23.6.0", "npmpub": "^4.1.0", "stylelint": "9.3.0", - "stylelint-taro-rn": "1.3.1" + "stylelint-taro-rn": "1.3.2" } } diff --git a/packages/stylelint-taro-rn/package.json b/packages/stylelint-taro-rn/package.json index 5a2c3b494db4..9995864ba887 100644 --- a/packages/stylelint-taro-rn/package.json +++ b/packages/stylelint-taro-rn/package.json @@ -1,7 +1,7 @@ { "name": "stylelint-taro-rn", "description": "A collection of React Native specific rules for stylelint", - "version": "1.3.1", + "version": "1.3.2", "main": "dist/index.js", "babel": { "presets": [ diff --git a/packages/taro-alipay/package.json b/packages/taro-alipay/package.json index bf18d70b8b03..77877ae5a6bb 100644 --- a/packages/taro-alipay/package.json +++ b/packages/taro-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-alipay", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro alipay framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.1", - "@tarojs/utils": "1.3.1", + "@tarojs/taro": "1.3.2", + "@tarojs/utils": "1.3.2", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-async-await/package.json b/packages/taro-async-await/package.json index d25f1b57475d..61f564b13385 100644 --- a/packages/taro-async-await/package.json +++ b/packages/taro-async-await/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/async-await", - "version": "1.3.1", + "version": "1.3.2", "description": "taro async await", "main": "index.js", "scripts": { diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json index 03edaabefc88..a50160c70dda 100644 --- a/packages/taro-cli/package.json +++ b/packages/taro-cli/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/cli", - "version": "1.3.1", + "version": "1.3.2", "description": "cli tool for taro", "main": "index.js", "scripts": { @@ -30,8 +30,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taroize": "1.3.1", - "@tarojs/transformer-wx": "1.3.1", + "@tarojs/taroize": "1.3.2", + "@tarojs/transformer-wx": "1.3.2", "@types/request": "^2.48.1", "autoprefixer": "^8.4.1", "babel-core": "^6.26.3", @@ -41,7 +41,7 @@ "babel-plugin-remove-dead-code": "^1.3.2", "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-define": "^1.3.0", - "babel-plugin-transform-jsx-to-stylesheet": "1.3.1", + "babel-plugin-transform-jsx-to-stylesheet": "1.3.2", "babel-plugin-transform-react-jsx": "^6.24.1", "babel-template": "^6.26.0", "babel-traverse": "^6.26.0", @@ -56,10 +56,10 @@ "ejs": "^2.6.1", "envinfo": "^6.0.1", "eslint": "^4.15.0", - "eslint-config-taro": "1.3.1", + "eslint-config-taro": "1.3.2", "eslint-plugin-import": "^2.8.0", "eslint-plugin-react": "^7.4.0", - "eslint-plugin-taro": "1.3.1", + "eslint-plugin-taro": "1.3.2", "eslint-plugin-typescript": "^0.12.0", "fbjs": "^1.0.0", "fs-extra": "^5.0.0", @@ -81,7 +81,7 @@ "postcss-modules-resolve-imports": "^1.3.0", "postcss-modules-scope": "^1.1.0", "postcss-modules-values": "^1.3.0", - "postcss-pxtransform": "1.3.1", + "postcss-pxtransform": "1.3.2", "postcss-reporter": "^6.0.1", "postcss-taro-unit-transform": "1.2.15", "postcss-url": "^7.3.2", @@ -92,16 +92,16 @@ "semver": "^5.5.0", "shelljs": "^0.8.1", "stylelint": "9.3.0", - "stylelint-config-taro-rn": "1.3.1", - "stylelint-taro-rn": "1.3.1", - "taro-css-to-react-native": "1.3.1", + "stylelint-config-taro-rn": "1.3.2", + "stylelint-taro-rn": "1.3.2", + "taro-css-to-react-native": "1.3.2", "through2": "^2.0.3", "vinyl": "^2.1.0", "vinyl-fs": "^3.0.2", "yauzl": "2.10.0" }, "devDependencies": { - "@tarojs/taro": "1.3.1", + "@tarojs/taro": "1.3.2", "@types/autoprefixer": "^9.1.1", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.2", diff --git a/packages/taro-components-qa/package.json b/packages/taro-components-qa/package.json index 4852f823afad..a0fe2ebecce6 100644 --- a/packages/taro-components-qa/package.json +++ b/packages/taro-components-qa/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-qa", - "version": "1.3.1", + "version": "1.3.2", "description": "多端解决方案基础组件(快应用)", "main": "./index.js", "files": [ diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index ec8224c916b3..ed1681ecd9f9 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-rn", - "version": "1.3.1", + "version": "1.3.2", "description": "多端解决方案基础组件(RN)", "main": "./dist/index.js", "scripts": { diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json index 24d7af8d10d3..ddb30f84d190 100644 --- a/packages/taro-components/package.json +++ b/packages/taro-components/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components", - "version": "1.3.1", + "version": "1.3.2", "description": "", "main:h5": "src/index.js", "main": "dist/index.js", @@ -49,14 +49,14 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0", "@babel/plugin-transform-react-jsx": "^7.0.0", "@babel/preset-env": "^7.1.5", - "@tarojs/taro-h5": "1.3.1", + "@tarojs/taro-h5": "1.3.2", "@types/react": "^16.4.6", "@types/urijs": "^1.15.38", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "10.0.1", "babel-jest": "^22.4.4", "babel-loader": "^8.0.5", - "babel-plugin-transform-taroapi": "1.3.1", + "babel-plugin-transform-taroapi": "1.3.2", "css-loader": "^2.1.1", "file-loader": "^3.0.1", "jest": "^22.4.4", diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json index ffd25483a3ab..1ca30eca3a50 100644 --- a/packages/taro-h5/package.json +++ b/packages/taro-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-h5", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro h5 framework", "main:h5": "src/index.js", "main": "dist/index.js", @@ -43,8 +43,8 @@ "@babel/plugin-proposal-object-rest-spread": "^7.3.4", "@babel/plugin-transform-react-jsx": "^7.2.2", "@babel/preset-env": "^7.3.4", - "@tarojs/components": "1.3.1", - "@tarojs/taro": "1.3.1", + "@tarojs/components": "1.3.2", + "@tarojs/taro": "1.3.2", "babel-core": "7.0.0-bridge.0", "babel-jest": "24.4.0", "eslint": "^4.18.2", diff --git a/packages/taro-mobx-common/package.json b/packages/taro-mobx-common/package.json index 111bb4247d42..fad3f82989fb 100644 --- a/packages/taro-mobx-common/package.json +++ b/packages/taro-mobx-common/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-common", - "version": "1.3.1", + "version": "1.3.2", "description": "mobx library for taro", "keywords": [ "mobx", diff --git a/packages/taro-mobx-h5/package.json b/packages/taro-mobx-h5/package.json index e0be7ec6f5d2..6d50223159d2 100644 --- a/packages/taro-mobx-h5/package.json +++ b/packages/taro-mobx-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-h5", - "version": "1.3.1", + "version": "1.3.2", "description": "mobx-h5 for taro", "keywords": [ "mobx", @@ -29,7 +29,7 @@ "nervjs": "^1.4.0" }, "dependencies": { - "@tarojs/mobx-common": "1.3.1" + "@tarojs/mobx-common": "1.3.2" }, "devDependencies": { "rimraf": "^2.6.2", diff --git a/packages/taro-mobx-rn/package.json b/packages/taro-mobx-rn/package.json index 08ace1f23aec..2638c3bd27e9 100644 --- a/packages/taro-mobx-rn/package.json +++ b/packages/taro-mobx-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-rn", - "version": "1.3.1", + "version": "1.3.2", "description": "mobx-rn for taro", "keywords": [ "mobx", @@ -18,7 +18,7 @@ "src" ], "dependencies": { - "@tarojs/mobx-common": "1.3.1", + "@tarojs/mobx-common": "1.3.2", "@tarojs/taro-rn": "1.1.7" } } diff --git a/packages/taro-mobx/package.json b/packages/taro-mobx/package.json index 979d178ec352..925b37d2aee7 100644 --- a/packages/taro-mobx/package.json +++ b/packages/taro-mobx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx", - "version": "1.3.1", + "version": "1.3.2", "description": "mobx for taro", "keywords": [ "mobx", @@ -22,7 +22,7 @@ "clear": "rimraf dist" }, "dependencies": { - "@tarojs/mobx-common": "1.3.1" + "@tarojs/mobx-common": "1.3.2" }, "peerDependencies": { "mobx": "4.8.0" diff --git a/packages/taro-plugin-babel/package.json b/packages/taro-plugin-babel/package.json index 10a906d41a00..a15511e771ed 100644 --- a/packages/taro-plugin-babel/package.json +++ b/packages/taro-plugin-babel/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-babel", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro babel编译", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-csso/package.json b/packages/taro-plugin-csso/package.json index 6f5157eebb61..b0379909f0bf 100644 --- a/packages/taro-plugin-csso/package.json +++ b/packages/taro-plugin-csso/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-csso", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro压缩CSS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-less/package.json b/packages/taro-plugin-less/package.json index 514a67d25109..6b1e774bf0b8 100644 --- a/packages/taro-plugin-less/package.json +++ b/packages/taro-plugin-less/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-less", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro 编译 less 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-sass/package.json b/packages/taro-plugin-sass/package.json index 9e5f4b68893e..0d1a4cfb4d1f 100644 --- a/packages/taro-plugin-sass/package.json +++ b/packages/taro-plugin-sass/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-sass", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro编译sass文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-stylus/package.json b/packages/taro-plugin-stylus/package.json index 4b027424901f..ac354660cf32 100644 --- a/packages/taro-plugin-stylus/package.json +++ b/packages/taro-plugin-stylus/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-stylus", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro 编译 stylus 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-typescript/package.json b/packages/taro-plugin-typescript/package.json index aed90c7e3479..32073a8402c8 100644 --- a/packages/taro-plugin-typescript/package.json +++ b/packages/taro-plugin-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-typescript", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro TypeScript 编译插件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-uglifyjs/package.json b/packages/taro-plugin-uglifyjs/package.json index fc83df62eeb1..6ba96ffba759 100644 --- a/packages/taro-plugin-uglifyjs/package.json +++ b/packages/taro-plugin-uglifyjs/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-uglifyjs", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro压缩JS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-qq/package.json b/packages/taro-qq/package.json index dbbb83de42fb..68502118ae04 100644 --- a/packages/taro-qq/package.json +++ b/packages/taro-qq/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-qq", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro qq framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.1", - "@tarojs/utils": "1.3.1", + "@tarojs/taro": "1.3.2", + "@tarojs/utils": "1.3.2", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-quickapp/package.json b/packages/taro-quickapp/package.json index 4da97d825ca5..c92fe5ec1be2 100644 --- a/packages/taro-quickapp/package.json +++ b/packages/taro-quickapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-quickapp", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro quickapp framework", "main": "index.js", "files": [ @@ -23,8 +23,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.1", - "@tarojs/utils": "1.3.1", + "@tarojs/taro": "1.3.2", + "@tarojs/utils": "1.3.2", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-redux-h5/package.json b/packages/taro-redux-h5/package.json index 329c79ee88dc..fe18d11eb4b9 100644 --- a/packages/taro-redux-h5/package.json +++ b/packages/taro-redux-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux-h5", - "version": "1.3.1", + "version": "1.3.2", "description": "Forked react-redux for taro", "keywords": [ "react", @@ -46,7 +46,7 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.49", "@babel/plugin-transform-react-jsx": "^7.0.0-beta.49", "@babel/preset-env": "^7.0.0-beta.49", - "@tarojs/taro-h5": "1.3.1", + "@tarojs/taro-h5": "1.3.2", "babel-plugin-transform-react-remove-prop-types": "^0.4.13", "redux": "^4.0.0", "rimraf": "^2.6.2", diff --git a/packages/taro-redux-rn/package.json b/packages/taro-redux-rn/package.json index a7b90f012c0f..97c48d66841e 100644 --- a/packages/taro-redux-rn/package.json +++ b/packages/taro-redux-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-redux-rn", - "version": "1.3.1", + "version": "1.3.2", "description": "taro-redux-rn", "main": "./src/index.js", "files": [ diff --git a/packages/taro-redux/package.json b/packages/taro-redux/package.json index 70675e38eeee..01366fee5a8f 100644 --- a/packages/taro-redux/package.json +++ b/packages/taro-redux/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux", - "version": "1.3.1", + "version": "1.3.2", "description": "Redux for Taro", "main": "index.js", "typings": "types/index.d.ts", @@ -31,7 +31,7 @@ "jest": "^23.1.0" }, "dependencies": { - "@tarojs/taro": "1.3.1", - "@tarojs/utils": "1.3.1" + "@tarojs/taro": "1.3.2", + "@tarojs/utils": "1.3.2" } } diff --git a/packages/taro-rn-runner/package.json b/packages/taro-rn-runner/package.json index 260af06bf05c..76d3ce853d17 100644 --- a/packages/taro-rn-runner/package.json +++ b/packages/taro-rn-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-runner", - "version": "1.3.1", + "version": "1.3.2", "description": "ReactNative build tool for taro", "main": "index.js", "scripts": { diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json index 9240bf5c2c8d..94d37fd76452 100644 --- a/packages/taro-rn/package.json +++ b/packages/taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-rn", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro RN framework", "main": "./index.js", "files": [ @@ -27,7 +27,7 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.1", + "@tarojs/taro": "1.3.2", "base64-js": "^1.3.0", "react-native-image-crop-picker": "^0.23.1", "react-native-image-zoom-viewer": "^2.2.13", diff --git a/packages/taro-router-rn/package.json b/packages/taro-router-rn/package.json index 2ce7327aa0c3..cc3a3996a83b 100644 --- a/packages/taro-router-rn/package.json +++ b/packages/taro-router-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-router-rn", - "version": "1.3.1", + "version": "1.3.2", "description": "taro-router-rn", "main": "./index.js", "files": [ diff --git a/packages/taro-router/package.json b/packages/taro-router/package.json index 72f1ccf6e51e..56b81d856c21 100644 --- a/packages/taro-router/package.json +++ b/packages/taro-router/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/router", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro-router", "main:h5": "dist/index.esm.js", "main": "index.js", @@ -41,7 +41,7 @@ "@babel/plugin-syntax-dynamic-import": "7.0.0", "@babel/plugin-transform-react-jsx": "7.0.0", "@babel/preset-env": "7.1.5", - "@tarojs/taro-h5": "1.3.1", + "@tarojs/taro-h5": "1.3.2", "@types/history": "4.7.2", "@types/jasmine": "2.8.11", "@types/jest": "23.3.9", diff --git a/packages/taro-swan/package.json b/packages/taro-swan/package.json index ae386e38624d..872805ac733f 100644 --- a/packages/taro-swan/package.json +++ b/packages/taro-swan/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-swan", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro swan framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.1", - "@tarojs/utils": "1.3.1", + "@tarojs/taro": "1.3.2", + "@tarojs/utils": "1.3.2", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-transformer-wx/package.json b/packages/taro-transformer-wx/package.json index 9887e87e605c..1df2e5e025b7 100644 --- a/packages/taro-transformer-wx/package.json +++ b/packages/taro-transformer-wx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/transformer-wx", - "version": "1.3.1", + "version": "1.3.2", "description": "Transfrom Nerv Component to Wechat mini program.", "repository": { "type": "git", @@ -62,14 +62,14 @@ "babel-types": "^6.26.0", "eslint": "^4.15.0", "eslint-plugin-react": "7.10.0", - "eslint-plugin-taro": "1.3.1", + "eslint-plugin-taro": "1.3.2", "html": "^1.0.0", "lodash": "^4.17.5", "prettier": "^1.14.2", "typescript": "^3.2.2" }, "devDependencies": { - "@tarojs/taro": "1.3.1", + "@tarojs/taro": "1.3.2", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.1", "@types/babel-template": "^6.25.0", diff --git a/packages/taro-tt/package.json b/packages/taro-tt/package.json index 4eea5b07124e..34aa6a5668ca 100644 --- a/packages/taro-tt/package.json +++ b/packages/taro-tt/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-tt", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro toutiao framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.1", - "@tarojs/utils": "1.3.1", + "@tarojs/taro": "1.3.2", + "@tarojs/utils": "1.3.2", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-utils/package.json b/packages/taro-utils/package.json index 68c5b76e9cb1..64b2258b0d54 100644 --- a/packages/taro-utils/package.json +++ b/packages/taro-utils/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/utils", - "version": "1.3.1", + "version": "1.3.2", "description": "Utils for Taro", "main": "index.js", "scripts": { diff --git a/packages/taro-weapp/package.json b/packages/taro-weapp/package.json index 2014783e6e2a..1c5c895204bc 100644 --- a/packages/taro-weapp/package.json +++ b/packages/taro-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-weapp", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro weapp framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.1", - "@tarojs/utils": "1.3.1", + "@tarojs/taro": "1.3.2", + "@tarojs/utils": "1.3.2", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json index ff5e9e3ef5fc..45e8c3f2034c 100644 --- a/packages/taro-webpack-runner/package.json +++ b/packages/taro-webpack-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/webpack-runner", - "version": "1.3.1", + "version": "1.3.2", "description": "webpack runner for taro", "main": "index.js", "scripts": { @@ -32,13 +32,13 @@ }, "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { - "@tarojs/taro-h5": "1.3.1", + "@tarojs/taro-h5": "1.3.2", "autoprefixer": "8.6.4", "babel-core": "6.26.0", "babel-loader": "7.1.4", "babel-plugin-syntax-dynamic-import": "6.18.0", "babel-plugin-transform-react-jsx": "6.24.1", - "babel-plugin-transform-taroapi": "1.3.1", + "babel-plugin-transform-taroapi": "1.3.2", "babel-types": "6.26.0", "chalk": "2.4.2", "copy-webpack-plugin": "^5.0.3", @@ -55,8 +55,8 @@ "opn": "5.3.0", "ora": "2.1.0", "postcss-loader": "2.1.6", - "postcss-plugin-constparse": "1.3.1", - "postcss-pxtransform": "1.3.1", + "postcss-plugin-constparse": "1.3.2", + "postcss-pxtransform": "1.3.2", "resolve": "1.8.1", "resolve-url-loader": "2.3.0", "sass-loader": "7.1.0", diff --git a/packages/taro-with-weapp/package.json b/packages/taro-with-weapp/package.json index 32f196b9eb37..72f03cb63d5c 100644 --- a/packages/taro-with-weapp/package.json +++ b/packages/taro-with-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/with-weapp", - "version": "1.3.1", + "version": "1.3.2", "description": "taroize 之后的运行时", "main": "index.js", "scripts": { @@ -22,7 +22,7 @@ "author": "yuche", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.1", + "@tarojs/taro": "1.3.2", "lodash": "^4.17.11" }, "devDependencies": { diff --git a/packages/taro/package.json b/packages/taro/package.json index 2f17a2b00084..602337cccdc1 100644 --- a/packages/taro/package.json +++ b/packages/taro/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro", - "version": "1.3.1", + "version": "1.3.2", "description": "Taro framework", "module": "dist/index.esm.js", "main": "index.js", diff --git a/packages/taroize/package.json b/packages/taroize/package.json index ca56c9512a5e..a2309d8acb69 100644 --- a/packages/taroize/package.json +++ b/packages/taroize/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taroize", - "version": "1.3.1", + "version": "1.3.2", "description": "转换原生微信小程序代码为 Taro 代码", "main": "index.js", "files": [ From 3b0a018c2458d6a90999d735fc177411bb21059d Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 17 Jun 2019 22:35:55 +0800 Subject: [PATCH 031/158] chore: changelog --- CHANGELOG.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e365f8a7bb1..10b012f2469d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ -# [](https://github.com/NervJS/taro/compare/v1.3.1...v) (2019-06-16) +# [](https://github.com/NervJS/taro/compare/v1.3.2...v) (2019-06-17) + + + + +## [1.3.2](https://github.com/NervJS/taro/compare/v1.3.1...v1.3.2) (2019-06-17) + + +### Bug Fixes + +* **components-rn:** Clickable android, 绑定 onClick 的组件让 ScrollView 无法滑动了 ([16cf886](https://github.com/NervJS/taro/commit/16cf886)) +* **components-rn:** react-native-swiper 修复并更新相关代码样式 ([7494c41](https://github.com/NervJS/taro/commit/7494c41)) +* **transformer:** mobx 不需要 import ReduxContext, close [#3453](https://github.com/NervJS/taro/issues/3453) ([8d99a2b](https://github.com/NervJS/taro/commit/8d99a2b)) +* **transformer:** 使用 spread props 导致报错,close [#3439](https://github.com/NervJS/taro/issues/3439) ([bf85def](https://github.com/NervJS/taro/commit/bf85def)) +* **transformer:** 使用异步订阅 redux 更新 ([1ab6123](https://github.com/NervJS/taro/commit/1ab6123)), closes [#3456](https://github.com/NervJS/taro/issues/3456) +* **transformer:** 误报解构警告,close [#3450](https://github.com/NervJS/taro/issues/3450) ([f38e13b](https://github.com/NervJS/taro/commit/f38e13b)) + + +### Features + +* **components:** 组件 Image 新增 lazyLoad 属性 ([6d03f64](https://github.com/NervJS/taro/commit/6d03f64)) +* **components-rn:** Swiper, 可以直接从样式传入 width, height 和 margin*,之前需要套 View, margin* 作用在内层导致样式有误 ([3646ec8](https://github.com/NervJS/taro/commit/3646ec8)) +* **components-rn:** 将 react-native-swiper 内嵌到项目中 ([91a27e0](https://github.com/NervJS/taro/commit/91a27e0)) +* **taro:** 新增 defineProperties polyfill ([6666f40](https://github.com/NervJS/taro/commit/6666f40)) From 2f33f562b3ae97851729bf337ac3a7a1bc284413 Mon Sep 17 00:00:00 2001 From: Colder Xihk Date: Tue, 18 Jun 2019 11:29:17 +0800 Subject: [PATCH 032/158] =?UTF-8?q?fix(taro):=20=E5=A2=9E=E5=8A=A0=20Taro.?= =?UTF-8?q?getAccountInfoSync=20=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89=20(#3?= =?UTF-8?q?433)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro/types/index.d.ts | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts index a6f5b79c91f4..faadbe57a250 100644 --- a/packages/taro/types/index.d.ts +++ b/packages/taro/types/index.d.ts @@ -9965,6 +9965,50 @@ declare namespace Taro { */ function reportAnalytics(eventName: string, data: any): void + /** + * @since 2.2.2 + * + * 获取当前帐号信息 + * + * **示例代码:** + * + ```javascript + const accountInfo = wx.getAccountInfoSync(); + console.log(accountInfo.miniProgram.appId) // 小程序 appId + console.log(accountInfo.plugin.appId) // 插件 appId + console.log(accountInfo.plugin.version) // 插件版本号, 'a.b.c' 这样的形式 + ``` + * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/account-info/wx.getAccountInfoSync.html + */ + function getAccountInfoSync(): getAccountInfoSync.Return + + namespace getAccountInfoSync { + interface Return { + /** + * 小程序帐号信息 + */ + miniProgram: { + /** + * 小程序 appId + */ + appId: string + } + /** + * 插件帐号信息(仅在插件中调用时包含这一项) + */ + plugin?: { + /** + * 插件 appId + */ + appId: string + /** + * 插件版本号 + */ + version: string + } + } + } + /** * @since 1.9.90 * From 0d2bb5356df9343056a8480c292b3959cfe6fd48 Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Tue, 18 Jun 2019 13:59:39 +0800 Subject: [PATCH 033/158] =?UTF-8?q?fix(weapp):=20=E5=88=9D=E5=A7=8B=20ref?= =?UTF-8?q?=20=E8=8E=B7=E5=8F=96=E6=94=B9=E5=88=B0=20didmount=20=E9=98=B6?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-weapp/src/create-component.js | 5 +++++ packages/taro-weapp/src/lifecycle.js | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/taro-weapp/src/create-component.js b/packages/taro-weapp/src/create-component.js index bcb2f9f737a7..48d0c01861aa 100644 --- a/packages/taro-weapp/src/create-component.js +++ b/packages/taro-weapp/src/create-component.js @@ -213,6 +213,11 @@ export function componentTrigger (component, key, args) { }) component.refs = Object.assign({}, component.refs || {}, refs) } + if (component['$$hasLoopRef']) { + component._disableEffect = true + component._createData(component.state, component.props, true) + component._disableEffect = false + } } if (key === 'componentWillUnmount') { diff --git a/packages/taro-weapp/src/lifecycle.js b/packages/taro-weapp/src/lifecycle.js index d8bd01587f0f..a65044eeb9a6 100644 --- a/packages/taro-weapp/src/lifecycle.js +++ b/packages/taro-weapp/src/lifecycle.js @@ -139,15 +139,13 @@ function doUpdate (component, prevProps, prevState) { const { state, props = {} } = component let data = state || {} if (component._createData) { - // 返回null或undefined则保持不变 - const runLoopRef = !component.__mounted if (component.__isReady) { injectContextType(component) Current.current = component Current.index = 0 invokeEffects(component, true) } - data = component._createData(state, props, runLoopRef) || data + data = component._createData(state, props) || data if (component.__isReady) { Current.current = null } From 506ca025afcdaf301cf1d01820beae831c56f605 Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Wed, 19 Jun 2019 15:54:25 +0800 Subject: [PATCH 034/158] =?UTF-8?q?fix(taro-weapp):=20=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=83=BD=E9=80=9A=E8=BF=87=20extraP?= =?UTF-8?q?rops=20=E6=8E=A5=E6=94=B6=E5=A4=96=E9=83=A8=20props?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主要为了解决两个问题: 1. 小程序原生组件使用 Taro 组件不能传 props。 2. 微信小程序插件开发时,组件插件不能接受外部 props。 --- docs/miniprogram-plugin.md | 20 +++++++++++++++ packages/taro-transformer-wx/src/render.ts | 5 +++- packages/taro-weapp/src/create-component.js | 27 +++++++++++++++++++-- packages/taro-weapp/src/propsManager.js | 2 +- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/docs/miniprogram-plugin.md b/docs/miniprogram-plugin.md index 93922b33d3d8..d6b42783f42d 100644 --- a/docs/miniprogram-plugin.md +++ b/docs/miniprogram-plugin.md @@ -90,6 +90,26 @@ export default class Index extends Component { } ``` +### Taro v1.3+ 组件插件接受外部 props 的问题 + +[#3176](https://github.com/NervJS/taro/issues/3176) + +Taro v1.3 对 props 系统进行了改造,使得不能兼容原生组件通过 properties 传入的属性。 + +目前可以通过把所有需要传入组件插件的 props,通过借助 `extraProps` 属性来解决。 + +```js +// 常规 props 传递 + + +// 在使用插件组件时需要改造成以下形式: +const extraProps = { + name: this.state.name, + desc: this.state.desc +} + +``` + ### 使用接口插件 plugin.json 的 **main** 字段加入接口插件路径: diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index 582a5dabe5e6..a6d0fde46eb7 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -989,6 +989,7 @@ export class RenderParser { if (t.isJSXIdentifier(name) && name.name !== 'key' && name.name !== 'id' + && !(name.name === 'extraProps' && Adapter.type === Adapters.weapp) && name.name !== Adapter.for && name.name !== Adapter.forItem && name.name !== Adapter.forIndex @@ -1642,7 +1643,9 @@ export class RenderParser { isEmptyProps = (attrs: (t.JSXAttribute | t.JSXSpreadAttribute)[]) => attrs.filter(a => { if (t.isJSXSpreadAttribute(a)) return true - return ![Adapter.for, Adapter.forIndex, Adapter.forItem, 'id'].includes(a.name.name as string) + const list = [Adapter.for, Adapter.forIndex, Adapter.forItem, 'id'] + Adapter.type === Adapters.weapp && list.push('extraProps') + return !list.includes(a.name.name as string) }).length === 0 findParentIndices (callee: NodePath, indexId: t.Identifier) { diff --git a/packages/taro-weapp/src/create-component.js b/packages/taro-weapp/src/create-component.js index bcb2f9f737a7..38507ade7909 100644 --- a/packages/taro-weapp/src/create-component.js +++ b/packages/taro-weapp/src/create-component.js @@ -3,6 +3,8 @@ import { commitAttachRef, detachAllRef, Current } from '@tarojs/taro' import { isEmptyObject, isFunction } from './util' import { mountComponent } from './lifecycle' import { cacheDataSet, cacheDataGet, cacheDataHas } from './data-cache' +import { updateComponent } from './lifecycle' +import nextTick from './next-tick' import propsManager from './propsManager' const anonymousFnNamePreffix = 'funPrivate' @@ -40,6 +42,22 @@ function bindProperties (weappComponentConf, ComponentClass, isPage) { initComponent.apply(this, [ComponentClass, isPage]) } } + weappComponentConf.properties.extraProps = { + type: null, + value: null, + observer () { + // update Component + if (!this.$component || !this.$component.__isReady) return + + const nextProps = filterProps(ComponentClass.defaultProps, {}, this.$component.props, this.data.extraProps) + this.$component.props = nextProps + nextTick(() => { + this.$component._unsafeCallUpdate = true + updateComponent(this.$component) + this.$component._unsafeCallUpdate = false + }) + } + } } function bindBehaviors (weappComponentConf, ComponentClass) { @@ -172,7 +190,7 @@ function bindEvents (weappComponentConf, events, isPage) { }) } -export function filterProps (defaultProps = {}, propsFromPropsManager = {}, curAllProps = {}) { +export function filterProps (defaultProps = {}, propsFromPropsManager = {}, curAllProps = {}, extraProps) { let newProps = Object.assign({}, curAllProps, propsFromPropsManager) if (!isEmptyObject(defaultProps)) { @@ -182,6 +200,11 @@ export function filterProps (defaultProps = {}, propsFromPropsManager = {}, curA } } } + + if (extraProps) { + newProps = Object.assign({}, newProps, extraProps) + } + return newProps } @@ -257,7 +280,7 @@ function initComponent (ComponentClass, isPage) { ComponentClass } } - const nextProps = filterProps(ComponentClass.defaultProps, propsManager.map[compid], this.$component.props) + const nextProps = filterProps(ComponentClass.defaultProps, propsManager.map[compid], this.$component.props, this.data.extraProps) this.$component.props = nextProps } else { this.$component.$router.path = getCurrentPageUrl() diff --git a/packages/taro-weapp/src/propsManager.js b/packages/taro-weapp/src/propsManager.js index 96f61fae9658..9f6d4314b960 100644 --- a/packages/taro-weapp/src/propsManager.js +++ b/packages/taro-weapp/src/propsManager.js @@ -23,7 +23,7 @@ class Manager { const ComponentClass = observers[compid] && observers[compid].ComponentClass if (!component || !ComponentClass || !component.__isReady) return - const nextProps = filterProps(ComponentClass.defaultProps, props, component.props) + const nextProps = filterProps(ComponentClass.defaultProps, props, component.props, this.data.extraProps) component.props = nextProps nextTick(() => { component._unsafeCallUpdate = true From 22edff9b0249d067a5b2e9390e868400615d3006 Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Fri, 21 Jun 2019 10:01:20 +0800 Subject: [PATCH 035/158] =?UTF-8?q?fix(taro-weapp/tt/swan/qq/alipay):=20?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8=E6=B7=BB=E5=8A=A0=20cleanIntercepto?= =?UTF-8?q?rs=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-alipay/src/native-api.js | 1 + packages/taro-qq/src/native-api.js | 1 + packages/taro-swan/src/native-api.js | 1 + packages/taro-tt/src/native-api.js | 1 + packages/taro-weapp/src/native-api.js | 1 + packages/taro/src/interceptor/index.js | 4 ++++ 6 files changed, 9 insertions(+) diff --git a/packages/taro-alipay/src/native-api.js b/packages/taro-alipay/src/native-api.js index 3d619d28fc69..e6e4cc06588d 100644 --- a/packages/taro-alipay/src/native-api.js +++ b/packages/taro-alipay/src/native-api.js @@ -441,6 +441,7 @@ export default function initNativeApi (taro) { processApis(taro) taro.request = link.request.bind(link) taro.addInterceptor = link.addInterceptor.bind(link) + taro.cleanInterceptors = link.cleanInterceptors.bind(link) taro.getCurrentPages = getCurrentPages taro.getApp = getApp taro.initPxTransform = initPxTransform.bind(taro) diff --git a/packages/taro-qq/src/native-api.js b/packages/taro-qq/src/native-api.js index 633434a122ef..acbf0859407f 100644 --- a/packages/taro-qq/src/native-api.js +++ b/packages/taro-qq/src/native-api.js @@ -232,6 +232,7 @@ export default function initNativeApi (taro) { processApis(taro) taro.request = link.request.bind(link) taro.addInterceptor = link.addInterceptor.bind(link) + taro.cleanInterceptors = link.cleanInterceptors.bind(link) taro.getCurrentPages = getCurrentPages taro.getApp = getApp taro.requirePlugin = requirePlugin diff --git a/packages/taro-swan/src/native-api.js b/packages/taro-swan/src/native-api.js index 9e1a5002e176..cde1d856011b 100644 --- a/packages/taro-swan/src/native-api.js +++ b/packages/taro-swan/src/native-api.js @@ -164,6 +164,7 @@ export default function initNativeApi (taro) { processApis(taro) taro.request = link.request.bind(link) taro.addInterceptor = link.addInterceptor.bind(link) + taro.cleanInterceptors = link.cleanInterceptors.bind(link) taro.getCurrentPages = getCurrentPages taro.getApp = getApp taro.initPxTransform = initPxTransform.bind(taro) diff --git a/packages/taro-tt/src/native-api.js b/packages/taro-tt/src/native-api.js index bbd19f7014f7..f212ceaefa16 100644 --- a/packages/taro-tt/src/native-api.js +++ b/packages/taro-tt/src/native-api.js @@ -189,6 +189,7 @@ export default function initNativeApi (taro) { processApis(taro) taro.request = link.request.bind(link) taro.addInterceptor = link.addInterceptor.bind(link) + taro.cleanInterceptors = link.cleanInterceptors.bind(link) taro.getCurrentPages = getCurrentPages taro.getApp = getApp taro.initPxTransform = initPxTransform.bind(taro) diff --git a/packages/taro-weapp/src/native-api.js b/packages/taro-weapp/src/native-api.js index fe46846b413d..86f049c18080 100644 --- a/packages/taro-weapp/src/native-api.js +++ b/packages/taro-weapp/src/native-api.js @@ -234,6 +234,7 @@ export default function initNativeApi (taro) { processApis(taro) taro.request = link.request.bind(link) taro.addInterceptor = link.addInterceptor.bind(link) + taro.cleanInterceptors = link.cleanInterceptors.bind(link) taro.getCurrentPages = getCurrentPages taro.getApp = getApp taro.requirePlugin = requirePlugin diff --git a/packages/taro/src/interceptor/index.js b/packages/taro/src/interceptor/index.js index 5c905e11a82e..c1380bfd159b 100644 --- a/packages/taro/src/interceptor/index.js +++ b/packages/taro/src/interceptor/index.js @@ -14,4 +14,8 @@ export default class Link { addInterceptor (interceptor) { this.chain.interceptors.push(interceptor) } + + cleanInterceptors () { + this.chain = new Chain() + } } From 448454614d5a53bb74b93e085fa2bef95551017d Mon Sep 17 00:00:00 2001 From: zysndy Date: Fri, 21 Jun 2019 11:03:31 +0800 Subject: [PATCH 036/158] feat(taro-components): add borderRadius for Progress Component --- .../taro-components/src/components/progress/index.js | 11 ++++++++--- .../taro-components/src/components/progress/index.md | 1 + packages/taro-components/types/Progress.d.ts | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/taro-components/src/components/progress/index.js b/packages/taro-components/src/components/progress/index.js index a7ffaa2eca52..26eaee4422fb 100644 --- a/packages/taro-components/src/components/progress/index.js +++ b/packages/taro-components/src/components/progress/index.js @@ -16,7 +16,8 @@ function parseType (props) { strokeWidth, activeColor, backgroundColor, - active + active, + borderRadius } = props // 抛出错误信息 @@ -33,6 +34,8 @@ function parseType (props) { if (backgroundColor) { isString(backgroundColor) ? '' : throwErrorMsg('backgroundColor') } + + if (borderRadius) isString(borderRadius) ? '' : throwErrorMsg('borderRadius') } const Progress = (props) => { @@ -44,7 +47,8 @@ const Progress = (props) => { activeColor, backgroundColor, active, - percent + percent, + borderRadius } = props let pgPercent = percent > 100 ? 100 : percent < 0 ? 0 : percent const cls = classNames('weui-progress', className) @@ -52,7 +56,8 @@ const Progress = (props) => { width: pgPercent + '%', backgroundColor: activeColor, WebkitTransition: active ? `width 1s ease-in-out` : 'none', - transition: active ? `width 1s ease-in-out` : 'none' + transition: active ? `width 1s ease-in-out` : 'none', + borderRadius: borderRadius ? `${borderRadius}px` : 0 } let pgHeight = { height: strokeWidth + 'px', diff --git a/packages/taro-components/src/components/progress/index.md b/packages/taro-components/src/components/progress/index.md index 3ae8a1e55812..76635c141cf2 100644 --- a/packages/taro-components/src/components/progress/index.md +++ b/packages/taro-components/src/components/progress/index.md @@ -12,3 +12,4 @@ progress | √ | backgroundColor | Color | 6 | 未选择的进度条的颜色 | | √ | active | Boolean | false | 进度条从左往右的动画 | | | active-mode | String | backwards | backwards: 动画从头播;forwards:动画从上次结束点接着播 | +| | borderRadius | Number | 0 | 圆角大小, 单位 px | diff --git a/packages/taro-components/types/Progress.d.ts b/packages/taro-components/types/Progress.d.ts index 5c96800ce90b..41cddb8569c4 100644 --- a/packages/taro-components/types/Progress.d.ts +++ b/packages/taro-components/types/Progress.d.ts @@ -56,6 +56,14 @@ export interface ProgressProps extends StandardProps { * 默认值:`backwards` */ activeMode?: 'backwards' | 'forwards' + + + /** + * 圆角大小 + * + * 默认值:0 + */ + borderRadius?: number } declare const Progress: ComponentType From 15bed066188eacdecd80df8a5a0c945049a9c25a Mon Sep 17 00:00:00 2001 From: luckyadam Date: Fri, 21 Jun 2019 11:39:35 +0800 Subject: [PATCH 037/158] =?UTF-8?q?fix(cli):=20=E4=BF=AE=E5=A4=8D=E5=BF=AB?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E7=BC=96=E8=AF=91=E6=8A=A5=E9=94=99=EF=BC=8C?= =?UTF-8?q?=E5=BF=AB=E5=BA=94=E7=94=A8=E4=BE=9D=E8=B5=96=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/mini/index.ts | 34 ++++++++++++------------- packages/taro-cli/src/util/constants.ts | 2 +- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/taro-cli/src/mini/index.ts b/packages/taro-cli/src/mini/index.ts index d77e869acbd3..f9838af223ac 100644 --- a/packages/taro-cli/src/mini/index.ts +++ b/packages/taro-cli/src/mini/index.ts @@ -4,7 +4,7 @@ import * as path from 'path' import chalk from 'chalk' import * as _ from 'lodash' import * as ora from 'ora' -import { exec } from 'child_process' +import { execSync } from 'child_process' import * as resolvePath from 'resolve' import { @@ -18,7 +18,7 @@ import { } from '../util' import { processTypeEnum, BUILD_TYPES } from '../util/constants' import { IMiniAppBuildConfig } from '../util/types' -import defaultManifestJSON from '../config/manifest.default.json' +import * as defaultManifestJSON from '../config/manifest.default.json' import { setBuildData, @@ -122,6 +122,7 @@ function generateQuickAppManifest () { if (fs.existsSync(quickappJSONPath)) { quickappJSON = fs.readJSONSync(quickappJSONPath) } else { + printLog(processTypeEnum.WARNING, '缺少配置', `检测到项目目录下未添加 ${chalk.bold('project.quickapp.json')} 文件,将使用默认配置,参考文档 https://nervjs.github.io/taro/docs/project-config.html`) quickappJSON = defaultManifestJSON } quickappJSON.router = router @@ -151,9 +152,8 @@ async function prepareQuickAppEnvironment (buildData: IBuildData) { } else { console.log(`${chalk.green('✔ ')} 快应用容器已经准备好`) } - - console.log() process.chdir(originalOutputDir) + console.log() if (fs.existsSync(path.join(originalOutputDir, 'node_modules'))) { needInstall = false } else { @@ -169,20 +169,18 @@ async function prepareQuickAppEnvironment (buildData: IBuildData) { command = 'NODE_ENV=development npm install' } const installSpinner = ora(`安装快应用依赖环境, 需要一会儿...`).start() - const install = exec(command) - install.on('close', code => { - if (code === 0) { - installSpinner.color = 'green' - installSpinner.succeed('安装成功') - console.log(`${install.stderr.read()}${install.stdout.read()}`) - isReady = true - } else { - installSpinner.color = 'red' - installSpinner.fail(chalk.red(`快应用依赖环境安装失败,请进入 ${path.basename(originalOutputDir)} 重新安装!`)) - console.log(`${install.stderr.read()}${install.stdout.read()}`) - isReady = false - } - }) + try { + const stdout = execSync(command) + installSpinner.color = 'green' + installSpinner.succeed('安装成功') + console.log(`${stdout}`) + isReady = true + } catch (error) { + installSpinner.color = 'red' + installSpinner.fail(chalk.red(`快应用依赖环境安装失败,请进入 ${path.basename(originalOutputDir)} 重新安装!`)) + console.log(`${error}`) + isReady = false + } } else { console.log(`${chalk.green('✔ ')} 快应用依赖已经安装好`) isReady = true diff --git a/packages/taro-cli/src/util/constants.ts b/packages/taro-cli/src/util/constants.ts index d343c2fdff98..410bc9946beb 100644 --- a/packages/taro-cli/src/util/constants.ts +++ b/packages/taro-cli/src/util/constants.ts @@ -53,7 +53,7 @@ export const processTypeMap: IProcessTypeMap = { }, [processTypeEnum.WARNING]: { name: '警告', - color: 'yellow' + color: 'yellowBright' }, [processTypeEnum.UNLINK]: { name: '删除', From b9f708aa1919b1e0077285e0ed688485fe4c7d14 Mon Sep 17 00:00:00 2001 From: Xiaoli <544028951@qq.com> Date: Fri, 21 Jun 2019 15:58:10 +0800 Subject: [PATCH 038/158] =?UTF-8?q?fix(router):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=81=B6=E5=B0=94=E9=A1=B5=E9=9D=A2=E9=9A=90=E8=97=8F=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-router/src/router/route.tsx | 28 ++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/taro-router/src/router/route.tsx b/packages/taro-router/src/router/route.tsx index 3a3fdcb5b61a..851970014e8d 100644 --- a/packages/taro-router/src/router/route.tsx +++ b/packages/taro-router/src/router/route.tsx @@ -1,5 +1,5 @@ import Taro from '@tarojs/taro-h5' -import Nerv from 'nervjs' +import Nerv, { nextTick } from 'nervjs' import { tryToCall } from '../utils' import { Location, RouteObj } from '../utils/types' @@ -98,19 +98,21 @@ class Route extends Taro.Component { this.matched = nextMatched - if (nextMatched) { - this.showPage() - if (!isRedirect) { + nextTick(() => { + if (nextMatched) { + this.showPage() + if (!isRedirect) { + scroller = scroller || getScroller() + scroller.set(this.scrollPos) + tryToCall(this.componentRef.componentDidShow, this.componentRef) + } + } else { scroller = scroller || getScroller() - scroller.set(this.scrollPos) - tryToCall(this.componentRef.componentDidShow, this.componentRef) + this.scrollPos = scroller.get() + this.hidePage() + tryToCall(this.componentRef.componentDidHide, this.componentRef) } - } else { - scroller = scroller || getScroller() - this.scrollPos = scroller.get() - this.hidePage() - tryToCall(this.componentRef.componentDidHide, this.componentRef) - } + }) } shouldComponentUpdate () { @@ -129,7 +131,7 @@ class Route extends Taro.Component { hidePage () { const dom = this.containerRef if (!dom) { - return console.error(`showPage:fail Received a falsy component for route "${this.props.path}". Forget to export it?`) + return console.error(`hidePage:fail Received a falsy component for route "${this.props.path}". Forget to export it?`) } dom.style.display = 'none' } From 849999dedb206ef272ac4e1f71cc2f2c3711dcde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= Date: Fri, 21 Jun 2019 18:07:57 +0800 Subject: [PATCH 039/158] =?UTF-8?q?fix(cli):=20=E5=BC=95=E5=85=A5json?= =?UTF-8?q?=E5=8C=85=E5=90=ABnull=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8Cclose?= =?UTF-8?q?=20#3505?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/NervJS/taro/issues/3505 --- packages/taro-cli/src/util/astConvert.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/taro-cli/src/util/astConvert.ts b/packages/taro-cli/src/util/astConvert.ts index 8aee0493b42f..12ef0ac07247 100644 --- a/packages/taro-cli/src/util/astConvert.ts +++ b/packages/taro-cli/src/util/astConvert.ts @@ -20,6 +20,9 @@ export function convertObjectToAstExpression (obj: object): t.ObjectProperty[] { if (Array.isArray(value)) { return t.objectProperty(t.stringLiteral(key), t.arrayExpression(convertArrayToAstExpression(value as []))) } + if (value === null) { + return t.objectProperty(t.stringLiteral(key), t.nullLiteral()) + } if (typeof value === 'object') { return t.objectProperty(t.stringLiteral(key), t.objectExpression(convertObjectToAstExpression(value))) } From a6f4c0aece3ddfca11be80fb3a9210994a4f4be7 Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Fri, 21 Jun 2019 18:10:07 +0800 Subject: [PATCH 040/158] =?UTF-8?q?fix(alipay):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=9C=A8=E6=94=AF=E4=BB=98=E5=AE=9D=E5=88=86=E5=8C=85=E4=B8=AD?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86=E5=B7=A5=E5=85=B7=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8Cfix=20#34?= =?UTF-8?q?45?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-mobx-common/src/store.js | 9 ++++++++- packages/taro-redux/src/utils/store.js | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/taro-mobx-common/src/store.js b/packages/taro-mobx-common/src/store.js index ec3c49ed1819..66e38da000e4 100644 --- a/packages/taro-mobx-common/src/store.js +++ b/packages/taro-mobx-common/src/store.js @@ -1,9 +1,16 @@ let store = {} export function getStore () { + if (process.env.TARO_ENV === 'alipay') { + return my.taroMobxStore || {} + } return store } export function setStore (arg) { - store = arg + if (process.env.TARO_ENV === 'alipay') { + my.taroMobxStore = arg + } else { + store = arg + } } diff --git a/packages/taro-redux/src/utils/store.js b/packages/taro-redux/src/utils/store.js index ec08d90ae709..a56ee04dc8fe 100644 --- a/packages/taro-redux/src/utils/store.js +++ b/packages/taro-redux/src/utils/store.js @@ -4,6 +4,8 @@ const globalRef = Object.getPrototypeOf(appGlobal) || appGlobal export function getStore () { if (process.env.TARO_ENV === 'quickapp') { return globalRef.store || null + } else if (process.env.TARO_ENV === 'alipay') { + return my.taroReduxStore || null } return store } @@ -11,6 +13,8 @@ export function getStore () { export function setStore (arg) { if (process.env.TARO_ENV === 'quickapp') { globalRef.store = arg + } else if (process.env.TARO_ENV === 'alipay') { + my.taroReduxStore = arg } else { store = arg } From 7a46080dda16574acb84af4789427080a472223f Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Sat, 22 Jun 2019 16:16:50 +0800 Subject: [PATCH 041/158] =?UTF-8?q?refactor(components-rn):=20react-native?= =?UTF-8?q?-swiper,=20=E4=BF=AE=E6=94=B9=E4=BF=AE=E5=A4=8D=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E8=8B=A5=E5=B9=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-components-rn/README.md | 2 + .../taro-components-rn/TCRNExample/App.js | 2 +- .../TCRNExample/example/EXSwiper.js | 86 ++- .../src/lib/react-native-swiper/PropsType.tsx | 19 +- .../react-native-swiper/index.bak20190619tsx | 529 ++++++++++++++++++ .../src/lib/react-native-swiper/index.tsx | 272 ++++----- .../src/lib/react-native-swiper/styles.tsx | 1 + 7 files changed, 751 insertions(+), 160 deletions(-) create mode 100644 packages/taro-components-rn/src/lib/react-native-swiper/index.bak20190619tsx diff --git a/packages/taro-components-rn/README.md b/packages/taro-components-rn/README.md index dcd3c9e38005..dca56c383c39 100644 --- a/packages/taro-components-rn/README.md +++ b/packages/taro-components-rn/README.md @@ -38,3 +38,5 @@ react-native run-ios ## 未来可能的升级 目前 react-native 版本为 0.55.4 + +- 0.58.x ScrollView 支持 snapToOffsets,Swiper 关注 diff --git a/packages/taro-components-rn/TCRNExample/App.js b/packages/taro-components-rn/TCRNExample/App.js index d93da9aba2e9..cf3d7d7829d2 100644 --- a/packages/taro-components-rn/TCRNExample/App.js +++ b/packages/taro-components-rn/TCRNExample/App.js @@ -47,7 +47,7 @@ export default class App extends Component { componentDidMount () { // setTimeout(() => { - // this.setState({ scrollTop: 1800 }) + // this.setState({ scrollTop: 2200 }) // }, 0) } diff --git a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js index c84ba49bc158..e733dbc12a2f 100644 --- a/packages/taro-components-rn/TCRNExample/example/EXSwiper.js +++ b/packages/taro-components-rn/TCRNExample/example/EXSwiper.js @@ -1,7 +1,50 @@ import React, { Component } from 'react' -import { View, Text, Swiper, SwiperItem, Image } from '../../dist' +import { View, Swiper, SwiperItem, Image } from '../../dist' export default class EXSwiper extends Component { + state = { + data: [] + } + + componentDidMount () { + setTimeout(() => { + this.setState({ + data: [ + { + image: 'https://imgcps.jd.com/ling4/4635736/5Lqs6YCJ5aW96LSn/5L2g5YC85b6X5oul5pyJ/p-5c17126882acdd181dd53ce0/95c21515/cr_1125x549_0_72/s1125x690/q70.jpg', + clickUrl: 'https://m.jd.com/' + }, + { + image: 'https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/54392/1/2538/95587/5d064ea3E74ca0763/dc1d10fbd105d8a0.jpg!cr_1125x549_0_72!q70.jpg.dpg', + clickUrl: 'https://m.jd.com/' + } + ] + }) + }, 300) + setTimeout(() => { + this.setState({ + data: [ + { + image: 'https://imgcps.jd.com/ling4/4635736/5Lqs6YCJ5aW96LSn/5L2g5YC85b6X5oul5pyJ/p-5c17126882acdd181dd53ce0/95c21515/cr_1125x549_0_72/s1125x690/q70.jpg', + clickUrl: 'https://m.jd.com/' + }, + { + image: 'https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/30451/34/12138/108202/5cb7720aE6ebf11ec/9945f5b3b9f9547f.jpg!cr_1125x549_0_72!q70.jpg.dpg', + clickUrl: 'https://m.jd.com/' + }, + { + image: 'https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/54392/1/2538/95587/5d064ea3E74ca0763/dc1d10fbd105d8a0.jpg!cr_1125x549_0_72!q70.jpg.dpg', + clickUrl: 'https://m.jd.com/' + }, + { + image: 'https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/81508/17/1849/124012/5d01f580E0fee0c3f/1839eac6ba834f3e.jpg!cr_1125x549_0_72!q70.jpg.dpg', + clickUrl: 'https://m.jd.com/' + } + ] + }) + }, 600) + } + render () { return ( @@ -10,43 +53,30 @@ export default class EXSwiper extends Component { indicatorColor="white" indicatorActiveColor="purple" autoplay={true} - current={1} - interval={6000} + // current={1} + interval={3000} circular={true} vertical={false} - onChange={() => { console.log('Swiper: onChange') }} + onChange={(event) => { console.log('Swiper: onChange', event.detail.current) }} onAnimationFinish={() => null} style={{ marginTop: 30, - width: 280, + width: 280.5, height: 200, backgroundColor: 'black' }} > - { console.log('click item') }} - style={{ backgroundColor: 'red' }} - > - Hello Swiper - - - Beautiful - - - And simple - + {this.state.data.map((item, index) => { + return ( + { console.log('click item') }} + > + + + ) + })}
- {/* - - - - - - - - - - */}
) } diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx index ce4d2453b73b..7a2c370a87df 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx @@ -89,10 +89,7 @@ export interface ReactNativeSwiperProps extends ScrollViewProps { export interface ReactNativeSwiperState { width: number; height: number; - offset: Partial<{ - x: number; - y: number; - }>, + offset: Offset, autoplayEnd?: boolean; loopJump?: boolean; total: number; @@ -100,3 +97,17 @@ export interface ReactNativeSwiperState { dir: 'x' | 'y'; pIndex: number; } + +export type Offset = { + x: number; + y: number; +} + +export type ScrollEventSim = { + nativeEvent: { + contentOffset: { + x: number; + y: number; + } + } +} diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.bak20190619tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.bak20190619tsx new file mode 100644 index 000000000000..e31e9b24b3c5 --- /dev/null +++ b/packages/taro-components-rn/src/lib/react-native-swiper/index.bak20190619tsx @@ -0,0 +1,529 @@ +/** + * react-native-swiper + * + * react-native >= 0.55.4 + * react >= 16.3.1 + * + * 组件由 `react-native-swiper` 修改而来 + * + * @author leecade + * @author Manjiz + */ + +import React, { Component } from 'react' +import { + View, + ScrollView, + Dimensions, + ActivityIndicator, + LayoutChangeEvent, + NativeSyntheticEvent, + NativeScrollEvent, + Platform, + InteractionManager, +} from 'react-native' +import { ReactNativeSwiperProps, ReactNativeSwiperState, Offset } from './PropsType' +import { noop } from '../../utils' +import styles from './styles' + +const isAndroid = Platform.OS === 'android' + +const getOffset = (dir: 'x'|'y', index: number, width: number, height: number): Offset => { + const tmp: Offset = { x: 0, y: 0 } + tmp[dir] = (dir === 'x' ? width : height) * index + return tmp +} + +export default class extends Component { + /** + * @see http://facebook.github.io/react-native/docs/scrollview.html + */ + static defaultProps = { + horizontal: true, + pagingEnabled: true, + removeClippedSubviews: true, + showsPagination: true, + loop: true, + loadMinimalSize: 1, + autoplayTimeout: 2.5, + autoplayDirection: true, + index: 0, + + showsHorizontalScrollIndicator: true, + showsVerticalScrollIndicator: false, + bounces: false, + scrollsToTop: false, + automaticallyAdjustContentInsets: false, + } + + static getDerivedStateFromProps (props: ReactNativeSwiperProps, state: ReactNativeSwiperState) { + const initState: any = { + autoplayEnd: false, + loopJump: false, + offset: {} + } + + initState.total = props.children ? props.children.length || 1 : 0 + + const updateIndex = state.pIndex !== props.index + + if (state.total === initState.total && !updateIndex) { + // retain the index + initState.index = state.index + } else { + initState.index = initState.total > 1 ? Math.min(props.index as number, initState.total - 1) : 0 + initState.pIndex = props.index as number + } + + const { width, height } = Dimensions.get('window') + + initState.dir = props.horizontal ? 'x' : 'y' + initState.width = props.width || state.width || width + initState.height = props.height || state.height || height + initState.offset[initState.dir] = (initState.dir === 'x' ? initState.width : initState.height) * (props.index as number + (props.loop ? 1 : 0)) + + return initState + } + + state: ReactNativeSwiperState = { + width: 0, + height: 0, + offset: { x: 0, y: 0 }, + total: 0, + pIndex: 0, + index: 0, + dir: 'x' + } + initialRender: boolean = true + autoplayTimer: any + loopJumpTimer: any + scrolling: boolean = false + realtimeOffset: Partial = { x: 0, y: 0 } + $scrollView: any = React.createRef() + + onContentSizeChange = (contentWidth: number, contentHeight: number): void => { + console.log('1123 onContentSizeChange=----') + const { loop } = this.props + const { index, width, height, dir } = this.state + const offset: Offset = getOffset(dir, index + (loop ? 1 : 0), width, height) + InteractionManager.runAfterInteractions(() => { + const node = this.$scrollView.current + node && node.scrollTo({ ...offset, animated: isAndroid }, false) + }) + } + + getSnapshotBeforeUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState) { + this.scrolling = false + return { + propsChanged: prevProps !== this.props, + shouldClearAutoPlay: !this.props.autoplay && this.autoplayTimer, + ifIndexChange: prevState.index !== this.state.index, + } + } + + componentDidUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState, snapshot: any) { + if (snapshot.shouldClearAutoPlay) { + clearTimeout(this.autoplayTimer as number) + } + // If the index has changed, we notify the parent via the onIndexChanged callback + if (snapshot.ifIndexChange) { + const { onIndexChanged = noop } = this.props + onIndexChanged(this.state.index) + } + if (!snapshot.propsChanged && prevState.offset !== this.state.offset) { + const node = this.$scrollView.current + // workaround-1: android scrollTo not work after offset changed. (In real device) + node && node.scrollTo({ + ...this.state.offset, + animated: isAndroid || this.isAutoScroll, + duration: this.isAutoScroll ? 500 : 1 + }) + this.isAutoScroll = false + } + } + + componentDidMount () { + this.autoplay() + } + + componentWillUnmount () { + this.autoplayTimer && clearTimeout(this.autoplayTimer) + this.loopJumpTimer && clearTimeout(this.loopJumpTimer) + } + + fullState () { + return Object.assign({}, this.state, { offset: this.realtimeOffset }) + } + + onLayout = (event: LayoutChangeEvent) => { + const { loop } = this.props + const { + index, + total, + dir, + width, + height, + } = this.state + // const { width: layoutWidth, height: layoutHeight } = event.nativeEvent.layout + const layoutWidth = Math.round(event.nativeEvent.layout.width) + const layoutHeight = Math.round(event.nativeEvent.layout.height) + let offsetWouldBeSet: Partial = this.realtimeOffset = {} + const stateWouldBeSet: any = { width: layoutWidth, height: layoutHeight } + + if (total > 1) { + let actualIndex = index + loop && actualIndex++ + offsetWouldBeSet = getOffset(dir, actualIndex, layoutWidth, layoutHeight) + } + + // only update the offset in state if needed, updating offset while swiping + // causes some bad jumping / stuttering + if (layoutWidth !== width || layoutHeight !== height) { + stateWouldBeSet.offset = offsetWouldBeSet + } + + this.setState(stateWouldBeSet) + } + + autoScrollOffset?: Offset + + /** + * Scroll by index + */ + isAutoScroll: boolean = false + scrollBy = (step: number, animated: boolean = true) => { + const { loop } = this.props + const { dir, width, height, index, total } = this.state + console.log('scrollBy', this.scrolling, total) + if (this.scrolling || total < 2) return + const actualIndex = (loop ? 1 : 0) + index + const newActualIndex = actualIndex + step + let x = 0 + let y = 0 + dir === 'x' ? (x = newActualIndex * width) : (y = newActualIndex * height) + + // const node = this.$scrollView.current + // node && node.scrollTo({ x, y, animated, duration: 500 }) + this.isAutoScroll = true + this.setState({ offset: { x, y } }) + this.autoScrollOffset = { x, y } + + // update scroll state + this.scrolling = true + + this.setState({ autoplayEnd: false }) + } + + /** + * Automatic rolling + */ + autoplay = () => { + const { + children, + autoplay, + autoplayTimeout, + loop, + autoplayDirection + } = this.props + const { index, total, autoplayEnd } = this.state + if (!Array.isArray(children) || !autoplay || this.scrolling || autoplayEnd) return + + this.autoplayTimer && clearTimeout(this.autoplayTimer) + this.autoplayTimer = setTimeout(() => { + if (!loop && (autoplayDirection ? index === total - 1 : index === 0)) { + return this.setState({ autoplayEnd: true }) + } else { + this.scrollBy(autoplayDirection ? 1 : -1) + } + }, (autoplayTimeout as number) * 1000) + } + + onScroll = (e: NativeSyntheticEvent) => { + if (isAndroid && this.autoScrollOffset) { + const contentOffset = e.nativeEvent.contentOffset + const { dir, width, height } = this.state + if (Math.abs(contentOffset[dir] - this.autoScrollOffset[dir]) <= 1) { + this.onScrollEnd(e) + } + } + } + + + /** + * Scroll begin handle + */ + onScrollBegin = (e?: NativeSyntheticEvent) => { + const { onScrollBeginDrag = noop } = this.props + // update scroll state + this.scrolling = true + onScrollBeginDrag(e, this.fullState(), this) + } + + /** + * Scroll end handle + */ + onScrollEnd = (e: NativeSyntheticEvent) => { + console.log('onScrollEnd---') + const { onMomentumScrollEnd = noop } = this.props + + // update scroll state + this.scrolling = false + + // making our events coming from android compatible to updateIndex logic + const contentOffset = e.nativeEvent.contentOffset + + this.updateIndexByOffset(contentOffset, () => { + this.autoplay() + + // if `onMomentumScrollEnd` registered will be called here + onMomentumScrollEnd(e, this.fullState(), this) + }) + } + + /* + * Drag end handle + */ + onScrollEndDrag = (e: NativeSyntheticEvent) => { + const { horizontal, children } = this.props + const { index } = this.state + const { contentOffset } = e.nativeEvent + const previousOffset = horizontal ? this.realtimeOffset.x : this.realtimeOffset.y + const newOffset = horizontal ? contentOffset.x : contentOffset.y + + if (previousOffset === newOffset && (index === 0 || index === children.length - 1)) { + this.scrolling = false + } + } + + /** + * Update index after scroll + */ + updateIndexByOffset = (contentOffset: Offset, cb: any) => { + const { loop } = this.props + let { index, dir, width, height, total } = this.state + + // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582 + !this.realtimeOffset && (this.realtimeOffset = {}) + + const diff = (contentOffset[dir] || 0) - (this.realtimeOffset[dir] || 0) + const step = dir === 'x' ? width : height + let loopJump = false + + // Do nothing if offset no change. + if (!this.initialRender && !diff) return + + // Note: if touch very very quickly and continuous, + // the variation of `index` more than 1. + // parseInt() ensures it's always an integer + // index = parseInt(index + Math.round(diff / step) + '') + let actualIndex = parseInt(Math.round((contentOffset[dir] || 0) / step) + '') + + if (loop) { + if (actualIndex === 0) { + index = total - 1 + contentOffset[dir] = step * total + loopJump = true + } else if (actualIndex === total + 1) { + index = 0 + contentOffset[dir] = step + loopJump = true + } else { + index = actualIndex - 1 + } + } + + const stateWouldBeSet: any = { index, loopJump } + + this.realtimeOffset = contentOffset + + // only update offset in state if loopJump is true + if (loopJump) { + // when swiping to the beginning of a looping set for the third time, + // the new offset will be the same as the last one set in state. + // Setting the offset to the same thing will not do anything, + // so we increment it by 1 then immediately set it to what it should be, + // after render. + if (contentOffset[dir] === this.realtimeOffset[dir]) { + stateWouldBeSet.offset = { x: 0, y: 0 } + stateWouldBeSet.offset[dir] = (contentOffset[dir] || 0) + 1 + this.setState(stateWouldBeSet, () => { + this.setState({ offset: contentOffset }, cb) + }) + } else { + stateWouldBeSet.offset = contentOffset + this.setState(stateWouldBeSet, cb) + } + } else { + this.setState(stateWouldBeSet, cb) + } + } + + scrollViewPropOverrides = () => { + const overrides: any = {} + + for (let prop in this.props) { + // if(~scrollResponders.indexOf(prop) + if ( + typeof this.props[prop as keyof ReactNativeSwiperProps] === 'function' + && prop !== 'onMomentumScrollEnd' + && prop !== 'renderPagination' + && prop !== 'onScrollBeginDrag' + ) { + const originResponder = this.props[prop as keyof ReactNativeSwiperProps] || noop + overrides[prop] = (e: any) => originResponder(e, this.fullState(), this) + } + } + + return overrides + } + + /** + * Render pagination + * By default, dots only show when `total` >= 2 + */ + renderPagination = (): React.ReactNode => { + if (this.state.total <= 1) return null + + const dots = [] + const ActiveDot = this.props.activeDot || ( + + ) + + const Dot = this.props.dot || ( + + ) + + for (let i = 0; i < this.state.total; i++) { + dots.push(i === this.state.index + ? React.cloneElement(ActiveDot, { key: i }) + : React.cloneElement(Dot, { key: i }) + ) + } + + return ( + + {dots} + + ) + } + + renderScrollView = (pages: any) => { + return ( + + {pages} + + ) + } + + /** + * Default render + */ + render () { + const { + index, + total, + width, + height + } = this.state + const { + children, + containerStyle, + loop, + loadMinimal, + loadMinimalSize, + loadMinimalLoader, + renderPagination, + showsPagination, + } = this.props + // let dir = state.dir + // let key = 0 + const loopVal = loop ? 1 : 0 + let pages: Element[] | Element = [] + + const pageStyle = [{ width, height }, styles.slide] + const pageStyleLoading: any = { + width, + height, + flex: 1, + justifyContent: 'center', + alignItems: 'center' + } + + // For make infinite at least total > 1 + if (total > 1) { + // Re-design a loop model for avoid img flickering + const pagesKeys = Object.keys(children) + if (loop) { + pagesKeys.unshift(total - 1 + '') + pagesKeys.push('0') + } + + pages = pagesKeys.map((pageIdx: string, i: number) => { + if (loadMinimal) { + if (i >= (index + loopVal - (loadMinimalSize as number)) && + i <= (index + loopVal + (loadMinimalSize as number))) { + return {children[parseInt(pageIdx)]} + } else { + return ( + + {loadMinimalLoader ? loadMinimalLoader : } + + ) + } + } else { + return {children[parseInt(pageIdx)]} + } + }) + } else { + pages = {children} + } + + return ( + + {this.renderScrollView(pages)} + {showsPagination && (renderPagination ? renderPagination(index, total, this) : this.renderPagination())} + + ) + } +} diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx index c6f178b74028..f9ddb1326a37 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx @@ -1,6 +1,9 @@ /** * react-native-swiper * + * react-native >= 0.55.4 + * react >= 16.3.1 + * * 组件由 `react-native-swiper` 修改而来 * * @author leecade @@ -17,11 +20,20 @@ import { NativeSyntheticEvent, NativeScrollEvent, Platform, + InteractionManager, } from 'react-native' -import { ReactNativeSwiperProps, ReactNativeSwiperState } from './PropsType' +import { ReactNativeSwiperProps, ReactNativeSwiperState, Offset, ScrollEventSim } from './PropsType' import { noop } from '../../utils' import styles from './styles' +const isAndroid = Platform.OS === 'android' + +const getOffset = (dir: 'x'|'y', index: number, width: number, height: number): Offset => { + const tmp: Offset = { x: 0, y: 0 } + tmp[dir] = (dir === 'x' ? width : height) * index + return tmp +} + export default class extends Component { /** * @see http://facebook.github.io/react-native/docs/scrollview.html @@ -66,11 +78,9 @@ export default class extends Component - } = { - isScrolling: false, - offset: { - x: 0, - y: 0 - } - } + autoScrolling: boolean = false + scrolling: boolean = false + scrollAnimated: boolean = false + realtimeOffset: Partial = { x: 0, y: 0 } + onAndroidScrollEndTimer: any + $scrollView: any = React.createRef() - getSnapshotBeforeUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState) { - this.internals.isScrolling = false - return { - shouldClearAutoPlay: !this.props.autoplay && this.autoplayTimer, - ifIndexChange: prevState.index !== this.state.index - } + componentDidMount () { + this.autoplay() } - componentDidUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState, snapshot: { shouldClearAutoPlay: boolean; ifIndexChange: boolean; }) { - if (snapshot.shouldClearAutoPlay) { - clearTimeout(this.autoplayTimer as number) - } + componentDidUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState) { + const shouldClearAutoPlay = !this.props.autoplay && this.autoplayTimer + const indexChanged = prevState.index !== this.state.index + this.scrolling = false + shouldClearAutoPlay && clearTimeout(this.autoplayTimer as number) // If the index has changed, we notify the parent via the onIndexChanged callback - if (snapshot.ifIndexChange) { + if (indexChanged) { const { onIndexChanged = noop } = this.props onIndexChanged(this.state.index) } - } - - componentDidMount () { - this.autoplay() + const { dir } = this.state + if (prevState.offset !== this.state.offset && prevState.offset[dir] !== this.state.offset[dir]) { + const node = this.$scrollView.current + // workaround-1: android scrollTo not work after offset changed. (In real device) + // Android scrollTo didn't trigger onMomentumScrollEnd. + node && node.scrollTo({ + ...this.state.offset, + animated: isAndroid || this.scrollAnimated, + duration: this.scrollAnimated ? 500 : 1 + }) + } } componentWillUnmount () { this.autoplayTimer && clearTimeout(this.autoplayTimer) this.loopJumpTimer && clearTimeout(this.loopJumpTimer) + this.onAndroidScrollEndTimer && clearTimeout(this.onAndroidScrollEndTimer) } /** - * include internals with state + * Reset index and autoplay if contentSizeChange. */ + onContentSizeChange = (contentWidth: number, contentHeight: number): void => { + const { loop } = this.props + const { width, total, height, dir } = this.state + const offset: Offset = getOffset(dir, loop && total > 1 ? 1 : 0, width, height) + this.realtimeOffset = offset + this.setState({ index: 0, offset }, () => { + this.autoplay() + // workaround-2: In android, + if (isAndroid) { + const node = this.$scrollView.current + node && node.scrollTo(offset) + } + }) + } + fullState () { - return { ...this.state, ...this.internals } + return Object.assign({}, this.state, { offset: this.realtimeOffset }) } onLayout = (event: LayoutChangeEvent) => { @@ -145,44 +168,50 @@ export default class extends Component = this.realtimeOffset = {} const stateWouldBeSet: any = { width: layoutWidth, height: layoutHeight } if (total > 1) { - let setup = index - loop && setup++ - offsetWouldBeSet[dir] = dir === 'y' ? layoutHeight * setup : layoutWidth * setup + let actualIndex = index + loop && actualIndex++ + offsetWouldBeSet = getOffset(dir, actualIndex, layoutWidth, layoutHeight) } // only update the offset in state if needed, updating offset while swiping // causes some bad jumping / stuttering - if (!offset || layoutWidth !== width || layoutHeight !== height) { + if (layoutWidth !== width || layoutHeight !== height) { stateWouldBeSet.offset = offsetWouldBeSet } - // related to https://github.com/leecade/react-native-swiper/issues/570 - // contentOffset is not working in react 0.48.x so we need to use scrollTo - // to emulate offset. - if (this.initialRender && total > 1) { - const node = this.$scrollView.current - node && (node as ScrollView).scrollTo({ ...offsetWouldBeSet, animated: false }) - this.initialRender = false - } - this.setState(stateWouldBeSet) } - loopJump = () => { - // Android doesn't support contentOffset, So... - if (Platform.OS === 'android' && this.props.loop) { - const { index, total } = this.state - if (index !== 0 && index !== total - 1) return - const node = this.$scrollView.current - node && node.scrollTo(this.internals.offset) - } + /** + * Scroll by index + */ + scrollBy = (step: number, animated: boolean = true) => { + const { loop } = this.props + const { dir, width, height, index, total } = this.state + if (this.scrolling || total < 2) return + const actualIndex = (loop ? 1 : 0) + index + const newActualIndex = actualIndex + step + let x = 0 + let y = 0 + dir === 'x' ? (x = newActualIndex * width) : (y = newActualIndex * height) + + this.scrolling = true + this.autoScrolling = true + this.scrollAnimated = animated + this.setState({ + offset: { x, y }, + autoplayEnd: false + }, () => { + this.scrollAnimated = false + }) } /** @@ -197,45 +226,59 @@ export default class extends Component { if (!loop && (autoplayDirection ? index === total - 1 : index === 0)) { return this.setState({ autoplayEnd: true }) + } else { + this.scrollBy(autoplayDirection ? 1 : -1) } - - this.scrollBy(autoplayDirection ? 1 : -1) }, (autoplayTimeout as number) * 1000) } /** * Scroll begin handle */ - onScrollBegin = (e?: NativeSyntheticEvent) => { + onScrollBegin = (e?: ScrollEventSim) => { const { onScrollBeginDrag = noop } = this.props - // update scroll state - this.internals.isScrolling = true + this.scrolling = true onScrollBeginDrag(e, this.fullState(), this) } + /** + * workaround-3: Android didn't trigger onMomentumScrollEnd after scrollTo(). + */ + onScroll = (e: ScrollEventSim) => { + if (isAndroid && this.autoScrolling) { + const contentOffset = e.nativeEvent.contentOffset + const { dir, offset } = this.state + if (Math.abs(Math.round(contentOffset[dir]) - Math.round(offset[dir])) < 2) { + this.onAndroidScrollEndTimer && clearTimeout(this.onAndroidScrollEndTimer) + // Protect nativeEvent object. + const tmpEvent: ScrollEventSim = { nativeEvent: { contentOffset: { x: contentOffset.x, y: contentOffset.y } } } + this.onAndroidScrollEndTimer = setTimeout(() => { + this.onScrollEnd(tmpEvent) + }, 50) + } + } + } + /** * Scroll end handle */ - onScrollEnd = (e: NativeSyntheticEvent) => { + onScrollEnd = (e: ScrollEventSim) => { const { onMomentumScrollEnd = noop } = this.props - const { dir } = this.state - // update scroll state - this.internals.isScrolling = false + this.scrolling = false + this.autoScrolling = false - let contentOffset // making our events coming from android compatible to updateIndex logic - contentOffset = (e as NativeSyntheticEvent).nativeEvent.contentOffset + const contentOffset = e.nativeEvent.contentOffset - this.updateIndex(contentOffset, dir, () => { + this.updateIndexByOffset(contentOffset, () => { this.autoplay() - this.loopJump() // if `onMomentumScrollEnd` registered will be called here onMomentumScrollEnd(e, this.fullState(), this) @@ -245,32 +288,29 @@ export default class extends Component) => { + onScrollEndDrag = (e: ScrollEventSim) => { const { horizontal, children } = this.props const { index } = this.state const { contentOffset } = e.nativeEvent - const { offset } = this.internals - const previousOffset = horizontal ? offset.x : offset.y + const previousOffset = horizontal ? this.realtimeOffset.x : this.realtimeOffset.y const newOffset = horizontal ? contentOffset.x : contentOffset.y if (previousOffset === newOffset && (index === 0 || index === children.length - 1)) { - this.internals.isScrolling = false + this.scrolling = false } } /** * Update index after scroll */ - updateIndex = (offset: { x?: number; y?: number }, dir: 'x'|'y', cb: any) => { + updateIndexByOffset = (contentOffset: Offset, cb: any) => { const { loop } = this.props - let { index, width, height, total } = this.state + let { index, dir, width, height, total } = this.state // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582 - if (!this.internals.offset) { - this.internals.offset = {} - } + !this.realtimeOffset && (this.realtimeOffset = {}) - const diff = (offset[dir] || 0) - (this.internals.offset[dir] || 0) + const diff = (contentOffset[dir] || 0) - (this.realtimeOffset[dir] || 0) const step = dir === 'x' ? width : height let loopJump = false @@ -280,23 +320,26 @@ export default class extends Component= total) { + } else if (actualIndex === total + 1) { index = 0 - offset[dir] = step + contentOffset[dir] = step loopJump = true + } else { + index = actualIndex - 1 } } const stateWouldBeSet: any = { index, loopJump } - this.internals.offset = offset + this.realtimeOffset = contentOffset // only update offset in state if loopJump is true if (loopJump) { @@ -305,14 +348,14 @@ export default class extends Component { - this.setState({ offset }, cb) + this.setState({ offset: contentOffset }, cb) }) } else { - stateWouldBeSet.offset = offset + stateWouldBeSet.offset = contentOffset this.setState(stateWouldBeSet, cb) } } else { @@ -320,40 +363,9 @@ export default class extends Component { - const { loop } = this.props - const { dir, width, height, index, total } = this.state - if (this.internals.isScrolling || total < 2) return - - const diff = (loop ? 1 : 0) + step + index - let x = 0 - let y = 0 - if (dir === 'x') x = diff * width - if (dir === 'y') y = diff * height - - const node = this.$scrollView.current - node && (node as ScrollView).scrollTo({ x, y, animated }) - - // update scroll state - this.internals.isScrolling = true - - this.setState({ autoplayEnd: false }) - } - scrollViewPropOverrides = () => { const overrides: any = {} - // const scrollResponders = [ - // 'onMomentumScrollBegin', - // 'onTouchStartCapture', - // 'onTouchStart', - // 'onTouchEnd', - // 'onResponderRelease', - // ] - for (let prop in this.props) { // if(~scrollResponders.indexOf(prop) if ( @@ -428,10 +440,13 @@ export default class extends Component @@ -490,7 +505,10 @@ export default class extends Component{children[parseInt(pageIdx)]} } else { return ( - + {loadMinimalLoader ? loadMinimalLoader : } ) diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx index 14ed8d5ba659..98f064f1a769 100644 --- a/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx +++ b/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx @@ -20,6 +20,7 @@ export default StyleSheet.create({ slide: { backgroundColor: 'transparent', + overflow: 'hidden' }, pagination_x: { From b543115e8db4d4fdeecf37729332895c84d5ea21 Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Mon, 24 Jun 2019 09:48:41 +0800 Subject: [PATCH 042/158] =?UTF-8?q?refactor(components-rn):=20Image,=20onL?= =?UTF-8?q?oad=20=E5=8F=AA=E5=9C=A8=E5=AD=98=E5=9C=A8=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E6=89=A7=E8=A1=8C=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=88=E8=AF=A5=E9=83=A8=E5=88=86=E9=80=BB=E8=BE=91=E4=BC=9A?= =?UTF-8?q?=E9=80=A0=E6=88=90=E5=9B=BE=E7=89=87=E8=B5=84=E6=BA=90=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E8=AF=B7=E6=B1=82=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Image/index.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/taro-components-rn/src/components/Image/index.tsx b/packages/taro-components-rn/src/components/Image/index.tsx index 2838271f1bff..4ba6d0c3aabd 100644 --- a/packages/taro-components-rn/src/components/Image/index.tsx +++ b/packages/taro-components-rn/src/components/Image/index.tsx @@ -10,7 +10,7 @@ * @warn Pass require(LOCAL IMAGE) to SRC, otherwise a string-type parameter. * @warn The width/height would be undefined in onLoad. * @warn Avoid using HTTP source image. - * @warn unstable + * @warn Image.resolveAssetSource 会造成重复请求 */ import * as React from 'react' @@ -55,7 +55,8 @@ class _Image extends React.Component { } onLoad = () => { - const { src, onLoad = noop } = this.props + const { src, onLoad } = this.props + if (!onLoad) return if (typeof src === 'string') { Image.getSize(src as string, (width: number, height: number) => { onLoad({ @@ -120,12 +121,8 @@ class _Image extends React.Component { return true } - getSnapshotBeforeUpdate (prevProps: ImageProps, prevState: ImageState) { - return prevProps.src !== this.props.src - } - - componentDidUpdate (prevProps: ImageProps, prevState: ImageState, snapshot: boolean) { - if (snapshot) { + componentDidUpdate (prevProps: ImageProps, prevState: ImageState) { + if (prevProps.src !== this.props.src) { this.loadImg(this.props) } } From 12213de7c88186ed0b3027b3a0e583018e4ca73c Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 24 Jun 2019 10:44:58 +0800 Subject: [PATCH 043/158] chore(release): publish v1.3.3 --- lerna.json | 2 +- .../package.json | 2 +- .../package.json | 4 ++-- packages/css-to-react-native/package.json | 2 +- packages/eslint-config-taro/package.json | 4 ++-- packages/eslint-plugin-taro/package.json | 2 +- .../postcss-plugin-constparse/package.json | 2 +- packages/postcss-pxtransform/package.json | 2 +- packages/postcss-unit-transform/package.json | 2 +- .../stylelint-config-taro-rn/package.json | 4 ++-- packages/stylelint-taro-rn/package.json | 2 +- packages/taro-alipay/package.json | 6 ++--- packages/taro-async-await/package.json | 2 +- packages/taro-cli/package.json | 22 +++++++++---------- packages/taro-components-qa/package.json | 2 +- packages/taro-components-rn/package.json | 2 +- packages/taro-components/package.json | 6 ++--- packages/taro-h5/package.json | 6 ++--- packages/taro-mobx-common/package.json | 2 +- packages/taro-mobx-h5/package.json | 4 ++-- packages/taro-mobx-rn/package.json | 4 ++-- packages/taro-mobx/package.json | 4 ++-- packages/taro-plugin-babel/package.json | 2 +- packages/taro-plugin-csso/package.json | 2 +- packages/taro-plugin-less/package.json | 2 +- packages/taro-plugin-sass/package.json | 2 +- packages/taro-plugin-stylus/package.json | 2 +- packages/taro-plugin-typescript/package.json | 2 +- packages/taro-plugin-uglifyjs/package.json | 2 +- packages/taro-qq/package.json | 6 ++--- packages/taro-quickapp/package.json | 6 ++--- packages/taro-redux-h5/package.json | 4 ++-- packages/taro-redux-rn/package.json | 2 +- packages/taro-redux/package.json | 6 ++--- packages/taro-rn-runner/package.json | 2 +- packages/taro-rn/package.json | 4 ++-- packages/taro-router-rn/package.json | 2 +- packages/taro-router/package.json | 4 ++-- packages/taro-swan/package.json | 6 ++--- packages/taro-transformer-wx/package.json | 6 ++--- packages/taro-tt/package.json | 6 ++--- packages/taro-utils/package.json | 2 +- packages/taro-weapp/package.json | 6 ++--- packages/taro-webpack-runner/package.json | 10 ++++----- packages/taro-with-weapp/package.json | 4 ++-- packages/taro/package.json | 2 +- packages/taroize/package.json | 2 +- 47 files changed, 91 insertions(+), 91 deletions(-) diff --git a/lerna.json b/lerna.json index 4ca7478c21bb..0ad3d28cf208 100644 --- a/lerna.json +++ b/lerna.json @@ -53,6 +53,6 @@ "message": "chore(release): publish %s" } }, - "version": "1.3.2", + "version": "1.3.3", "npmClient": "npm" } diff --git a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json index 513da8db622d..114c100cd349 100644 --- a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json +++ b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-jsx-to-stylesheet", - "version": "1.3.2", + "version": "1.3.3", "description": "Transform stylesheet selector to style in JSX Elements.", "license": "MIT", "main": "src/index.js", diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json index f9bc023af016..98bf238602c1 100644 --- a/packages/babel-plugin-transform-taroapi/package.json +++ b/packages/babel-plugin-transform-taroapi/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-taroapi", - "version": "1.3.2", + "version": "1.3.3", "main": "dist/index.js", "license": "MIT", "scripts": { @@ -10,7 +10,7 @@ "test": "jest" }, "devDependencies": { - "@tarojs/taro-h5": "1.3.2", + "@tarojs/taro-h5": "1.3.3", "@types/babel-core": "^6.25.5", "@types/babel-traverse": "^6.25.4", "@types/babel-types": "^7.0.4", diff --git a/packages/css-to-react-native/package.json b/packages/css-to-react-native/package.json index 32066324bf31..a7a5fc681495 100644 --- a/packages/css-to-react-native/package.json +++ b/packages/css-to-react-native/package.json @@ -1,7 +1,7 @@ { "name": "taro-css-to-react-native", "description": "Convert CSS text to a React Native stylesheet object", - "version": "1.3.2", + "version": "1.3.3", "main": "dist/index.js", "license": "MIT", "scripts": { diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json index 0ac71ee6271c..a70a4a276d13 100644 --- a/packages/eslint-config-taro/package.json +++ b/packages/eslint-config-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-taro", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro specific linting rules for ESLint", "main": "index.js", "files": [ @@ -27,6 +27,6 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "eslint-plugin-taro": "1.3.2" + "eslint-plugin-taro": "1.3.3" } } diff --git a/packages/eslint-plugin-taro/package.json b/packages/eslint-plugin-taro/package.json index 338f7a6d9920..f0f4b846c05d 100644 --- a/packages/eslint-plugin-taro/package.json +++ b/packages/eslint-plugin-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-taro", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro specific linting plugin for ESLint", "main": "index.js", "files": [ diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json index a2681ad294a8..6cacdd414789 100644 --- a/packages/postcss-plugin-constparse/package.json +++ b/packages/postcss-plugin-constparse/package.json @@ -1,6 +1,6 @@ { "name": "postcss-plugin-constparse", - "version": "1.3.2", + "version": "1.3.3", "description": "parse constants defined in config", "main": "index.js", "author": "Simba", diff --git a/packages/postcss-pxtransform/package.json b/packages/postcss-pxtransform/package.json index bfb3d6bb3fe9..3c0869d54d60 100644 --- a/packages/postcss-pxtransform/package.json +++ b/packages/postcss-pxtransform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-pxtransform", - "version": "1.3.2", + "version": "1.3.3", "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位", "keywords": [ "postcss", diff --git a/packages/postcss-unit-transform/package.json b/packages/postcss-unit-transform/package.json index c06c6db5d6ac..6db67df4672c 100644 --- a/packages/postcss-unit-transform/package.json +++ b/packages/postcss-unit-transform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-taro-unit-transform", - "version": "1.3.2", + "version": "1.3.3", "description": "小程序单位转换", "main": "index.js", "scripts": { diff --git a/packages/stylelint-config-taro-rn/package.json b/packages/stylelint-config-taro-rn/package.json index 4ce2a24274ca..f51c0f5d01a5 100644 --- a/packages/stylelint-config-taro-rn/package.json +++ b/packages/stylelint-config-taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-config-taro-rn", - "version": "1.3.2", + "version": "1.3.3", "description": "Shareable stylelint config for React Native CSS modules", "main": "index.js", "files": [ @@ -28,6 +28,6 @@ "jest": "^23.6.0", "npmpub": "^4.1.0", "stylelint": "9.3.0", - "stylelint-taro-rn": "1.3.2" + "stylelint-taro-rn": "1.3.3" } } diff --git a/packages/stylelint-taro-rn/package.json b/packages/stylelint-taro-rn/package.json index 9995864ba887..a34f3554cd61 100644 --- a/packages/stylelint-taro-rn/package.json +++ b/packages/stylelint-taro-rn/package.json @@ -1,7 +1,7 @@ { "name": "stylelint-taro-rn", "description": "A collection of React Native specific rules for stylelint", - "version": "1.3.2", + "version": "1.3.3", "main": "dist/index.js", "babel": { "presets": [ diff --git a/packages/taro-alipay/package.json b/packages/taro-alipay/package.json index 77877ae5a6bb..c636e75c5169 100644 --- a/packages/taro-alipay/package.json +++ b/packages/taro-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-alipay", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro alipay framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.2", - "@tarojs/utils": "1.3.2", + "@tarojs/taro": "1.3.3", + "@tarojs/utils": "1.3.3", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-async-await/package.json b/packages/taro-async-await/package.json index 61f564b13385..80b1dd12655c 100644 --- a/packages/taro-async-await/package.json +++ b/packages/taro-async-await/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/async-await", - "version": "1.3.2", + "version": "1.3.3", "description": "taro async await", "main": "index.js", "scripts": { diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json index a50160c70dda..a3a1494d8f0d 100644 --- a/packages/taro-cli/package.json +++ b/packages/taro-cli/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/cli", - "version": "1.3.2", + "version": "1.3.3", "description": "cli tool for taro", "main": "index.js", "scripts": { @@ -30,8 +30,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taroize": "1.3.2", - "@tarojs/transformer-wx": "1.3.2", + "@tarojs/taroize": "1.3.3", + "@tarojs/transformer-wx": "1.3.3", "@types/request": "^2.48.1", "autoprefixer": "^8.4.1", "babel-core": "^6.26.3", @@ -41,7 +41,7 @@ "babel-plugin-remove-dead-code": "^1.3.2", "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-define": "^1.3.0", - "babel-plugin-transform-jsx-to-stylesheet": "1.3.2", + "babel-plugin-transform-jsx-to-stylesheet": "1.3.3", "babel-plugin-transform-react-jsx": "^6.24.1", "babel-template": "^6.26.0", "babel-traverse": "^6.26.0", @@ -56,10 +56,10 @@ "ejs": "^2.6.1", "envinfo": "^6.0.1", "eslint": "^4.15.0", - "eslint-config-taro": "1.3.2", + "eslint-config-taro": "1.3.3", "eslint-plugin-import": "^2.8.0", "eslint-plugin-react": "^7.4.0", - "eslint-plugin-taro": "1.3.2", + "eslint-plugin-taro": "1.3.3", "eslint-plugin-typescript": "^0.12.0", "fbjs": "^1.0.0", "fs-extra": "^5.0.0", @@ -81,7 +81,7 @@ "postcss-modules-resolve-imports": "^1.3.0", "postcss-modules-scope": "^1.1.0", "postcss-modules-values": "^1.3.0", - "postcss-pxtransform": "1.3.2", + "postcss-pxtransform": "1.3.3", "postcss-reporter": "^6.0.1", "postcss-taro-unit-transform": "1.2.15", "postcss-url": "^7.3.2", @@ -92,16 +92,16 @@ "semver": "^5.5.0", "shelljs": "^0.8.1", "stylelint": "9.3.0", - "stylelint-config-taro-rn": "1.3.2", - "stylelint-taro-rn": "1.3.2", - "taro-css-to-react-native": "1.3.2", + "stylelint-config-taro-rn": "1.3.3", + "stylelint-taro-rn": "1.3.3", + "taro-css-to-react-native": "1.3.3", "through2": "^2.0.3", "vinyl": "^2.1.0", "vinyl-fs": "^3.0.2", "yauzl": "2.10.0" }, "devDependencies": { - "@tarojs/taro": "1.3.2", + "@tarojs/taro": "1.3.3", "@types/autoprefixer": "^9.1.1", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.2", diff --git a/packages/taro-components-qa/package.json b/packages/taro-components-qa/package.json index a0fe2ebecce6..c1df1ea897b5 100644 --- a/packages/taro-components-qa/package.json +++ b/packages/taro-components-qa/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-qa", - "version": "1.3.2", + "version": "1.3.3", "description": "多端解决方案基础组件(快应用)", "main": "./index.js", "files": [ diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index ed1681ecd9f9..ec87ca724fba 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-rn", - "version": "1.3.2", + "version": "1.3.3", "description": "多端解决方案基础组件(RN)", "main": "./dist/index.js", "scripts": { diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json index ddb30f84d190..412f08492791 100644 --- a/packages/taro-components/package.json +++ b/packages/taro-components/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components", - "version": "1.3.2", + "version": "1.3.3", "description": "", "main:h5": "src/index.js", "main": "dist/index.js", @@ -49,14 +49,14 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0", "@babel/plugin-transform-react-jsx": "^7.0.0", "@babel/preset-env": "^7.1.5", - "@tarojs/taro-h5": "1.3.2", + "@tarojs/taro-h5": "1.3.3", "@types/react": "^16.4.6", "@types/urijs": "^1.15.38", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "10.0.1", "babel-jest": "^22.4.4", "babel-loader": "^8.0.5", - "babel-plugin-transform-taroapi": "1.3.2", + "babel-plugin-transform-taroapi": "1.3.3", "css-loader": "^2.1.1", "file-loader": "^3.0.1", "jest": "^22.4.4", diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json index 1ca30eca3a50..8ba6afa31fdc 100644 --- a/packages/taro-h5/package.json +++ b/packages/taro-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-h5", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro h5 framework", "main:h5": "src/index.js", "main": "dist/index.js", @@ -43,8 +43,8 @@ "@babel/plugin-proposal-object-rest-spread": "^7.3.4", "@babel/plugin-transform-react-jsx": "^7.2.2", "@babel/preset-env": "^7.3.4", - "@tarojs/components": "1.3.2", - "@tarojs/taro": "1.3.2", + "@tarojs/components": "1.3.3", + "@tarojs/taro": "1.3.3", "babel-core": "7.0.0-bridge.0", "babel-jest": "24.4.0", "eslint": "^4.18.2", diff --git a/packages/taro-mobx-common/package.json b/packages/taro-mobx-common/package.json index fad3f82989fb..1f8d5ba62434 100644 --- a/packages/taro-mobx-common/package.json +++ b/packages/taro-mobx-common/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-common", - "version": "1.3.2", + "version": "1.3.3", "description": "mobx library for taro", "keywords": [ "mobx", diff --git a/packages/taro-mobx-h5/package.json b/packages/taro-mobx-h5/package.json index 6d50223159d2..b473bf97522f 100644 --- a/packages/taro-mobx-h5/package.json +++ b/packages/taro-mobx-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-h5", - "version": "1.3.2", + "version": "1.3.3", "description": "mobx-h5 for taro", "keywords": [ "mobx", @@ -29,7 +29,7 @@ "nervjs": "^1.4.0" }, "dependencies": { - "@tarojs/mobx-common": "1.3.2" + "@tarojs/mobx-common": "1.3.3" }, "devDependencies": { "rimraf": "^2.6.2", diff --git a/packages/taro-mobx-rn/package.json b/packages/taro-mobx-rn/package.json index 2638c3bd27e9..19fe8b63a10f 100644 --- a/packages/taro-mobx-rn/package.json +++ b/packages/taro-mobx-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-rn", - "version": "1.3.2", + "version": "1.3.3", "description": "mobx-rn for taro", "keywords": [ "mobx", @@ -18,7 +18,7 @@ "src" ], "dependencies": { - "@tarojs/mobx-common": "1.3.2", + "@tarojs/mobx-common": "1.3.3", "@tarojs/taro-rn": "1.1.7" } } diff --git a/packages/taro-mobx/package.json b/packages/taro-mobx/package.json index 925b37d2aee7..a440da0a9d2d 100644 --- a/packages/taro-mobx/package.json +++ b/packages/taro-mobx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx", - "version": "1.3.2", + "version": "1.3.3", "description": "mobx for taro", "keywords": [ "mobx", @@ -22,7 +22,7 @@ "clear": "rimraf dist" }, "dependencies": { - "@tarojs/mobx-common": "1.3.2" + "@tarojs/mobx-common": "1.3.3" }, "peerDependencies": { "mobx": "4.8.0" diff --git a/packages/taro-plugin-babel/package.json b/packages/taro-plugin-babel/package.json index a15511e771ed..b92d656f5472 100644 --- a/packages/taro-plugin-babel/package.json +++ b/packages/taro-plugin-babel/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-babel", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro babel编译", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-csso/package.json b/packages/taro-plugin-csso/package.json index b0379909f0bf..62d0aca5822c 100644 --- a/packages/taro-plugin-csso/package.json +++ b/packages/taro-plugin-csso/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-csso", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro压缩CSS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-less/package.json b/packages/taro-plugin-less/package.json index 6b1e774bf0b8..76f239c3432f 100644 --- a/packages/taro-plugin-less/package.json +++ b/packages/taro-plugin-less/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-less", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro 编译 less 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-sass/package.json b/packages/taro-plugin-sass/package.json index 0d1a4cfb4d1f..ba1969587162 100644 --- a/packages/taro-plugin-sass/package.json +++ b/packages/taro-plugin-sass/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-sass", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro编译sass文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-stylus/package.json b/packages/taro-plugin-stylus/package.json index ac354660cf32..3b271150b70d 100644 --- a/packages/taro-plugin-stylus/package.json +++ b/packages/taro-plugin-stylus/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-stylus", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro 编译 stylus 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-typescript/package.json b/packages/taro-plugin-typescript/package.json index 32073a8402c8..dac4496f8bb1 100644 --- a/packages/taro-plugin-typescript/package.json +++ b/packages/taro-plugin-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-typescript", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro TypeScript 编译插件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-uglifyjs/package.json b/packages/taro-plugin-uglifyjs/package.json index 6ba96ffba759..d9b208f0de87 100644 --- a/packages/taro-plugin-uglifyjs/package.json +++ b/packages/taro-plugin-uglifyjs/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-uglifyjs", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro压缩JS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-qq/package.json b/packages/taro-qq/package.json index 68502118ae04..83cd4a6b26f2 100644 --- a/packages/taro-qq/package.json +++ b/packages/taro-qq/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-qq", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro qq framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.2", - "@tarojs/utils": "1.3.2", + "@tarojs/taro": "1.3.3", + "@tarojs/utils": "1.3.3", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-quickapp/package.json b/packages/taro-quickapp/package.json index c92fe5ec1be2..69d1fff12e88 100644 --- a/packages/taro-quickapp/package.json +++ b/packages/taro-quickapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-quickapp", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro quickapp framework", "main": "index.js", "files": [ @@ -23,8 +23,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.2", - "@tarojs/utils": "1.3.2", + "@tarojs/taro": "1.3.3", + "@tarojs/utils": "1.3.3", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-redux-h5/package.json b/packages/taro-redux-h5/package.json index fe18d11eb4b9..17e53f1a512d 100644 --- a/packages/taro-redux-h5/package.json +++ b/packages/taro-redux-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux-h5", - "version": "1.3.2", + "version": "1.3.3", "description": "Forked react-redux for taro", "keywords": [ "react", @@ -46,7 +46,7 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.49", "@babel/plugin-transform-react-jsx": "^7.0.0-beta.49", "@babel/preset-env": "^7.0.0-beta.49", - "@tarojs/taro-h5": "1.3.2", + "@tarojs/taro-h5": "1.3.3", "babel-plugin-transform-react-remove-prop-types": "^0.4.13", "redux": "^4.0.0", "rimraf": "^2.6.2", diff --git a/packages/taro-redux-rn/package.json b/packages/taro-redux-rn/package.json index 97c48d66841e..a0ca45348f02 100644 --- a/packages/taro-redux-rn/package.json +++ b/packages/taro-redux-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-redux-rn", - "version": "1.3.2", + "version": "1.3.3", "description": "taro-redux-rn", "main": "./src/index.js", "files": [ diff --git a/packages/taro-redux/package.json b/packages/taro-redux/package.json index 01366fee5a8f..e5a52e4aa494 100644 --- a/packages/taro-redux/package.json +++ b/packages/taro-redux/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux", - "version": "1.3.2", + "version": "1.3.3", "description": "Redux for Taro", "main": "index.js", "typings": "types/index.d.ts", @@ -31,7 +31,7 @@ "jest": "^23.1.0" }, "dependencies": { - "@tarojs/taro": "1.3.2", - "@tarojs/utils": "1.3.2" + "@tarojs/taro": "1.3.3", + "@tarojs/utils": "1.3.3" } } diff --git a/packages/taro-rn-runner/package.json b/packages/taro-rn-runner/package.json index 76d3ce853d17..68f67579acf4 100644 --- a/packages/taro-rn-runner/package.json +++ b/packages/taro-rn-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-runner", - "version": "1.3.2", + "version": "1.3.3", "description": "ReactNative build tool for taro", "main": "index.js", "scripts": { diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json index 94d37fd76452..99c956e99a64 100644 --- a/packages/taro-rn/package.json +++ b/packages/taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-rn", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro RN framework", "main": "./index.js", "files": [ @@ -27,7 +27,7 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.2", + "@tarojs/taro": "1.3.3", "base64-js": "^1.3.0", "react-native-image-crop-picker": "^0.23.1", "react-native-image-zoom-viewer": "^2.2.13", diff --git a/packages/taro-router-rn/package.json b/packages/taro-router-rn/package.json index cc3a3996a83b..26aa2768507b 100644 --- a/packages/taro-router-rn/package.json +++ b/packages/taro-router-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-router-rn", - "version": "1.3.2", + "version": "1.3.3", "description": "taro-router-rn", "main": "./index.js", "files": [ diff --git a/packages/taro-router/package.json b/packages/taro-router/package.json index 56b81d856c21..28f090f05895 100644 --- a/packages/taro-router/package.json +++ b/packages/taro-router/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/router", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro-router", "main:h5": "dist/index.esm.js", "main": "index.js", @@ -41,7 +41,7 @@ "@babel/plugin-syntax-dynamic-import": "7.0.0", "@babel/plugin-transform-react-jsx": "7.0.0", "@babel/preset-env": "7.1.5", - "@tarojs/taro-h5": "1.3.2", + "@tarojs/taro-h5": "1.3.3", "@types/history": "4.7.2", "@types/jasmine": "2.8.11", "@types/jest": "23.3.9", diff --git a/packages/taro-swan/package.json b/packages/taro-swan/package.json index 872805ac733f..1d774f14c2d2 100644 --- a/packages/taro-swan/package.json +++ b/packages/taro-swan/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-swan", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro swan framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.2", - "@tarojs/utils": "1.3.2", + "@tarojs/taro": "1.3.3", + "@tarojs/utils": "1.3.3", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-transformer-wx/package.json b/packages/taro-transformer-wx/package.json index 1df2e5e025b7..3e192daffbd0 100644 --- a/packages/taro-transformer-wx/package.json +++ b/packages/taro-transformer-wx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/transformer-wx", - "version": "1.3.2", + "version": "1.3.3", "description": "Transfrom Nerv Component to Wechat mini program.", "repository": { "type": "git", @@ -62,14 +62,14 @@ "babel-types": "^6.26.0", "eslint": "^4.15.0", "eslint-plugin-react": "7.10.0", - "eslint-plugin-taro": "1.3.2", + "eslint-plugin-taro": "1.3.3", "html": "^1.0.0", "lodash": "^4.17.5", "prettier": "^1.14.2", "typescript": "^3.2.2" }, "devDependencies": { - "@tarojs/taro": "1.3.2", + "@tarojs/taro": "1.3.3", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.1", "@types/babel-template": "^6.25.0", diff --git a/packages/taro-tt/package.json b/packages/taro-tt/package.json index 34aa6a5668ca..7b49dfcc5708 100644 --- a/packages/taro-tt/package.json +++ b/packages/taro-tt/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-tt", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro toutiao framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.2", - "@tarojs/utils": "1.3.2", + "@tarojs/taro": "1.3.3", + "@tarojs/utils": "1.3.3", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-utils/package.json b/packages/taro-utils/package.json index 64b2258b0d54..87efd1df0a63 100644 --- a/packages/taro-utils/package.json +++ b/packages/taro-utils/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/utils", - "version": "1.3.2", + "version": "1.3.3", "description": "Utils for Taro", "main": "index.js", "scripts": { diff --git a/packages/taro-weapp/package.json b/packages/taro-weapp/package.json index 1c5c895204bc..f9db13f9b52b 100644 --- a/packages/taro-weapp/package.json +++ b/packages/taro-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-weapp", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro weapp framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.2", - "@tarojs/utils": "1.3.2", + "@tarojs/taro": "1.3.3", + "@tarojs/utils": "1.3.3", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json index 45e8c3f2034c..01c177a638ee 100644 --- a/packages/taro-webpack-runner/package.json +++ b/packages/taro-webpack-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/webpack-runner", - "version": "1.3.2", + "version": "1.3.3", "description": "webpack runner for taro", "main": "index.js", "scripts": { @@ -32,13 +32,13 @@ }, "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { - "@tarojs/taro-h5": "1.3.2", + "@tarojs/taro-h5": "1.3.3", "autoprefixer": "8.6.4", "babel-core": "6.26.0", "babel-loader": "7.1.4", "babel-plugin-syntax-dynamic-import": "6.18.0", "babel-plugin-transform-react-jsx": "6.24.1", - "babel-plugin-transform-taroapi": "1.3.2", + "babel-plugin-transform-taroapi": "1.3.3", "babel-types": "6.26.0", "chalk": "2.4.2", "copy-webpack-plugin": "^5.0.3", @@ -55,8 +55,8 @@ "opn": "5.3.0", "ora": "2.1.0", "postcss-loader": "2.1.6", - "postcss-plugin-constparse": "1.3.2", - "postcss-pxtransform": "1.3.2", + "postcss-plugin-constparse": "1.3.3", + "postcss-pxtransform": "1.3.3", "resolve": "1.8.1", "resolve-url-loader": "2.3.0", "sass-loader": "7.1.0", diff --git a/packages/taro-with-weapp/package.json b/packages/taro-with-weapp/package.json index 72f03cb63d5c..8aa9d298e0a1 100644 --- a/packages/taro-with-weapp/package.json +++ b/packages/taro-with-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/with-weapp", - "version": "1.3.2", + "version": "1.3.3", "description": "taroize 之后的运行时", "main": "index.js", "scripts": { @@ -22,7 +22,7 @@ "author": "yuche", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.2", + "@tarojs/taro": "1.3.3", "lodash": "^4.17.11" }, "devDependencies": { diff --git a/packages/taro/package.json b/packages/taro/package.json index 602337cccdc1..b4eafeaaaf3b 100644 --- a/packages/taro/package.json +++ b/packages/taro/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro", - "version": "1.3.2", + "version": "1.3.3", "description": "Taro framework", "module": "dist/index.esm.js", "main": "index.js", diff --git a/packages/taroize/package.json b/packages/taroize/package.json index a2309d8acb69..6a3a70136758 100644 --- a/packages/taroize/package.json +++ b/packages/taroize/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taroize", - "version": "1.3.2", + "version": "1.3.3", "description": "转换原生微信小程序代码为 Taro 代码", "main": "index.js", "files": [ From ba379c184662846b3bc71663c8a54acd8ffb01ef Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 24 Jun 2019 11:11:21 +0800 Subject: [PATCH 044/158] chore: changelog --- CHANGELOG.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10b012f2469d..3254642c3b74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ -# [](https://github.com/NervJS/taro/compare/v1.3.2...v) (2019-06-17) +# [](https://github.com/NervJS/taro/compare/v1.3.3...v) (2019-06-24) + + + + +## [1.3.3](https://github.com/NervJS/taro/compare/v1.3.2...v1.3.3) (2019-06-24) + + +### Bug Fixes + +* **alipay:** 修复在支付宝分包中状态管理工具不可用的问题,fix [#3445](https://github.com/NervJS/taro/issues/3445) ([a6f4c0a](https://github.com/NervJS/taro/commit/a6f4c0a)) +* **cli:** 修复快应用编译报错,快应用依赖安装问题 ([15bed06](https://github.com/NervJS/taro/commit/15bed06)) +* **cli:** 引入json包含null的问题,close [#3505](https://github.com/NervJS/taro/issues/3505) ([849999d](https://github.com/NervJS/taro/commit/849999d)) +* **router:** 修复偶尔页面隐藏失败的情况 ([b9f708a](https://github.com/NervJS/taro/commit/b9f708a)) +* **taro:** 增加 Taro.getAccountInfoSync 类型定义 ([#3433](https://github.com/NervJS/taro/issues/3433)) ([2f33f56](https://github.com/NervJS/taro/commit/2f33f56)) +* **taro-weapp:** 微信小程序能通过 extraProps 接收外部 props ([506ca02](https://github.com/NervJS/taro/commit/506ca02)) +* **taro-weapp/tt/swan/qq/alipay:** 拦截器添加 cleanInterceptors 方法 ([22edff9](https://github.com/NervJS/taro/commit/22edff9)) + + +### Features + +* **taro-components:** add borderRadius for Progress Component ([4484546](https://github.com/NervJS/taro/commit/4484546)) @@ -34,6 +55,7 @@ * **cli:** 修正页面创建时页面命名等问题 ([247b0c0](https://github.com/NervJS/taro/commit/247b0c0)) * **mobx-h5:** 修复inject组件的componentDidShow内获取不到组件this的问题, fix [#3333](https://github.com/NervJS/taro/issues/3333) ([322f258](https://github.com/NervJS/taro/commit/322f258)) +* 优化h5 下 ScrollView 标签,提供 onTouchMove 方法 ([44b730a](https://github.com/NervJS/taro/commit/44b730a)) * **rn:** [RN]Taro.getCurrentPages方法不存在 close [#3224](https://github.com/NervJS/taro/issues/3224) ([a9b8fa7](https://github.com/NervJS/taro/commit/a9b8fa7)) * **taro-tt:** 修复头条小程序事件不带 type 参数的问题,fix [#3382](https://github.com/NervJS/taro/issues/3382) ([1977062](https://github.com/NervJS/taro/commit/1977062)) * **transformer:**   在第一个直接时会被无视, close [#3406](https://github.com/NervJS/taro/issues/3406) ([4d14dd7](https://github.com/NervJS/taro/commit/4d14dd7)) From 3deb1a797d3c6039ff6894db8b1589863346f019 Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Mon, 24 Jun 2019 15:10:01 +0800 Subject: [PATCH 045/158] =?UTF-8?q?fix(weapp):=20=E4=BF=AE=E5=A4=8D=20mobx?= =?UTF-8?q?=20=E4=B8=8B=20extraProps=20=E5=88=A4=E6=96=AD=20bug=E3=80=82cl?= =?UTF-8?q?ose=20#3513?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-weapp/src/propsManager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/taro-weapp/src/propsManager.js b/packages/taro-weapp/src/propsManager.js index 9f6d4314b960..e8a5a9dc09ab 100644 --- a/packages/taro-weapp/src/propsManager.js +++ b/packages/taro-weapp/src/propsManager.js @@ -23,7 +23,8 @@ class Manager { const ComponentClass = observers[compid] && observers[compid].ComponentClass if (!component || !ComponentClass || !component.__isReady) return - const nextProps = filterProps(ComponentClass.defaultProps, props, component.props, this.data.extraProps) + const extraProps = (this && this.data && this.data.extraProps) || null + const nextProps = filterProps(ComponentClass.defaultProps, props, component.props, extraProps) component.props = nextProps nextTick(() => { component._unsafeCallUpdate = true From 0a66dbdd6a3172e07bb2838890159322c8f6241a Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 24 Jun 2019 14:14:52 +0800 Subject: [PATCH 046/158] =?UTF-8?q?feat(transformer):=20=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=9C=A8=E5=BF=AB=E5=BA=94=E7=94=A8=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E4=B8=AD=E4=BD=BF=E7=94=A8=E5=8C=BF=E5=90=8D=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C#3495?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/jsx.ts | 3 +++ packages/taro-transformer-wx/src/render.ts | 24 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/taro-transformer-wx/src/jsx.ts b/packages/taro-transformer-wx/src/jsx.ts index 637de1dc0f88..8f858271490d 100644 --- a/packages/taro-transformer-wx/src/jsx.ts +++ b/packages/taro-transformer-wx/src/jsx.ts @@ -82,6 +82,9 @@ export function setJSXAttr ( value?: t.StringLiteral | t.JSXExpressionContainer | t.JSXElement, path?: NodePath ) { + if ((name === Adapter.forIndex || name === Adapter.forItem) && Adapter.type === Adapters.quickapp) { + return + } const element = jsx.openingElement if (!t.isJSXIdentifier(element.name)) { return diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index a6d0fde46eb7..cfa21ab9927b 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -573,7 +573,7 @@ export class RenderParser { } else { forExpr = `(${indexName}, ${itemName}) in ${code}` } - setJSXAttr(jsxElementPath.node, Adapter.for, t.stringLiteral(forExpr)) + setJSXAttr(jsxElementPath.node, Adapter.for, t.stringLiteral(`{{${forExpr}}}`)) } // if (itemName && !indexName) { // const forExpr = gene @@ -1718,9 +1718,13 @@ export class RenderParser { }) const [ func ] = callee.node.arguments let indexId: t.Identifier | null = null + let itemId: t.Identifier | null = null if (t.isFunctionExpression(func) || t.isArrowFunctionExpression(func)) { const params = func.params as t.Identifier[] - indexId = params[1] + if (Array.isArray(params)) { + indexId = params[1] + itemId = params[0] + } } if (this.loopRefs.has(component.node) || loopRefComponent!) { hasLoopRef = true @@ -2052,7 +2056,21 @@ export class RenderParser { // setJSXAttr(returned, Adapter.for, t.identifier(stateName)) this.addRefIdentifier(callee, t.identifier(stateName)) // this.referencedIdentifiers.add(t.identifier(stateName)) - setJSXAttr(component.node, Adapter.for, t.jSXExpressionContainer(t.identifier(stateName))) + if (Adapters.quickapp === Adapter.type) { + let itemName = indexId!.name + let indexName = indexId!.name + if (itemName || indexName) { + let forExpr: string + if (itemName && !indexName) { + forExpr = `${itemName} in ${stateName}` + } else { + forExpr = `(${indexName}, ${itemName}) in ${stateName}` + } + setJSXAttr(component.node, Adapter.for, t.stringLiteral(`{{${forExpr}}}`)) + } + } else { + setJSXAttr(component.node, Adapter.for, t.jSXExpressionContainer(t.identifier(stateName))) + } const returnBody = this.renderPath.node.body.body const ifStem = callee.findParent(p => p.isIfStatement()) // @TEST From beb21f019fa06d9eba3a9f72531943b4985d62fa Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 24 Jun 2019 14:51:32 +0800 Subject: [PATCH 047/158] =?UTF-8?q?fix(transformer):=20=E5=9C=A8=20hooks?= =?UTF-8?q?=20=E4=BC=9A=E6=8A=8A=20return=20=E6=9B=BF=E6=8D=A2=EF=BC=8Cclo?= =?UTF-8?q?se=20#3469?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/class.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-transformer-wx/src/class.ts b/packages/taro-transformer-wx/src/class.ts index 893462260937..d77cef58e2eb 100644 --- a/packages/taro-transformer-wx/src/class.ts +++ b/packages/taro-transformer-wx/src/class.ts @@ -459,7 +459,7 @@ class Transformer { const arg = returnPath.node.argument const ifStem = returnPath.findParent(p => p.isIfStatement()) // tslint:disable-next-line: strict-type-predicates - if (ifStem && ifStem.isIfStatement() && arg === null) { + if (ifStem && classMethodPath.node.body.body.some(s => s === ifStem.node) && ifStem.isIfStatement() && arg === null) { const consequent = ifStem.get('consequent') if (consequent.isBlockStatement() && consequent.node.body.includes(returnPath.node)) { returnPath.get('argument').replaceWith(t.nullLiteral()) From 38a38cedfe59e3834493fd055e77f4c14610e108 Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 24 Jun 2019 16:28:01 +0800 Subject: [PATCH 048/158] =?UTF-8?q?feat(transformer):=20=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E4=B8=AD=E5=8F=AF=E4=BB=A5=E7=9B=B4=E6=8E=A5=20return=20JSX=20?= =?UTF-8?q?=E5=BC=95=E7=94=A8=EF=BC=8Cclose=20#3504?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/render.ts | 7 ++++--- packages/taro-transformer-wx/src/utils.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index cfa21ab9927b..56e03a3b0b09 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -769,8 +769,8 @@ export class RenderParser { } if (t.isIdentifier(parentNode.left)) { const assignmentName = parentNode.left.name - const renderScope = isIfStemInLoop ? jsxElementPath.findParent(p => isArrayMapCallExpression(p)).get('arguments')[0].get('body').scope : this.renderScope - const bindingNode = renderScope.getOwnBinding(assignmentName).path.node + const renderScope: Scope = isIfStemInLoop ? jsxElementPath.findParent(p => isArrayMapCallExpression(p)).get('arguments')[0].get('body').scope : this.renderScope + const bindingNode = renderScope.getOwnBinding(assignmentName)!.path.node // tslint:disable-next-line const parallelIfStems = this.findParallelIfStem(ifStatement) const parentIfStatement = ifStatement.findParent(p => @@ -897,6 +897,7 @@ export class RenderParser { // setTemplate(name, path, templates) assignmentName && this.templates.set(assignmentName, block) if (isIfStemInLoop) { + this.replaceIdWithTemplate()(renderScope.path) this.returnedPaths.push(parentPath) } } @@ -2058,7 +2059,7 @@ export class RenderParser { // this.referencedIdentifiers.add(t.identifier(stateName)) if (Adapters.quickapp === Adapter.type) { let itemName = indexId!.name - let indexName = indexId!.name + let indexName = itemId!.name if (itemName || indexName) { let forExpr: string if (itemName && !indexName) { diff --git a/packages/taro-transformer-wx/src/utils.ts b/packages/taro-transformer-wx/src/utils.ts index edc564917322..f7e4a321d56a 100644 --- a/packages/taro-transformer-wx/src/utils.ts +++ b/packages/taro-transformer-wx/src/utils.ts @@ -246,7 +246,7 @@ export function generateAnonymousState ( if (isArrowFunctionInJSX) { return } - if (t.isIdentifier(id) && !id.name.startsWith(LOOP_STATE) && !id.name.startsWith('_$')) { + if (t.isIdentifier(id) && !id.name.startsWith(LOOP_STATE) && !id.name.startsWith('_$') && init != null) { const newId = scope.generateDeclaredUidIdentifier('$' + id.name) refIds.forEach((refId) => { if (refId.name === variableName && !variableName.startsWith('_$')) { From 328843668e422661276dcd4922ed7557da105632 Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Mon, 24 Jun 2019 19:55:24 +0800 Subject: [PATCH 049/158] =?UTF-8?q?fix(weapp):=20=E4=BF=AE=E5=A4=8D=20extr?= =?UTF-8?q?aProps=20=E5=88=A4=E6=96=AD=20bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/best-practice.md | 20 ++++++++++++++++++++ packages/taro-weapp/src/propsManager.js | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/best-practice.md b/docs/best-practice.md index dbe59e9e57cd..070d7c7175ba 100644 --- a/docs/best-practice.md +++ b/docs/best-practice.md @@ -234,6 +234,26 @@ if (process.env.NODE_ENV === 'development') { `this.$componentType` 可能取值分别为 `PAGE` 和 `COMPONENT`,开发者可以根据此变量的取值分别采取不同逻辑。 +### 原生小程序组件传递 props 给 Taro 组件 + +**Taro v1.3+** 对 props 系统进行了改造,使得不能兼容原生组件通过 properties 传入的属性。 + +目前可以通过把所有需要传入 Taro 组件的 props,通过借助 `extraProps` 属性来解决。 + +```js +// 小程序组件常规 props 传递 + + +// 原生小程序组件调用 Taro 组件时需要改造成以下形式: +this.setData({ + extraProps: { + name, + desc + } +}) + +``` + ## 全局变量 在 Taro 中推荐使用 `Redux` 来进行全局变量的管理,但是对于一些小型的应用, `Redux` 就可能显得比较重了,这时候如果想使用全局变量,推荐如下使用。 diff --git a/packages/taro-weapp/src/propsManager.js b/packages/taro-weapp/src/propsManager.js index e8a5a9dc09ab..9b59db7615ac 100644 --- a/packages/taro-weapp/src/propsManager.js +++ b/packages/taro-weapp/src/propsManager.js @@ -23,7 +23,7 @@ class Manager { const ComponentClass = observers[compid] && observers[compid].ComponentClass if (!component || !ComponentClass || !component.__isReady) return - const extraProps = (this && this.data && this.data.extraProps) || null + const extraProps = (component.$scope && component.$scope.data && component.$scope.data.extraProps) || null const nextProps = filterProps(ComponentClass.defaultProps, props, component.props, extraProps) component.props = nextProps nextTick(() => { From 6b525c23b82414a5660c905f910b60e10aa7f5ee Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 24 Jun 2019 20:22:33 +0800 Subject: [PATCH 050/158] =?UTF-8?q?fix(transformer):=20=E5=B5=8C=E5=A5=97?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E5=88=A4=E6=96=AD=E4=BD=BF=E7=94=A8=E4=B8=8A?= =?UTF-8?q?=E7=BA=A7=E5=8F=98=E9=87=8F=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=8Cclose=20#3462?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/render.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index 56e03a3b0b09..b06e8da6d223 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -1971,7 +1971,7 @@ export class RenderParser { return } } - if (this.ancestorConditions.has(parentCondition.node)) { + if (path.findParent(p => this.ancestorConditions.has(p.node))) { return } } From 96573c1ff16c486273009e9fdcf23680b7003954 Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 24 Jun 2019 21:20:28 +0800 Subject: [PATCH 051/158] =?UTF-8?q?fix(transformer):=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E7=B1=BB=EF=BC=8Cclose=20#3080?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/render.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index b06e8da6d223..68d38432ed20 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -996,6 +996,7 @@ export class RenderParser { && name.name !== Adapter.forIndex && name.name.indexOf('render') !== 0 && !t.isJSXElement(value) + && !name.name.includes('-') ) { // tslint:disable-next-line: strict-type-predicates const v: t.StringLiteral | t.Expression | t.BooleanLiteral = value === null From 6714e244e2f6d9a7efe08452d7796ca18ad869ac Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Mon, 24 Jun 2019 21:42:23 +0800 Subject: [PATCH 052/158] =?UTF-8?q?feat(components-rn):=20ScrollView,=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20FlatList=20=E6=9D=A5=E4=BB=A3=E6=9B=BF=20S?= =?UTF-8?q?crollView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TCRNExample/App.flatlist.js | 157 ++++++++++++++++++ .../src/components/ScrollView/PropsType.tsx | 6 +- .../src/components/ScrollView/index.tsx | 112 ++++++++----- 3 files changed, 229 insertions(+), 46 deletions(-) create mode 100644 packages/taro-components-rn/TCRNExample/App.flatlist.js diff --git a/packages/taro-components-rn/TCRNExample/App.flatlist.js b/packages/taro-components-rn/TCRNExample/App.flatlist.js new file mode 100644 index 000000000000..681c89eaa639 --- /dev/null +++ b/packages/taro-components-rn/TCRNExample/App.flatlist.js @@ -0,0 +1,157 @@ +import React, { Component } from 'react' +import { StyleSheet } from 'react-native' +import { + Provider, + Block, + ScrollView, + View, + Text, + Button, + Image +} from '../dist' +// import EXAudio from './example/EXAudio' +import EXButton from './example/EXButton' +import EXCheckbox from './example/EXCheckbox' +import EXForm from './example/EXForm' +import EXIcon from './example/EXIcon' +import EXImage from './example/EXImage' +import EXInput from './example/EXInput' +// import EXMap from './example/EXMap' +import EXPicker from './example/EXPicker' +import EXProgress from './example/EXProgress' +import EXRadio from './example/EXRadio' +import EXRichText from './example/EXRichText' +import EXSlider from './example/EXSlider' +import EXSwiper from './example/EXSwiper' +import EXSwitch from './example/EXSwitch' +// import EXVideo from './example/EXVideo' +import EXWebView from './example/EXWebView' + +export default class App extends Component { + state = { + // 更改 scrollTop 可滚动 + scrollTop: 0 + } + + onViewTouchstart = () => { + console.log('view toucstart') + } + + onViewTouchmove = () => { + console.log('view touchmove') + } + + onViewTouchend = () => { + console.log('view touchend') + } + + componentDidMount () { + // setTimeout(() => { + // this.setState({ scrollTop: 2200 }) + // }, 0) + } + + renderItem = ({ item }) => { + switch (item.name) { + case 'welcome': + return Welcome to React Native! + case 'Block': + return ( + + + Block + + + + ) + case 'Button': + return ( + + + Button + + + + ) + case 'Checkbox': + return ( + + + Checkbox + + + + ) + case 'Form': + return ( + + + Form + + + + ) + } + } + + render () { + return ( + + { + console.log('to upper') + }} + onScrollToLower={() => { + console.log('to lower') + }} + onScroll={(e) => { + console.log('onScroll', e) + }} + bounces={false} + data={[ + { name: 'welcome' }, + { name: 'Block' }, + { name: 'Button' }, + { name: 'Checkbox' }, + { name: 'Form' }, + ]} + renderItem={this.renderItem} + /> + + ) + } +} + +const styles = StyleSheet.create({ + section: { + alignItems: 'center', + width: '100%', + paddingBottom: 10, + marginBottom: 10, + borderBottomWidth: 1, + borderBottomColor: 'gold' + }, + sectionTit: { + marginBottom: 10, + paddingVertical: 4, + paddingHorizontal: 8, + backgroundColor: 'tomato', + borderRadius: 4, + borderLeftWidth: 3, + borderLeftColor: '#666', + borderRightWidth: 3, + borderRightColor: '#666' + }, + sectionTitTxt: { + fontSize: 18, + color: 'white' + } +}) diff --git a/packages/taro-components-rn/src/components/ScrollView/PropsType.tsx b/packages/taro-components-rn/src/components/ScrollView/PropsType.tsx index fc38857cf139..465ea9c60f01 100644 --- a/packages/taro-components-rn/src/components/ScrollView/PropsType.tsx +++ b/packages/taro-components-rn/src/components/ScrollView/PropsType.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { StyleProp, ViewStyle } from 'react-native' +import { StyleProp, ViewStyle, ListRenderItem } from 'react-native' export type ScrollMetrics = { contentLength: number; @@ -37,7 +37,7 @@ export interface ScrollViewState { snapScrollLeft: number; } -export interface ScrollViewProps { +export interface ScrollViewProps { children?: React.ReactNode; style?: StyleProp; scrollX?: boolean; @@ -52,4 +52,6 @@ export interface ScrollViewProps { onScroll?: (evt: EventOnScroll) => void; // RN 属性 contentContainerStyle?: StyleProp; + data?: ReadonlyArray | null; + renderItem?: ListRenderItem; } diff --git a/packages/taro-components-rn/src/components/ScrollView/index.tsx b/packages/taro-components-rn/src/components/ScrollView/index.tsx index 4a5e0fb3e38c..9ee100aa7615 100644 --- a/packages/taro-components-rn/src/components/ScrollView/index.tsx +++ b/packages/taro-components-rn/src/components/ScrollView/index.tsx @@ -22,6 +22,7 @@ import * as React from 'react' import { ScrollView, + FlatList, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, @@ -38,7 +39,7 @@ import { ScrollViewProps, ScrollViewState, ScrollMetrics } from './PropsType' // // Other // ] -class _ScrollView extends React.Component { +class _ScrollView extends React.Component, ScrollViewState> { static defaultProps = { upperThreshold: 50, lowerThreshold: 50, @@ -47,7 +48,7 @@ class _ScrollView extends React.Component { enableBackToTop: false, } - static getDerivedStateFromProps (props: ScrollViewProps, state: ScrollViewState) { + static getDerivedStateFromProps (props: ScrollViewProps, state: ScrollViewState) { return state.snapScrollTop !== props.scrollTop || state.snapScrollLeft !== props.scrollLeft ? { snapScrollTop: props.scrollTop, snapScrollLeft: props.scrollLeft @@ -70,7 +71,7 @@ class _ScrollView extends React.Component { velocity: 0, visibleLength: 0, } - $scrollView = React.createRef() + $scrollView = React.createRef() _hasDataChangedSinceEndReached: boolean _sentEndForContentLength: number = 0 _scrollEventThrottle: number = 50 @@ -180,8 +181,15 @@ class _ScrollView extends React.Component { } scrollToOffset = (x: number = 0, y: number = 0): void => { + const { scrollX, data, renderItem } = this.props const node = this.$scrollView.current - node && node.scrollTo({ x, y, animated: !!this.props.scrollWithAnimation }) + if (node) { + if (data && renderItem) { + (node as FlatList).scrollToOffset({ offset: scrollX ? x : y, animated: !!this.props.scrollWithAnimation }) + } else { + (node as ScrollView).scrollTo({ x, y, animated: !!this.props.scrollWithAnimation }) + } + } } componentDidMount () { @@ -192,11 +200,11 @@ class _ScrollView extends React.Component { } } - getSnapshotBeforeUpdate (prevProps: ScrollViewProps, prevState: ScrollViewState) { + getSnapshotBeforeUpdate (prevProps: ScrollViewProps, prevState: ScrollViewState) { return prevState.snapScrollTop !== this.state.snapScrollTop || prevState.snapScrollLeft !== this.state.snapScrollLeft } - componentDidUpdate (prevProps: ScrollViewProps, prevState: ScrollViewState, snapshot: boolean) { + componentDidUpdate (prevProps: ScrollViewProps, prevState: ScrollViewState, snapshot: boolean) { if (snapshot) { this.scrollToOffset(this.state.snapScrollLeft, this.state.snapScrollTop) } @@ -213,6 +221,8 @@ class _ScrollView extends React.Component { scrollX, enableBackToTop, contentContainerStyle, + data, + renderItem, } = this.props const flattenStyle: ViewStyle & { [key: string]: any } = StyleSheet.flatten(style) @@ -226,45 +236,59 @@ class _ScrollView extends React.Component { flattenStyle.justifyContent && (_contentContainerStyle.justifyContent = flattenStyle.justifyContent) } - return ( + const scrollElementProps = { + horizontal: scrollX, + onContentSizeChange: this._onContentSizeChange, + onLayout: this._onLayout, + onScroll: this._onScroll, + onScrollEndDrag: this._onScrollEndDrag, + onMomentumScrollEnd: this._onMomentumScrollEnd, + scrollEventThrottle: this._scrollEventThrottle, + scrollsToTop: !!enableBackToTop, + style: wrapperStyle, + contentContainerStyle: [_contentContainerStyle, contentContainerStyle], + ...omit(this.props, [ + // props + 'style', + 'scrollX', + 'upperThreshold', + 'lowerThreshold', + 'scrollTop', + 'scrollLeft', + 'scrollWithAnimation', + 'enableBackToTop', + 'onScrollToUpper', + 'onScrollToLower', + 'onScroll', + 'contentContainerStyle', + // SProps + 'horizontal', + 'onContentSizeChange', + 'onLayout', + 'onScroll', + 'onScrollEndDrag', + 'onMomentumScrollEnd', + 'scrollEventThrottle', + 'scrollsToTop', + 'style', + 'contentContainerStyle', + 'data', + 'renderItem', + 'keyExtractor', + ]), + ref: this.$scrollView + } + + return data && renderItem ? ( + index + ''} + /> + ) : ( {children} From 773d02e13fe9e5ecdb1b53a9f1a828f9e00c9f65 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 25 Jun 2019 09:57:58 +0800 Subject: [PATCH 053/158] chore(release): publish v1.3.4 --- lerna.json | 2 +- .../package.json | 2 +- .../package.json | 4 ++-- packages/css-to-react-native/package.json | 2 +- packages/eslint-config-taro/package.json | 4 ++-- packages/eslint-plugin-taro/package.json | 2 +- .../postcss-plugin-constparse/package.json | 2 +- packages/postcss-pxtransform/package.json | 2 +- packages/postcss-unit-transform/package.json | 2 +- .../stylelint-config-taro-rn/package.json | 4 ++-- packages/stylelint-taro-rn/package.json | 2 +- packages/taro-alipay/package.json | 6 ++--- packages/taro-async-await/package.json | 2 +- packages/taro-cli/package.json | 22 +++++++++---------- packages/taro-components-qa/package.json | 2 +- packages/taro-components-rn/package.json | 2 +- packages/taro-components/package.json | 6 ++--- packages/taro-h5/package.json | 6 ++--- packages/taro-mobx-common/package.json | 2 +- packages/taro-mobx-h5/package.json | 4 ++-- packages/taro-mobx-rn/package.json | 4 ++-- packages/taro-mobx/package.json | 4 ++-- packages/taro-plugin-babel/package.json | 2 +- packages/taro-plugin-csso/package.json | 2 +- packages/taro-plugin-less/package.json | 2 +- packages/taro-plugin-sass/package.json | 2 +- packages/taro-plugin-stylus/package.json | 2 +- packages/taro-plugin-typescript/package.json | 2 +- packages/taro-plugin-uglifyjs/package.json | 2 +- packages/taro-qq/package.json | 6 ++--- packages/taro-quickapp/package.json | 6 ++--- packages/taro-redux-h5/package.json | 4 ++-- packages/taro-redux-rn/package.json | 2 +- packages/taro-redux/package.json | 6 ++--- packages/taro-rn-runner/package.json | 2 +- packages/taro-rn/package.json | 4 ++-- packages/taro-router-rn/package.json | 2 +- packages/taro-router/package.json | 4 ++-- packages/taro-swan/package.json | 6 ++--- packages/taro-transformer-wx/package.json | 6 ++--- packages/taro-tt/package.json | 6 ++--- packages/taro-utils/package.json | 2 +- packages/taro-weapp/package.json | 6 ++--- packages/taro-webpack-runner/package.json | 10 ++++----- packages/taro-with-weapp/package.json | 4 ++-- packages/taro/package.json | 2 +- packages/taroize/package.json | 2 +- 47 files changed, 91 insertions(+), 91 deletions(-) diff --git a/lerna.json b/lerna.json index 0ad3d28cf208..19d19fd59e4c 100644 --- a/lerna.json +++ b/lerna.json @@ -53,6 +53,6 @@ "message": "chore(release): publish %s" } }, - "version": "1.3.3", + "version": "1.3.4", "npmClient": "npm" } diff --git a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json index 114c100cd349..9e6d8bb6a65d 100644 --- a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json +++ b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-jsx-to-stylesheet", - "version": "1.3.3", + "version": "1.3.4", "description": "Transform stylesheet selector to style in JSX Elements.", "license": "MIT", "main": "src/index.js", diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json index 98bf238602c1..96035495d5aa 100644 --- a/packages/babel-plugin-transform-taroapi/package.json +++ b/packages/babel-plugin-transform-taroapi/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-taroapi", - "version": "1.3.3", + "version": "1.3.4", "main": "dist/index.js", "license": "MIT", "scripts": { @@ -10,7 +10,7 @@ "test": "jest" }, "devDependencies": { - "@tarojs/taro-h5": "1.3.3", + "@tarojs/taro-h5": "1.3.4", "@types/babel-core": "^6.25.5", "@types/babel-traverse": "^6.25.4", "@types/babel-types": "^7.0.4", diff --git a/packages/css-to-react-native/package.json b/packages/css-to-react-native/package.json index a7a5fc681495..5c77ab5a88fe 100644 --- a/packages/css-to-react-native/package.json +++ b/packages/css-to-react-native/package.json @@ -1,7 +1,7 @@ { "name": "taro-css-to-react-native", "description": "Convert CSS text to a React Native stylesheet object", - "version": "1.3.3", + "version": "1.3.4", "main": "dist/index.js", "license": "MIT", "scripts": { diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json index a70a4a276d13..c752cf95c079 100644 --- a/packages/eslint-config-taro/package.json +++ b/packages/eslint-config-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-taro", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro specific linting rules for ESLint", "main": "index.js", "files": [ @@ -27,6 +27,6 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "eslint-plugin-taro": "1.3.3" + "eslint-plugin-taro": "1.3.4" } } diff --git a/packages/eslint-plugin-taro/package.json b/packages/eslint-plugin-taro/package.json index f0f4b846c05d..b7210438a967 100644 --- a/packages/eslint-plugin-taro/package.json +++ b/packages/eslint-plugin-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-taro", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro specific linting plugin for ESLint", "main": "index.js", "files": [ diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json index 6cacdd414789..683eec2f2d30 100644 --- a/packages/postcss-plugin-constparse/package.json +++ b/packages/postcss-plugin-constparse/package.json @@ -1,6 +1,6 @@ { "name": "postcss-plugin-constparse", - "version": "1.3.3", + "version": "1.3.4", "description": "parse constants defined in config", "main": "index.js", "author": "Simba", diff --git a/packages/postcss-pxtransform/package.json b/packages/postcss-pxtransform/package.json index 3c0869d54d60..dc35d9e5d1cd 100644 --- a/packages/postcss-pxtransform/package.json +++ b/packages/postcss-pxtransform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-pxtransform", - "version": "1.3.3", + "version": "1.3.4", "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位", "keywords": [ "postcss", diff --git a/packages/postcss-unit-transform/package.json b/packages/postcss-unit-transform/package.json index 6db67df4672c..151f249748f6 100644 --- a/packages/postcss-unit-transform/package.json +++ b/packages/postcss-unit-transform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-taro-unit-transform", - "version": "1.3.3", + "version": "1.3.4", "description": "小程序单位转换", "main": "index.js", "scripts": { diff --git a/packages/stylelint-config-taro-rn/package.json b/packages/stylelint-config-taro-rn/package.json index f51c0f5d01a5..bc89f982eb69 100644 --- a/packages/stylelint-config-taro-rn/package.json +++ b/packages/stylelint-config-taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-config-taro-rn", - "version": "1.3.3", + "version": "1.3.4", "description": "Shareable stylelint config for React Native CSS modules", "main": "index.js", "files": [ @@ -28,6 +28,6 @@ "jest": "^23.6.0", "npmpub": "^4.1.0", "stylelint": "9.3.0", - "stylelint-taro-rn": "1.3.3" + "stylelint-taro-rn": "1.3.4" } } diff --git a/packages/stylelint-taro-rn/package.json b/packages/stylelint-taro-rn/package.json index a34f3554cd61..4c030e3c4b50 100644 --- a/packages/stylelint-taro-rn/package.json +++ b/packages/stylelint-taro-rn/package.json @@ -1,7 +1,7 @@ { "name": "stylelint-taro-rn", "description": "A collection of React Native specific rules for stylelint", - "version": "1.3.3", + "version": "1.3.4", "main": "dist/index.js", "babel": { "presets": [ diff --git a/packages/taro-alipay/package.json b/packages/taro-alipay/package.json index c636e75c5169..0d107d3ba7ee 100644 --- a/packages/taro-alipay/package.json +++ b/packages/taro-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-alipay", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro alipay framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.3", - "@tarojs/utils": "1.3.3", + "@tarojs/taro": "1.3.4", + "@tarojs/utils": "1.3.4", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-async-await/package.json b/packages/taro-async-await/package.json index 80b1dd12655c..0b4b09510a06 100644 --- a/packages/taro-async-await/package.json +++ b/packages/taro-async-await/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/async-await", - "version": "1.3.3", + "version": "1.3.4", "description": "taro async await", "main": "index.js", "scripts": { diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json index a3a1494d8f0d..9f7543d72eb9 100644 --- a/packages/taro-cli/package.json +++ b/packages/taro-cli/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/cli", - "version": "1.3.3", + "version": "1.3.4", "description": "cli tool for taro", "main": "index.js", "scripts": { @@ -30,8 +30,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taroize": "1.3.3", - "@tarojs/transformer-wx": "1.3.3", + "@tarojs/taroize": "1.3.4", + "@tarojs/transformer-wx": "1.3.4", "@types/request": "^2.48.1", "autoprefixer": "^8.4.1", "babel-core": "^6.26.3", @@ -41,7 +41,7 @@ "babel-plugin-remove-dead-code": "^1.3.2", "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-define": "^1.3.0", - "babel-plugin-transform-jsx-to-stylesheet": "1.3.3", + "babel-plugin-transform-jsx-to-stylesheet": "1.3.4", "babel-plugin-transform-react-jsx": "^6.24.1", "babel-template": "^6.26.0", "babel-traverse": "^6.26.0", @@ -56,10 +56,10 @@ "ejs": "^2.6.1", "envinfo": "^6.0.1", "eslint": "^4.15.0", - "eslint-config-taro": "1.3.3", + "eslint-config-taro": "1.3.4", "eslint-plugin-import": "^2.8.0", "eslint-plugin-react": "^7.4.0", - "eslint-plugin-taro": "1.3.3", + "eslint-plugin-taro": "1.3.4", "eslint-plugin-typescript": "^0.12.0", "fbjs": "^1.0.0", "fs-extra": "^5.0.0", @@ -81,7 +81,7 @@ "postcss-modules-resolve-imports": "^1.3.0", "postcss-modules-scope": "^1.1.0", "postcss-modules-values": "^1.3.0", - "postcss-pxtransform": "1.3.3", + "postcss-pxtransform": "1.3.4", "postcss-reporter": "^6.0.1", "postcss-taro-unit-transform": "1.2.15", "postcss-url": "^7.3.2", @@ -92,16 +92,16 @@ "semver": "^5.5.0", "shelljs": "^0.8.1", "stylelint": "9.3.0", - "stylelint-config-taro-rn": "1.3.3", - "stylelint-taro-rn": "1.3.3", - "taro-css-to-react-native": "1.3.3", + "stylelint-config-taro-rn": "1.3.4", + "stylelint-taro-rn": "1.3.4", + "taro-css-to-react-native": "1.3.4", "through2": "^2.0.3", "vinyl": "^2.1.0", "vinyl-fs": "^3.0.2", "yauzl": "2.10.0" }, "devDependencies": { - "@tarojs/taro": "1.3.3", + "@tarojs/taro": "1.3.4", "@types/autoprefixer": "^9.1.1", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.2", diff --git a/packages/taro-components-qa/package.json b/packages/taro-components-qa/package.json index c1df1ea897b5..0a46bb175897 100644 --- a/packages/taro-components-qa/package.json +++ b/packages/taro-components-qa/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-qa", - "version": "1.3.3", + "version": "1.3.4", "description": "多端解决方案基础组件(快应用)", "main": "./index.js", "files": [ diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index ec87ca724fba..ccbabe47d1cb 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-rn", - "version": "1.3.3", + "version": "1.3.4", "description": "多端解决方案基础组件(RN)", "main": "./dist/index.js", "scripts": { diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json index 412f08492791..74ecb4a77b68 100644 --- a/packages/taro-components/package.json +++ b/packages/taro-components/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components", - "version": "1.3.3", + "version": "1.3.4", "description": "", "main:h5": "src/index.js", "main": "dist/index.js", @@ -49,14 +49,14 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0", "@babel/plugin-transform-react-jsx": "^7.0.0", "@babel/preset-env": "^7.1.5", - "@tarojs/taro-h5": "1.3.3", + "@tarojs/taro-h5": "1.3.4", "@types/react": "^16.4.6", "@types/urijs": "^1.15.38", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "10.0.1", "babel-jest": "^22.4.4", "babel-loader": "^8.0.5", - "babel-plugin-transform-taroapi": "1.3.3", + "babel-plugin-transform-taroapi": "1.3.4", "css-loader": "^2.1.1", "file-loader": "^3.0.1", "jest": "^22.4.4", diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json index 8ba6afa31fdc..66fcd69041f4 100644 --- a/packages/taro-h5/package.json +++ b/packages/taro-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-h5", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro h5 framework", "main:h5": "src/index.js", "main": "dist/index.js", @@ -43,8 +43,8 @@ "@babel/plugin-proposal-object-rest-spread": "^7.3.4", "@babel/plugin-transform-react-jsx": "^7.2.2", "@babel/preset-env": "^7.3.4", - "@tarojs/components": "1.3.3", - "@tarojs/taro": "1.3.3", + "@tarojs/components": "1.3.4", + "@tarojs/taro": "1.3.4", "babel-core": "7.0.0-bridge.0", "babel-jest": "24.4.0", "eslint": "^4.18.2", diff --git a/packages/taro-mobx-common/package.json b/packages/taro-mobx-common/package.json index 1f8d5ba62434..4fa76321bf03 100644 --- a/packages/taro-mobx-common/package.json +++ b/packages/taro-mobx-common/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-common", - "version": "1.3.3", + "version": "1.3.4", "description": "mobx library for taro", "keywords": [ "mobx", diff --git a/packages/taro-mobx-h5/package.json b/packages/taro-mobx-h5/package.json index b473bf97522f..dea3f4d5684d 100644 --- a/packages/taro-mobx-h5/package.json +++ b/packages/taro-mobx-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-h5", - "version": "1.3.3", + "version": "1.3.4", "description": "mobx-h5 for taro", "keywords": [ "mobx", @@ -29,7 +29,7 @@ "nervjs": "^1.4.0" }, "dependencies": { - "@tarojs/mobx-common": "1.3.3" + "@tarojs/mobx-common": "1.3.4" }, "devDependencies": { "rimraf": "^2.6.2", diff --git a/packages/taro-mobx-rn/package.json b/packages/taro-mobx-rn/package.json index 19fe8b63a10f..e5fc0be94cc7 100644 --- a/packages/taro-mobx-rn/package.json +++ b/packages/taro-mobx-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-rn", - "version": "1.3.3", + "version": "1.3.4", "description": "mobx-rn for taro", "keywords": [ "mobx", @@ -18,7 +18,7 @@ "src" ], "dependencies": { - "@tarojs/mobx-common": "1.3.3", + "@tarojs/mobx-common": "1.3.4", "@tarojs/taro-rn": "1.1.7" } } diff --git a/packages/taro-mobx/package.json b/packages/taro-mobx/package.json index a440da0a9d2d..fbe1b335ecf9 100644 --- a/packages/taro-mobx/package.json +++ b/packages/taro-mobx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx", - "version": "1.3.3", + "version": "1.3.4", "description": "mobx for taro", "keywords": [ "mobx", @@ -22,7 +22,7 @@ "clear": "rimraf dist" }, "dependencies": { - "@tarojs/mobx-common": "1.3.3" + "@tarojs/mobx-common": "1.3.4" }, "peerDependencies": { "mobx": "4.8.0" diff --git a/packages/taro-plugin-babel/package.json b/packages/taro-plugin-babel/package.json index b92d656f5472..b0ef4873c2c7 100644 --- a/packages/taro-plugin-babel/package.json +++ b/packages/taro-plugin-babel/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-babel", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro babel编译", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-csso/package.json b/packages/taro-plugin-csso/package.json index 62d0aca5822c..04f0b5c2b04d 100644 --- a/packages/taro-plugin-csso/package.json +++ b/packages/taro-plugin-csso/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-csso", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro压缩CSS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-less/package.json b/packages/taro-plugin-less/package.json index 76f239c3432f..27399c328efa 100644 --- a/packages/taro-plugin-less/package.json +++ b/packages/taro-plugin-less/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-less", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro 编译 less 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-sass/package.json b/packages/taro-plugin-sass/package.json index ba1969587162..de7bf55a34c5 100644 --- a/packages/taro-plugin-sass/package.json +++ b/packages/taro-plugin-sass/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-sass", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro编译sass文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-stylus/package.json b/packages/taro-plugin-stylus/package.json index 3b271150b70d..6d67052e6313 100644 --- a/packages/taro-plugin-stylus/package.json +++ b/packages/taro-plugin-stylus/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-stylus", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro 编译 stylus 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-typescript/package.json b/packages/taro-plugin-typescript/package.json index dac4496f8bb1..e4d1b581acc1 100644 --- a/packages/taro-plugin-typescript/package.json +++ b/packages/taro-plugin-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-typescript", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro TypeScript 编译插件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-uglifyjs/package.json b/packages/taro-plugin-uglifyjs/package.json index d9b208f0de87..a0ec5e75f2c4 100644 --- a/packages/taro-plugin-uglifyjs/package.json +++ b/packages/taro-plugin-uglifyjs/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-uglifyjs", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro压缩JS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-qq/package.json b/packages/taro-qq/package.json index 83cd4a6b26f2..b40eaacb9d2a 100644 --- a/packages/taro-qq/package.json +++ b/packages/taro-qq/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-qq", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro qq framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.3", - "@tarojs/utils": "1.3.3", + "@tarojs/taro": "1.3.4", + "@tarojs/utils": "1.3.4", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-quickapp/package.json b/packages/taro-quickapp/package.json index 69d1fff12e88..8ce2fcdf4c2b 100644 --- a/packages/taro-quickapp/package.json +++ b/packages/taro-quickapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-quickapp", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro quickapp framework", "main": "index.js", "files": [ @@ -23,8 +23,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.3", - "@tarojs/utils": "1.3.3", + "@tarojs/taro": "1.3.4", + "@tarojs/utils": "1.3.4", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-redux-h5/package.json b/packages/taro-redux-h5/package.json index 17e53f1a512d..0306b16cc49c 100644 --- a/packages/taro-redux-h5/package.json +++ b/packages/taro-redux-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux-h5", - "version": "1.3.3", + "version": "1.3.4", "description": "Forked react-redux for taro", "keywords": [ "react", @@ -46,7 +46,7 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.49", "@babel/plugin-transform-react-jsx": "^7.0.0-beta.49", "@babel/preset-env": "^7.0.0-beta.49", - "@tarojs/taro-h5": "1.3.3", + "@tarojs/taro-h5": "1.3.4", "babel-plugin-transform-react-remove-prop-types": "^0.4.13", "redux": "^4.0.0", "rimraf": "^2.6.2", diff --git a/packages/taro-redux-rn/package.json b/packages/taro-redux-rn/package.json index a0ca45348f02..028d00369417 100644 --- a/packages/taro-redux-rn/package.json +++ b/packages/taro-redux-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-redux-rn", - "version": "1.3.3", + "version": "1.3.4", "description": "taro-redux-rn", "main": "./src/index.js", "files": [ diff --git a/packages/taro-redux/package.json b/packages/taro-redux/package.json index e5a52e4aa494..6b84798f3007 100644 --- a/packages/taro-redux/package.json +++ b/packages/taro-redux/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux", - "version": "1.3.3", + "version": "1.3.4", "description": "Redux for Taro", "main": "index.js", "typings": "types/index.d.ts", @@ -31,7 +31,7 @@ "jest": "^23.1.0" }, "dependencies": { - "@tarojs/taro": "1.3.3", - "@tarojs/utils": "1.3.3" + "@tarojs/taro": "1.3.4", + "@tarojs/utils": "1.3.4" } } diff --git a/packages/taro-rn-runner/package.json b/packages/taro-rn-runner/package.json index 68f67579acf4..8c9f056f28c3 100644 --- a/packages/taro-rn-runner/package.json +++ b/packages/taro-rn-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-runner", - "version": "1.3.3", + "version": "1.3.4", "description": "ReactNative build tool for taro", "main": "index.js", "scripts": { diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json index 99c956e99a64..befab22a426e 100644 --- a/packages/taro-rn/package.json +++ b/packages/taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-rn", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro RN framework", "main": "./index.js", "files": [ @@ -27,7 +27,7 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.3", + "@tarojs/taro": "1.3.4", "base64-js": "^1.3.0", "react-native-image-crop-picker": "^0.23.1", "react-native-image-zoom-viewer": "^2.2.13", diff --git a/packages/taro-router-rn/package.json b/packages/taro-router-rn/package.json index 26aa2768507b..1b68c7ccb6d9 100644 --- a/packages/taro-router-rn/package.json +++ b/packages/taro-router-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-router-rn", - "version": "1.3.3", + "version": "1.3.4", "description": "taro-router-rn", "main": "./index.js", "files": [ diff --git a/packages/taro-router/package.json b/packages/taro-router/package.json index 28f090f05895..fe30b1342212 100644 --- a/packages/taro-router/package.json +++ b/packages/taro-router/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/router", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro-router", "main:h5": "dist/index.esm.js", "main": "index.js", @@ -41,7 +41,7 @@ "@babel/plugin-syntax-dynamic-import": "7.0.0", "@babel/plugin-transform-react-jsx": "7.0.0", "@babel/preset-env": "7.1.5", - "@tarojs/taro-h5": "1.3.3", + "@tarojs/taro-h5": "1.3.4", "@types/history": "4.7.2", "@types/jasmine": "2.8.11", "@types/jest": "23.3.9", diff --git a/packages/taro-swan/package.json b/packages/taro-swan/package.json index 1d774f14c2d2..7f56a4c0edef 100644 --- a/packages/taro-swan/package.json +++ b/packages/taro-swan/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-swan", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro swan framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.3", - "@tarojs/utils": "1.3.3", + "@tarojs/taro": "1.3.4", + "@tarojs/utils": "1.3.4", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-transformer-wx/package.json b/packages/taro-transformer-wx/package.json index 3e192daffbd0..c3020ac5f7ff 100644 --- a/packages/taro-transformer-wx/package.json +++ b/packages/taro-transformer-wx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/transformer-wx", - "version": "1.3.3", + "version": "1.3.4", "description": "Transfrom Nerv Component to Wechat mini program.", "repository": { "type": "git", @@ -62,14 +62,14 @@ "babel-types": "^6.26.0", "eslint": "^4.15.0", "eslint-plugin-react": "7.10.0", - "eslint-plugin-taro": "1.3.3", + "eslint-plugin-taro": "1.3.4", "html": "^1.0.0", "lodash": "^4.17.5", "prettier": "^1.14.2", "typescript": "^3.2.2" }, "devDependencies": { - "@tarojs/taro": "1.3.3", + "@tarojs/taro": "1.3.4", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.1", "@types/babel-template": "^6.25.0", diff --git a/packages/taro-tt/package.json b/packages/taro-tt/package.json index 7b49dfcc5708..4028947ab2a4 100644 --- a/packages/taro-tt/package.json +++ b/packages/taro-tt/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-tt", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro toutiao framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.3", - "@tarojs/utils": "1.3.3", + "@tarojs/taro": "1.3.4", + "@tarojs/utils": "1.3.4", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-utils/package.json b/packages/taro-utils/package.json index 87efd1df0a63..9b83fc854ffe 100644 --- a/packages/taro-utils/package.json +++ b/packages/taro-utils/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/utils", - "version": "1.3.3", + "version": "1.3.4", "description": "Utils for Taro", "main": "index.js", "scripts": { diff --git a/packages/taro-weapp/package.json b/packages/taro-weapp/package.json index f9db13f9b52b..a751b96997f4 100644 --- a/packages/taro-weapp/package.json +++ b/packages/taro-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-weapp", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro weapp framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.3", - "@tarojs/utils": "1.3.3", + "@tarojs/taro": "1.3.4", + "@tarojs/utils": "1.3.4", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json index 01c177a638ee..e767f6a5bc99 100644 --- a/packages/taro-webpack-runner/package.json +++ b/packages/taro-webpack-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/webpack-runner", - "version": "1.3.3", + "version": "1.3.4", "description": "webpack runner for taro", "main": "index.js", "scripts": { @@ -32,13 +32,13 @@ }, "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { - "@tarojs/taro-h5": "1.3.3", + "@tarojs/taro-h5": "1.3.4", "autoprefixer": "8.6.4", "babel-core": "6.26.0", "babel-loader": "7.1.4", "babel-plugin-syntax-dynamic-import": "6.18.0", "babel-plugin-transform-react-jsx": "6.24.1", - "babel-plugin-transform-taroapi": "1.3.3", + "babel-plugin-transform-taroapi": "1.3.4", "babel-types": "6.26.0", "chalk": "2.4.2", "copy-webpack-plugin": "^5.0.3", @@ -55,8 +55,8 @@ "opn": "5.3.0", "ora": "2.1.0", "postcss-loader": "2.1.6", - "postcss-plugin-constparse": "1.3.3", - "postcss-pxtransform": "1.3.3", + "postcss-plugin-constparse": "1.3.4", + "postcss-pxtransform": "1.3.4", "resolve": "1.8.1", "resolve-url-loader": "2.3.0", "sass-loader": "7.1.0", diff --git a/packages/taro-with-weapp/package.json b/packages/taro-with-weapp/package.json index 8aa9d298e0a1..799758473461 100644 --- a/packages/taro-with-weapp/package.json +++ b/packages/taro-with-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/with-weapp", - "version": "1.3.3", + "version": "1.3.4", "description": "taroize 之后的运行时", "main": "index.js", "scripts": { @@ -22,7 +22,7 @@ "author": "yuche", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.3", + "@tarojs/taro": "1.3.4", "lodash": "^4.17.11" }, "devDependencies": { diff --git a/packages/taro/package.json b/packages/taro/package.json index b4eafeaaaf3b..5a0aad75b235 100644 --- a/packages/taro/package.json +++ b/packages/taro/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro", - "version": "1.3.3", + "version": "1.3.4", "description": "Taro framework", "module": "dist/index.esm.js", "main": "index.js", diff --git a/packages/taroize/package.json b/packages/taroize/package.json index 6a3a70136758..b092355c2ea6 100644 --- a/packages/taroize/package.json +++ b/packages/taroize/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taroize", - "version": "1.3.3", + "version": "1.3.4", "description": "转换原生微信小程序代码为 Taro 代码", "main": "index.js", "files": [ From 16fed3627f8e39da6a25887963133efef209aca3 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 25 Jun 2019 10:22:08 +0800 Subject: [PATCH 054/158] chore: changelog --- CHANGELOG.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3254642c3b74..a0579b4165e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ -# [](https://github.com/NervJS/taro/compare/v1.3.3...v) (2019-06-24) +# [](https://github.com/NervJS/taro/compare/v1.3.4...v) (2019-06-25) + + + + +## [1.3.4](https://github.com/NervJS/taro/compare/v1.3.3...v1.3.4) (2019-06-25) + + +### Bug Fixes + +* **transformer:** 在 hooks 会把 return 替换,close [#3469](https://github.com/NervJS/taro/issues/3469) ([beb21f0](https://github.com/NervJS/taro/commit/beb21f0)) +* **transformer:** 嵌套循环判断使用上级变量编译错误,close [#3462](https://github.com/NervJS/taro/issues/3462) ([6b525c2](https://github.com/NervJS/taro/commit/6b525c2)) +* **transformer:** 自定义组件支持外部类,close [#3080](https://github.com/NervJS/taro/issues/3080) ([96573c1](https://github.com/NervJS/taro/commit/96573c1)) +* **weapp:** 修复 extraProps 判断 bug。 ([3288436](https://github.com/NervJS/taro/commit/3288436)) +* **weapp:** 修复 mobx 下 extraProps 判断 bug。close [#3513](https://github.com/NervJS/taro/issues/3513) ([3deb1a7](https://github.com/NervJS/taro/commit/3deb1a7)) + + +### Features + +* **components-rn:** ScrollView, 支持 FlatList 来代替 ScrollView ([6714e24](https://github.com/NervJS/taro/commit/6714e24)) +* **transformer:** 支持在快应用循环中使用匿名函数,[#3495](https://github.com/NervJS/taro/issues/3495) ([0a66dbd](https://github.com/NervJS/taro/commit/0a66dbd)) +* **transformer:** 循环中可以直接 return JSX 引用,close [#3504](https://github.com/NervJS/taro/issues/3504) ([38a38ce](https://github.com/NervJS/taro/commit/38a38ce)) From 8ae96c2e43b69d3821c8641c9dd68c49cc54f3d0 Mon Sep 17 00:00:00 2001 From: onelong Date: Tue, 25 Jun 2019 10:22:54 +0800 Subject: [PATCH 055/158] =?UTF-8?q?fix(docs):=20=E6=A1=88=E4=BE=8B?= =?UTF-8?q?=E4=B8=AD=E7=9A=84taro-redux=E5=BC=95=E7=94=A8=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E9=94=99=E8=AF=AF=20(#3522)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/redux.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/redux.md b/docs/redux.md index b41f44057f78..7ca24634f7ca 100644 --- a/docs/redux.md +++ b/docs/redux.md @@ -251,7 +251,7 @@ Selector 函数大致相当于 `connect` 函数的 `mapStateToProps` 参数。Se ```jsx import Taro, { Components } from '@tarojs/taro' -import { useSelector } from 'taro-redux' +import { useSelector } from '@tarojs/redux' export const CounterComponent = () => { const counter = useSelector(state => state.counter) @@ -272,8 +272,8 @@ export const TodoListItem = props => { #### 进阶使用 你还可以访问 [react-redux 文档](https://react-redux.js.org/api/hooks#using-memoizing-selectors) 了解如何使用 `reselect` 缓存 selector。 - - + + ### `useDispatch` ```javascript @@ -286,7 +286,7 @@ const dispatch = useDispatch() ```jsx import Taro, { Components } from '@tarojs/taro' -import { useDispatch } from 'taro-redux' +import { useDispatch } from '@tarojs/redux' export const CounterComponent = ({ value }) => { const dispatch = useDispatch() @@ -343,7 +343,7 @@ const store = useStore() ```jsx import Taro, { Components } from '@tarojs/taro' -import { useStore } from 'taro-redux' +import { useStore } from '@tarojs/redux' export const CounterComponent = ({ value }) => { const store = useStore() From 7c8edd2d219c8e9a97cdc6778c0fd44d4a716f85 Mon Sep 17 00:00:00 2001 From: onelong Date: Tue, 25 Jun 2019 10:23:33 +0800 Subject: [PATCH 056/158] feat(typings): add the type definition of FunctionComponent and Taro.memo (#3517) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(types): add the type definition of FunctionComponent and Taro.memo * fix(typings): 遗漏了Taro.memo的泛型 * fix: 遗漏了Taro.memo中compare函数的参数类型定义 --- packages/taro/types/index.d.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts index faadbe57a250..b86cb85ab1c6 100644 --- a/packages/taro/types/index.d.ts +++ b/packages/taro/types/index.d.ts @@ -353,6 +353,10 @@ declare namespace Taro { $scope?: any } + interface FunctionComponent

{ + (props: Readonly

): JSX.Element + } + interface ComponentClass

extends StaticLifecycle { new (...args: any[]): Component propTypes?: any @@ -729,6 +733,11 @@ declare namespace Taro { class PureComponent

extends Component {} + function memo

( + FunctionComponent: FunctionComponent

, + compare?: (oldProps: P, newProps: P) => Boolean + ): FunctionComponent

+ // Events class Events { /** From 975084fa06de7edc2806e904e991e1f791954d4e Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Tue, 25 Jun 2019 14:15:03 +0800 Subject: [PATCH 057/158] =?UTF-8?q?fix(taro-weapp/qq/tt/swan/alipay):=20?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=20ref=20=E9=97=AE=E9=A2=98=E3=80=82close=20#?= =?UTF-8?q?3455?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-alipay/src/lifecycle.js | 16 +++++++++------- packages/taro-qq/src/create-component.js | 7 +++++++ packages/taro-qq/src/lifecycle.js | 6 +++--- packages/taro-swan/src/create-component.js | 9 ++++++++- packages/taro-swan/src/lifecycle.js | 6 +++--- packages/taro-tt/src/create-component.js | 7 +++++++ packages/taro-tt/src/lifecycle.js | 6 +++--- packages/taro-weapp/src/create-component.js | 2 ++ packages/taro-weapp/src/lifecycle.js | 2 ++ packages/taro/src/hooks.js | 2 +- 10 files changed, 45 insertions(+), 18 deletions(-) diff --git a/packages/taro-alipay/src/lifecycle.js b/packages/taro-alipay/src/lifecycle.js index 75db099356d0..3a03dab991ce 100644 --- a/packages/taro-alipay/src/lifecycle.js +++ b/packages/taro-alipay/src/lifecycle.js @@ -139,15 +139,13 @@ function doUpdate (component, prevProps, prevState) { const { state, props = {} } = component let data = state || {} if (component._createData) { - // 返回null或undefined则保持不变 - const isRunLoopRef = !component.__mounted if (component.__isReady) { injectContextType(component) Current.current = component Current.index = 0 invokeEffects(component, true) } - data = component._createData(state, props, isRunLoopRef) || data + data = component._createData(state, props) || data if (component.__isReady) { Current.current = null } @@ -206,19 +204,23 @@ function doUpdate (component, prevProps, prevState) { } if (component['$$hasLoopRef']) { + Current.current = component component._disableEffect = true component._createData(component.state, component.props, true) component._disableEffect = false + Current.current = null } if (typeof component.componentDidUpdate === 'function') { component.componentDidUpdate(prevProps, prevState, snapshot) } - } - - // 解决初始化时 onLoad 最先触发,但拿不到子组件 ref 的问题 - if (component.$componentType === 'PAGE' && component['$$hasLoopRef']) { + } else if (component.$componentType === 'PAGE' && component['$$hasLoopRef']) { + // 解决初始化时 onLoad 最先触发,但拿不到子组件 ref 的问题 + Current.current = component + component._disableEffect = true component._createData(component.state, component.props, true) + component._disableEffect = false + Current.current = null } if (cbs.length) { diff --git a/packages/taro-qq/src/create-component.js b/packages/taro-qq/src/create-component.js index fb43aa53a21e..269c12b7d268 100644 --- a/packages/taro-qq/src/create-component.js +++ b/packages/taro-qq/src/create-component.js @@ -213,6 +213,13 @@ export function componentTrigger (component, key, args) { }) component.refs = Object.assign({}, component.refs || {}, refs) } + if (component['$$hasLoopRef']) { + Current.current = component + component._disableEffect = true + component._createData(component.state, component.props, true) + component._disableEffect = false + Current.current = null + } } if (key === 'componentWillUnmount') { diff --git a/packages/taro-qq/src/lifecycle.js b/packages/taro-qq/src/lifecycle.js index d0c46dd44253..70e5236d6255 100644 --- a/packages/taro-qq/src/lifecycle.js +++ b/packages/taro-qq/src/lifecycle.js @@ -139,15 +139,13 @@ function doUpdate (component, prevProps, prevState) { const { state, props = {} } = component let data = state || {} if (component._createData) { - // 返回null或undefined则保持不变 - const runLoopRef = !component.__mounted if (component.__isReady) { injectContextType(component) Current.current = component Current.index = 0 invokeEffects(component, true) } - data = component._createData(state, props, runLoopRef) || data + data = component._createData(state, props) || data if (component.__isReady) { Current.current = null } @@ -209,9 +207,11 @@ function doUpdate (component, prevProps, prevState) { } if (component['$$hasLoopRef']) { + Current.current = component component._disableEffect = true component._createData(component.state, component.props, true) component._disableEffect = false + Current.current = null } if (typeof component.componentDidUpdate === 'function') { diff --git a/packages/taro-swan/src/create-component.js b/packages/taro-swan/src/create-component.js index 1394e451eeb3..992e2762d05b 100644 --- a/packages/taro-swan/src/create-component.js +++ b/packages/taro-swan/src/create-component.js @@ -258,7 +258,7 @@ function createComponent (ComponentClass, isPage) { const query = swan.createSelectorQuery().in(this) if (ref.type === 'component') { target = this.selectComponent(`#${ref.id}`) - target = target.$component || target + target = (target && target.$component) || target } else { target = query.select(`#${ref.id}`) } @@ -267,6 +267,13 @@ function createComponent (ComponentClass, isPage) { }) component.refs = Object.assign({}, component.refs || {}, refs) } + if (component['$$hasLoopRef']) { + Current.current = component + component._disableEffect = true + component._createData(component.state, component.props, true) + component._disableEffect = false + Current.current = null + } if (!component.__mounted) { component.__mounted = true componentTrigger(component, 'componentDidMount') diff --git a/packages/taro-swan/src/lifecycle.js b/packages/taro-swan/src/lifecycle.js index 3d188368a522..653f6c84b3e1 100644 --- a/packages/taro-swan/src/lifecycle.js +++ b/packages/taro-swan/src/lifecycle.js @@ -139,15 +139,13 @@ function doUpdate (component, prevProps, prevState) { const { state, props = {} } = component let data = state || {} if (component._createData) { - // 返回null或undefined则保持不变 - const isRunLoopRef = !component.__mounted if (component.__isReady) { injectContextType(component) Current.current = component Current.index = 0 invokeEffects(component, true) } - data = component._createData(state, props, isRunLoopRef) || data + data = component._createData(state, props) || data if (component.__isReady) { Current.current = null } @@ -208,9 +206,11 @@ function doUpdate (component, prevProps, prevState) { } if (component['$$hasLoopRef']) { + Current.current = component component._disableEffect = true component._createData(component.state, component.props, true) component._disableEffect = false + Current.current = null } if (typeof component.componentDidUpdate === 'function') { diff --git a/packages/taro-tt/src/create-component.js b/packages/taro-tt/src/create-component.js index a04bcd535c8e..8cbc44ee690a 100644 --- a/packages/taro-tt/src/create-component.js +++ b/packages/taro-tt/src/create-component.js @@ -300,6 +300,13 @@ function createComponent (ComponentClass, isPage) { }) .catch(err => console.error(err)) } + if (component['$$hasLoopRef']) { + Current.current = component + component._disableEffect = true + component._createData(component.state, component.props, true) + component._disableEffect = false + Current.current = null + } }, 0) }, detached () { diff --git a/packages/taro-tt/src/lifecycle.js b/packages/taro-tt/src/lifecycle.js index 76c250e9c16c..a1f519bec331 100644 --- a/packages/taro-tt/src/lifecycle.js +++ b/packages/taro-tt/src/lifecycle.js @@ -139,15 +139,13 @@ function doUpdate (component, prevProps, prevState) { const { state, props = {} } = component let data = state || {} if (component._createData) { - // 返回null或undefined则保持不变 - const isRunLoopRef = !component.__mounted if (component.__isReady) { injectContextType(component) Current.current = component Current.index = 0 invokeEffects(component, true) } - data = component._createData(state, props, isRunLoopRef) || data + data = component._createData(state, props) || data if (component.__isReady) { Current.current = null } @@ -209,9 +207,11 @@ function doUpdate (component, prevProps, prevState) { } if (component['$$hasLoopRef']) { + Current.current = component component._disableEffect = true component._createData(component.state, component.props, true) component._disableEffect = false + Current.current = null } if (typeof component.componentDidUpdate === 'function') { diff --git a/packages/taro-weapp/src/create-component.js b/packages/taro-weapp/src/create-component.js index 48d0c01861aa..e05a96197ae6 100644 --- a/packages/taro-weapp/src/create-component.js +++ b/packages/taro-weapp/src/create-component.js @@ -214,9 +214,11 @@ export function componentTrigger (component, key, args) { component.refs = Object.assign({}, component.refs || {}, refs) } if (component['$$hasLoopRef']) { + Current.current = component component._disableEffect = true component._createData(component.state, component.props, true) component._disableEffect = false + Current.current = null } } diff --git a/packages/taro-weapp/src/lifecycle.js b/packages/taro-weapp/src/lifecycle.js index a65044eeb9a6..31e8663d5917 100644 --- a/packages/taro-weapp/src/lifecycle.js +++ b/packages/taro-weapp/src/lifecycle.js @@ -207,9 +207,11 @@ function doUpdate (component, prevProps, prevState) { } if (component['$$hasLoopRef']) { + Current.current = component component._disableEffect = true component._createData(component.state, component.props, true) component._disableEffect = false + Current.current = null } if (isFunction(component.componentDidUpdate)) { component.componentDidUpdate(prevProps, prevState, snapshot) diff --git a/packages/taro/src/hooks.js b/packages/taro/src/hooks.js index 9cea214eb67d..a2cd7b035a2e 100644 --- a/packages/taro/src/hooks.js +++ b/packages/taro/src/hooks.js @@ -102,7 +102,7 @@ function invokeScheduleEffects (component) { function useEffectImpl (effect, deps, delay) { const hook = getHooks(Current.index++) - if (Current.current._disableHooks || !Current.current.__isReady) { + if (Current.current._disableEffect || !Current.current.__isReady) { return } if (areDepsChanged(hook.deps, deps)) { From b6d1d45c732398ea90e16b0c08910087c382a773 Mon Sep 17 00:00:00 2001 From: yuche Date: Tue, 25 Jun 2019 15:21:25 +0800 Subject: [PATCH 058/158] =?UTF-8?q?feat(transformer):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20children=20=E4=B8=8E=E5=85=B6=E5=AE=83=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E4=BB=8E=20props=20=E4=B8=AD=E8=A7=A3?= =?UTF-8?q?=E6=9E=84=20close=20#3530?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/functional.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/taro-transformer-wx/src/functional.ts b/packages/taro-transformer-wx/src/functional.ts index ed9e6356aa63..dee3762d75e6 100644 --- a/packages/taro-transformer-wx/src/functional.ts +++ b/packages/taro-transformer-wx/src/functional.ts @@ -91,11 +91,27 @@ const ${id.name} = ${generate(t.arrowFunctionExpression(params, body)).code} if (t.isIdentifier(arg)) { cloneBody.body.unshift(buildConstVariableDeclaration(arg.name, t.memberExpression(t.thisExpression(), t.identifier('props')))) } else if (t.isObjectPattern(arg)) { + let hasChildren = false + for (const [index, p] of arg.properties.entries()) { + if (t.isObjectProperty(p) && t.isIdentifier(p.key, { name: 'children' })) { + hasChildren = true + arg.properties.splice(index, 1) + } + } cloneBody.body.unshift( t.variableDeclaration('const', [ t.variableDeclarator(arg, t.memberExpression(t.thisExpression(), t.identifier('props'))) ]) ) + if (hasChildren) { + cloneBody.body.unshift( + t.variableDeclaration('const', [ + t.variableDeclarator(t.objectPattern([ + t.objectProperty(t.identifier('children'), t.identifier('children')) as any + ]), t.memberExpression(t.thisExpression(), t.identifier('props'))) + ]) + ) + } } else if (t.isAssignmentPattern(arg)) { throw codeFrameError(arg, '给函数式组件的第一个参数设置默认参数是没有意义的,因为 props 永远都有值(不传 props 的时候是个空对象),所以默认参数永远都不会执行。') } else { From ed361db3f4bd2fc0a6ac1090cbef0ec12eaa4d31 Mon Sep 17 00:00:00 2001 From: yuche Date: Tue, 25 Jun 2019 16:07:45 +0800 Subject: [PATCH 059/158] =?UTF-8?q?fix(transformer):=20=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=BC=8F=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81=20bind=EF=BC=8Ccl?= =?UTF-8?q?ose=20#3534?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/class.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/taro-transformer-wx/src/class.ts b/packages/taro-transformer-wx/src/class.ts index d77cef58e2eb..24c5cdbff3d3 100644 --- a/packages/taro-transformer-wx/src/class.ts +++ b/packages/taro-transformer-wx/src/class.ts @@ -25,6 +25,7 @@ import { Adapters, Adapter, isNewPropsSystem } from './adapter' import { LoopRef } from './interface' import generate from 'babel-generator' import { isTestEnv } from './env' +import { Status } from './functional' type ClassMethodsMap = Map> @@ -648,7 +649,8 @@ class Transformer { if ( t.isCallExpression(expr) && t.isMemberExpression(expr.callee) && - t.isIdentifier(expr.callee.property, { name: 'bind' }) + t.isIdentifier(expr.callee.property, { name: 'bind' }) && + !Status.isSFC ) { if ( (!isNewPropsSystem()) || From 46604f5003bdf0afe2cede73f69a44a4c16638d0 Mon Sep 17 00:00:00 2001 From: yuche Date: Tue, 25 Jun 2019 16:33:56 +0800 Subject: [PATCH 060/158] =?UTF-8?q?fix(transformer):=20=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=86=99=20return=20=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=8C=BF=E5=90=8D=E5=87=BD=E6=95=B0=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?close=20#3536?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/class.ts | 63 ++++++++++++++--------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/packages/taro-transformer-wx/src/class.ts b/packages/taro-transformer-wx/src/class.ts index 24c5cdbff3d3..e735ea34f486 100644 --- a/packages/taro-transformer-wx/src/class.ts +++ b/packages/taro-transformer-wx/src/class.ts @@ -270,32 +270,45 @@ class Transformer { ] ) )]) - stemParent.insertBefore(indexKeyDecl) - const arrayFunc = t.memberExpression( - t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName + 'Map')), - t.identifier(indexKey), - true - ) - classBody.push( - t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier(indexKey), t.identifier('e')], t.blockStatement([ - isCatch ? t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('e'), t.identifier('stopPropagation')), [])) : t.emptyStatement(), - t.returnStatement(t.logicalExpression('&&', arrayFunc, t.callExpression(arrayFunc, [t.identifier('e')]))) - ])) - ) - exprPath.replaceWith(t.callExpression( - t.memberExpression( - t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)), - t.identifier('bind') - ), - [t.thisExpression(), t.identifier(indexKey)] - )) - stemParent.insertBefore( - t.expressionStatement(t.assignmentExpression( - '=', - arrayFunc, - expr + + const func = loopCallExpr.node.arguments[0] + if (t.isArrowFunctionExpression(func)) { + if (!t.isBlockStatement(func.body)) { + func.body = t.blockStatement([ + indexKeyDecl, + t.returnStatement(func.body) + ]) + } else { + func.body.body.push(indexKeyDecl) + } + const arrayFunc = t.memberExpression( + t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName + 'Map')), + t.identifier(indexKey), + true + ) + classBody.push( + t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier(indexKey), t.identifier('e')], t.blockStatement([ + isCatch ? t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('e'), t.identifier('stopPropagation')), [])) : t.emptyStatement(), + t.returnStatement(t.logicalExpression('&&', arrayFunc, t.callExpression(arrayFunc, [t.identifier('e')]))) + ])) + ) + exprPath.replaceWith(t.callExpression( + t.memberExpression( + t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)), + t.identifier('bind') + ), + [t.thisExpression(), t.identifier(indexKey)] )) - ) + func.body.body.push( + t.expressionStatement(t.assignmentExpression( + '=', + arrayFunc, + expr + )) + ) + } else { + throw codeFrameError(func, '返回 JSX 的循环语句必须使用箭头函数') + } } else { classBody.push( t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier('e')], t.blockStatement([ From 9198e8b692bb3ef28758e470b88f46534324ca6d Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Tue, 25 Jun 2019 10:37:14 +0800 Subject: [PATCH 061/158] =?UTF-8?q?refactor(components-rn):=20Button,=20To?= =?UTF-8?q?uchableWithoutFeedback=20=E4=BB=A3=E6=9B=BF=20TouchableOpacity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taro-components-rn/src/components/Button/index.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/taro-components-rn/src/components/Button/index.tsx b/packages/taro-components-rn/src/components/Button/index.tsx index 75065aa25692..2c7c2651f3bc 100644 --- a/packages/taro-components-rn/src/components/Button/index.tsx +++ b/packages/taro-components-rn/src/components/Button/index.tsx @@ -30,7 +30,7 @@ import * as React from 'react' import { - TouchableOpacity, + TouchableWithoutFeedback, Text, View, Image, @@ -52,7 +52,7 @@ class _Button extends React.Component { hoverStayTime: 70 } - $touchable = React.createRef() + $touchable = React.createRef() state: ButtonState = { valve: new Animated.Value(0), @@ -139,9 +139,7 @@ class _Button extends React.Component { }) return ( - { {children} : children} - + ) } } From d1d548b8ceb42dad54f84c278e404901979510fe Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Wed, 26 Jun 2019 10:14:20 +0800 Subject: [PATCH 062/158] =?UTF-8?q?test(components-rn):=20=E9=92=88?= =?UTF-8?q?=E5=AF=B9=E7=80=91=E5=B8=83=E6=B5=81=E7=9A=84=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E5=B0=9D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TCRNExample/App.experimental.js | 157 ++++++++++++ .../ScrollView/PropsTypeExperimental.tsx | 59 +++++ .../ScrollView/ScrollViewExperimental.tsx | 225 ++++++++++++++++++ packages/taro-components-rn/tsconfig.json | 4 + 4 files changed, 445 insertions(+) create mode 100644 packages/taro-components-rn/TCRNExample/App.experimental.js create mode 100644 packages/taro-components-rn/src/components/ScrollView/PropsTypeExperimental.tsx create mode 100644 packages/taro-components-rn/src/components/ScrollView/ScrollViewExperimental.tsx diff --git a/packages/taro-components-rn/TCRNExample/App.experimental.js b/packages/taro-components-rn/TCRNExample/App.experimental.js new file mode 100644 index 000000000000..2382a56b407a --- /dev/null +++ b/packages/taro-components-rn/TCRNExample/App.experimental.js @@ -0,0 +1,157 @@ +import React, { Component } from 'react' +import { StyleSheet } from 'react-native' +import { + Provider, + Block, + // ScrollView, + View, + Text, + Button, + Image +} from '../dist' +import ScrollView from '../dist/components/ScrollView/ScrollViewExperimental' +// import EXAudio from './example/EXAudio' +import EXButton from './example/EXButton' +import EXCheckbox from './example/EXCheckbox' +import EXForm from './example/EXForm' +import EXIcon from './example/EXIcon' +import EXImage from './example/EXImage' +import EXInput from './example/EXInput' +// import EXMap from './example/EXMap' +import EXPicker from './example/EXPicker' +import EXProgress from './example/EXProgress' +import EXRadio from './example/EXRadio' +import EXRichText from './example/EXRichText' +import EXSlider from './example/EXSlider' +import EXSwiper from './example/EXSwiper' +import EXSwitch from './example/EXSwitch' +// import EXVideo from './example/EXVideo' +import EXWebView from './example/EXWebView' + +export default class App extends Component { + state = { + // 更改 scrollTop 可滚动 + scrollTop: 0 + } + + onViewTouchstart = () => { + console.log('view toucstart') + } + + onViewTouchmove = () => { + console.log('view touchmove') + } + + onViewTouchend = () => { + console.log('view touchend') + } + + componentDidMount () { + // setTimeout(() => { + // this.setState({ scrollTop: 2200 }) + // }, 0) + } + + render () { + return ( + + { + console.log('to upper') + }} + onScrollToLower={() => { + console.log('to lower') + }} + lowerThreshold={500} + onScroll={(e) => { + // console.log('onScroll', e) + }} + bounces={false} + + // Experimental + data={[{ height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }, { height: 50 }, { height: 80 }, { height: 60 }]} + heightForItem={(item) => item.height} + renderHeader={() => ( + + Welcome to React Native! + + + Block + + + + + + Button + + + + + + Checkbox + + + + + + Form + + + + + + + Icon + + + + + + + Image + + + + + )} + renderItem={(item, index) => { + return ( + + ) + }} + /> + + ) + } +} + +const styles = StyleSheet.create({ + section: { + alignItems: 'center', + width: '100%', + paddingBottom: 10, + marginBottom: 10, + borderBottomWidth: 1, + borderBottomColor: 'gold' + }, + sectionTit: { + marginBottom: 10, + paddingVertical: 4, + paddingHorizontal: 8, + backgroundColor: 'tomato', + borderRadius: 4, + borderLeftWidth: 3, + borderLeftColor: '#666', + borderRightWidth: 3, + borderRightColor: '#666' + }, + sectionTitTxt: { + fontSize: 18, + color: 'white' + } +}) diff --git a/packages/taro-components-rn/src/components/ScrollView/PropsTypeExperimental.tsx b/packages/taro-components-rn/src/components/ScrollView/PropsTypeExperimental.tsx new file mode 100644 index 000000000000..ea23dce596ed --- /dev/null +++ b/packages/taro-components-rn/src/components/ScrollView/PropsTypeExperimental.tsx @@ -0,0 +1,59 @@ +import * as React from 'react' +import { StyleProp, ViewStyle, ListRenderItem } from 'react-native' +import { LoadingFooter } from 'react-native-spring-scrollview' + +export type ScrollMetrics = { + contentLength: number; + dOffset: number; + dt: number; + offset: number; + offsetX: number; + offsetY: number; + timestamp: number; + velocity: number; + visibleLength: number; +} + +export type EventOnScrollToUpper = { + distanceFromTop: number; +} + +export type EventOnScrollToLower = { + distanceFromEnd: number; +} + +export type EventOnScroll = { + detail: { + scrollLeft: number; + scrollTop: number; + scrollHeight: number; + scrollWidth: number; + deltaX: number; + deltaY: number; + } +} + +export interface ScrollViewState { + snapScrollTop: number; + snapScrollLeft: number; +} + +export interface ScrollViewProps { + style?: StyleProp; + data: any[]; + heightForItem: (item:any,index:number) => number; + renderHeader?: () => React.ReactElement; + renderFooter?: () => React.ReactElement; + renderItem: (item:any, index:number) => React.ReactElement + + scrollX?: boolean; + upperThreshold: number; + lowerThreshold: number; + scrollTop: number; + scrollLeft: number; + onScrollToUpper?: (evt: EventOnScrollToUpper) => void; + onScrollToLower?: (evt: EventOnScrollToLower) => void; + onScroll?: (evt: EventOnScroll) => void; + // RN 属性 + contentContainerStyle?: StyleProp; +} diff --git a/packages/taro-components-rn/src/components/ScrollView/ScrollViewExperimental.tsx b/packages/taro-components-rn/src/components/ScrollView/ScrollViewExperimental.tsx new file mode 100644 index 000000000000..caa55af06332 --- /dev/null +++ b/packages/taro-components-rn/src/components/ScrollView/ScrollViewExperimental.tsx @@ -0,0 +1,225 @@ +/** + * ScrollViewExperimental + */ + +import * as React from 'react' +import { + ScrollView, + FlatList, + NativeSyntheticEvent, + NativeScrollEvent, + LayoutChangeEvent, + StyleSheet, + ViewStyle, + View, + Text +} from 'react-native' +import { WaterfallList } from 'react-native-largelist-v3' +import { omit, noop } from '../../utils' +import { ScrollViewProps, ScrollViewState, ScrollMetrics } from './PropsTypeExperimental' + +class _ScrollView extends React.Component, ScrollViewState> { + static defaultProps = { + upperThreshold: 50, + lowerThreshold: 50, + scrollTop: 0, + scrollLeft: 0, + } + + static getDerivedStateFromProps (props: ScrollViewProps, state: ScrollViewState) { + return state.snapScrollTop !== props.scrollTop || state.snapScrollLeft !== props.scrollLeft ? { + snapScrollTop: props.scrollTop, + snapScrollLeft: props.scrollLeft + } : null + } + + state: ScrollViewState = { + snapScrollTop: 0, + snapScrollLeft: 0 + } + + _scrollMetrics: ScrollMetrics = { + contentLength: 0, + dOffset: 0, + dt: 10, + offset: 0, + offsetX: 0, + offsetY: 0, + timestamp: 0, + velocity: 0, + visibleLength: 0, + } + $scrollView = React.createRef>() + _hasDataChangedSinceEndReached: boolean + _sentEndForContentLength: number = 0 + _scrollEventThrottle: number = 50 + _hasCallScrollToUpperInRange: boolean = false + _hasCallScrollToLowerInRange: boolean = false + _initialScrollIndexTimeout: any + + _selectLength = (metrics: { height: number, width: number }): number => { + return !this.props.scrollX ? metrics.height : metrics.width + } + + _selectOffset = (metrics: {x: number, y: number}): number => { + return !this.props.scrollX ? metrics.y : metrics.x + } + + _onContentSizeChange = (width: number, height: number): void => { + this._scrollMetrics.contentLength = this._selectLength({ height, width }) + } + + _onScrollEndDrag = (e: NativeSyntheticEvent): void => { + const { velocity } = e.nativeEvent + if (velocity) { + this._scrollMetrics.velocity = this._selectOffset(velocity) + } + } + + _onMomentumScrollEnd = (): void => { + this._scrollMetrics.velocity = 0 + } + + _onLayout = (e: LayoutChangeEvent): void => { + this._scrollMetrics.visibleLength = this._selectLength(e.nativeEvent.layout) + } + + _maybeCallOnStartReached = (): void => { + const { onScrollToUpper, upperThreshold } = this.props + const { offset } = this._scrollMetrics + if (onScrollToUpper && offset < upperThreshold) { + if (!this._hasCallScrollToUpperInRange) { + onScrollToUpper({ distanceFromTop: offset }) + this._hasCallScrollToUpperInRange = true + } + } else { + this._hasCallScrollToUpperInRange = false + } + } + + _maybeCallOnEndReached = (): void => { + const { onScrollToLower, lowerThreshold } = this.props + const { contentLength, visibleLength, offset } = this._scrollMetrics + const distanceFromEnd = contentLength - visibleLength - offset + if (onScrollToLower && + distanceFromEnd < lowerThreshold && + (this._hasDataChangedSinceEndReached || contentLength !== this._sentEndForContentLength)) { + if (!this._hasCallScrollToLowerInRange) { + this._hasDataChangedSinceEndReached = false + this._hasCallScrollToLowerInRange = true + this._sentEndForContentLength = this._scrollMetrics.contentLength + onScrollToLower({ distanceFromEnd }) + } + } else { + this._hasCallScrollToLowerInRange = false + } + } + + _onScroll = (e: NativeSyntheticEvent): void => { + const { onScroll = noop } = this.props + const scrollLeft: number = e.nativeEvent.contentOffset.x + const scrollTop: number = e.nativeEvent.contentOffset.y + const scrollHeight: number = e.nativeEvent.contentSize.height + const scrollWidth: number = e.nativeEvent.contentSize.width + onScroll({ + detail: { + scrollLeft, + scrollTop, + scrollHeight, + scrollWidth, + deltaX: scrollLeft - this._scrollMetrics.offsetX, + deltaY: scrollTop - this._scrollMetrics.offsetY, + } + }) + + const timestamp: number = e.timeStamp + const visibleLength: number = this._selectLength(e.nativeEvent.layoutMeasurement) + const contentLength: number = this._selectLength(e.nativeEvent.contentSize) + const offset: number = this._selectOffset(e.nativeEvent.contentOffset) + const dt: number = Math.max(1, timestamp - this._scrollMetrics.timestamp) + const dOffset: number = offset - this._scrollMetrics.offset + const velocity: number = dOffset / dt + this._scrollMetrics = { + contentLength, + dt, + dOffset, + offset, + offsetX: scrollLeft, + offsetY: scrollTop, + timestamp, + velocity, + visibleLength, + } + this._maybeCallOnStartReached() + this._maybeCallOnEndReached() + } + + scrollToOffset = (x: number = 0, y: number = 0): void => { + const node = this.$scrollView.current + node && node.scrollTo({ x, y }) + } + + componentDidMount () { + if (this.state.snapScrollTop || this.state.snapScrollLeft) { + this._initialScrollIndexTimeout = setTimeout(() => { + this.scrollToOffset(this.state.snapScrollLeft, this.state.snapScrollTop) + }, 0) + } + } + + getSnapshotBeforeUpdate (prevProps: ScrollViewProps, prevState: ScrollViewState) { + return prevState.snapScrollTop !== this.state.snapScrollTop || prevState.snapScrollLeft !== this.state.snapScrollLeft + } + + componentDidUpdate (prevProps: ScrollViewProps, prevState: ScrollViewState, snapshot: boolean) { + if (snapshot) { + this.scrollToOffset(this.state.snapScrollLeft, this.state.snapScrollTop) + } + } + + componentWillUnmount () { + this._initialScrollIndexTimeout && clearTimeout(this._initialScrollIndexTimeout) + } + + render () { + const { + style, + data, + heightForItem, + renderHeader, + renderFooter, + renderItem, + contentContainerStyle, + } = this.props + + const flattenStyle: ViewStyle & { [key: string]: any } = StyleSheet.flatten(style) + const wrapperStyle: ViewStyle = omit(flattenStyle, [ + 'alignItems', + 'justifyContent' + ]) + const _contentContainerStyle: ViewStyle & { [key: string]: any } = {} + if (flattenStyle) { + flattenStyle.alignItems && (_contentContainerStyle.alignItems = flattenStyle.alignItems) + flattenStyle.justifyContent && (_contentContainerStyle.justifyContent = flattenStyle.justifyContent) + } + + return ( + + ) + } +} + +export default _ScrollView diff --git a/packages/taro-components-rn/tsconfig.json b/packages/taro-components-rn/tsconfig.json index 71d5dea0fa4e..37f930e6db7f 100644 --- a/packages/taro-components-rn/tsconfig.json +++ b/packages/taro-components-rn/tsconfig.json @@ -4,6 +4,10 @@ "src/**/*.tsx", "src/**/*.ts" ], + "exclude": [ + "src/**/ScrollViewExperimental.tsx", + "src/**/PropsTypeExperimental.tsx" + ], "compilerOptions": { "rootDir": "./src", "outDir": "./dist", From b69232dff55a598589f9301e8e70ccc0d000688b Mon Sep 17 00:00:00 2001 From: JinJinJin <709899428@qq.com> Date: Wed, 26 Jun 2019 11:36:03 +0800 Subject: [PATCH 063/158] =?UTF-8?q?fix(components):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20Video=20=E7=BB=84=E4=BB=B6=20poster=20=E5=A4=B1=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20close=20#3526?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-components/src/components/video/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/taro-components/src/components/video/index.js b/packages/taro-components/src/components/video/index.js index 77e114984f7b..d39bd1ea7cce 100644 --- a/packages/taro-components/src/components/video/index.js +++ b/packages/taro-components/src/components/video/index.js @@ -210,6 +210,7 @@ class Video extends Component { } onLoadedMetadata = e => { + if (this.props.poster) return this.setState({ duration: this.videoRef.duration }) From 527ae897c9a42dbcf3b785e8874893e4eb8dc443 Mon Sep 17 00:00:00 2001 From: yuche Date: Wed, 26 Jun 2019 13:53:39 +0800 Subject: [PATCH 064/158] =?UTF-8?q?fix(transformer):=20=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E4=B8=AD=E4=BD=BF=E7=94=A8=E5=AF=B9=E8=B1=A1=E5=B1=95=E5=BC=80?= =?UTF-8?q?=E7=AC=A6=E6=8A=A5=E9=94=99=EF=BC=8Cclose=20#3547?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/class.ts | 2 +- packages/taro-transformer-wx/src/render.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/taro-transformer-wx/src/class.ts b/packages/taro-transformer-wx/src/class.ts index e735ea34f486..c2680d826f52 100644 --- a/packages/taro-transformer-wx/src/class.ts +++ b/packages/taro-transformer-wx/src/class.ts @@ -741,7 +741,7 @@ class Transformer { } if (id.name.endsWith(CONTEXT_PROVIDER)) { - const valueAttr = path.node.openingElement.attributes.find(a => a.name.name === 'value') + const valueAttr = path.node.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === 'value') const contextName = id.name.slice(0, id.name.length - CONTEXT_PROVIDER.length) if (valueAttr) { if (t.isJSXElement(valueAttr.value)) { diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index 68d38432ed20..a3ea45be558c 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -502,7 +502,7 @@ export class RenderParser { } } const block = buildBlockElement() - const hasIfAttr = jsxElementPath.node.openingElement.attributes.find(a => a.name.name === Adapter.if) + const hasIfAttr = jsxElementPath.node.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if) const needWrapper = Adapters.swan === Adapter.type && hasIfAttr if (needWrapper) { block.children = [jsxElementPath.node] @@ -872,7 +872,7 @@ export class RenderParser { newJSXIfAttr(jsxElementPath.node, test, jsxElementPath) } } - const ifAttr = block.openingElement.attributes.find(a => a.name.name === Adapter.if) + const ifAttr = block.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if) if (ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: test })) { const newBlock = buildBlockElement() newBlock.children = [block, jsxElementPath.node] @@ -883,7 +883,7 @@ export class RenderParser { let hasNest = false this.handleNestedIfStatement(block, jsxElementPath.node, parentIfStatement.node.test, hasNest, isElse || !!ifStatement.findParent(p => p.node === parentIfStatement.node.alternate)) if (!hasNest && parentIfStatement.get('alternate') !== ifStatement) { - const ifAttr = block.openingElement.attributes.find(a => a.name.name === Adapter.if) + const ifAttr = block.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if) if (ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: parentIfStatement.node.test })) { const newBlock = buildBlockElement() block.children.push(jsxElementPath.node) @@ -922,8 +922,8 @@ export class RenderParser { if (!t.isJSXElement(child)) { continue } - const ifAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.if) - const ifElseAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.elseif) + const ifAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if) + const ifElseAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.elseif) if ( (ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: test })) || @@ -946,8 +946,8 @@ export class RenderParser { if (!t.isJSXElement(child)) { continue } - const ifAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.if) - const ifElseAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.elseif) + const ifAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if) + const ifElseAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.elseif) if ( (ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: test })) || From 96324366a7cddb67caa99fe408a9e267ed06e48a Mon Sep 17 00:00:00 2001 From: Xiaoli <544028951@qq.com> Date: Wed, 26 Jun 2019 15:25:30 +0800 Subject: [PATCH 065/158] =?UTF-8?q?feat(cli):=20=E4=BF=AE=E5=A4=8Dweapp?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E9=A1=B9=E7=9B=AE=E5=90=8ENerv=E6=9C=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/h5/index.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/taro-cli/src/h5/index.ts b/packages/taro-cli/src/h5/index.ts index dc695135b52a..0b5051fd6081 100644 --- a/packages/taro-cli/src/h5/index.ts +++ b/packages/taro-cli/src/h5/index.ts @@ -267,7 +267,6 @@ class Compiler { let hasComponentDidShow = false let hasComponentDidHide = false let hasComponentWillUnmount = false - let hasJSX = false let hasNerv = false let stateNode: t.ClassProperty @@ -542,6 +541,7 @@ class Compiler { } } + // require('fs').writeFileSync('./ast.json', JSON.stringify(ast, null, 2)) traverse(ast, { ClassExpression: ClassDeclarationOrExpression, ClassDeclaration: ClassDeclarationOrExpression, @@ -669,11 +669,6 @@ class Compiler { } } }, - JSXElement: { - enter (astPath: NodePath) { - hasJSX = true - } - }, JSXOpeningElement: { enter (astPath: NodePath) { const node = astPath.node @@ -709,10 +704,10 @@ class Compiler { createHistoryNode, mountApisNode ] - astPath.traverse(programExitVisitor) - if (hasJSX && !hasNerv) { + /* Taro.render() 会被移除,导致hasJSX判断错误 */ + if (!hasNerv) { extraNodes.unshift( t.importDeclaration( [t.importDefaultSpecifier(t.identifier(nervJsImportDefaultName))], @@ -887,9 +882,13 @@ class Compiler { } } }, + JSXElement: { + exit (astPath: NodePath) { + hasJSX = true + } + }, JSXOpeningElement: { exit (astPath: NodePath) { - hasJSX = true const node = astPath.node const componentName = componentnameMap.get(toVar(node.name)) const componentId = getComponentId(componentName, node) From ff803ae9b596c3886c0f746e05fec3e4c647074b Mon Sep 17 00:00:00 2001 From: Manjiz <25199230@qq.com> Date: Wed, 26 Jun 2019 15:53:20 +0800 Subject: [PATCH 066/158] =?UTF-8?q?refactor(components-rn):=20react-native?= =?UTF-8?q?-swiper=20=E7=8B=AC=E7=AB=8B=E6=88=90=E5=8C=85=20:point=5Fright?= =?UTF-8?q?:=20@manjiz/react-native-swiper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-components-rn/jest.config.js | 3 +- packages/taro-components-rn/package.json | 1 + .../src/components/Swiper/index.tsx | 2 +- .../src/lib/react-native-swiper/PropsType.tsx | 113 ---- .../react-native-swiper/index.bak20190619tsx | 529 ----------------- .../src/lib/react-native-swiper/index.tsx | 534 ------------------ .../src/lib/react-native-swiper/styles.tsx | 49 -- packages/taro-components-rn/yarn.lock | 5 + 8 files changed, 9 insertions(+), 1227 deletions(-) delete mode 100644 packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx delete mode 100644 packages/taro-components-rn/src/lib/react-native-swiper/index.bak20190619tsx delete mode 100644 packages/taro-components-rn/src/lib/react-native-swiper/index.tsx delete mode 100644 packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx diff --git a/packages/taro-components-rn/jest.config.js b/packages/taro-components-rn/jest.config.js index 4afdc4b45124..38e7beacce42 100644 --- a/packages/taro-components-rn/jest.config.js +++ b/packages/taro-components-rn/jest.config.js @@ -6,7 +6,8 @@ module.exports = { '^.+\\.tsx?$': 'ts-jest' }, transformIgnorePatterns: [ - 'node_modules/(?!(react-native|react-native-swiper|react-native-vertical-view-pager|react-native-animatable|react-native-collapsible|@bang88/react-native-ultimate-listview|react-native-modal-popover|react-native-modal-popover|react-native-safe-area-view)/)' + 'node_modules/(?!(react-native|react-native-swiper|react-native-vertical-view-pager|react-native-animatable|react-native-collapsible|@bang88/react-native-ultimate-listview|react-native-modal-popover|react-native-modal-popover|react-native-safe-area-view)/)', + 'node_modules/(?!(@manjiz/react-native-swiper)/)' ], testMatch: [ '**/__tests__/**/*.ts?(x)', diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index ccbabe47d1cb..97fb941cc27e 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -29,6 +29,7 @@ "license": "MIT", "dependencies": { "@ant-design/react-native": "^3.1.9", + "@manjiz/react-native-swiper": "^0.0.3", "prop-types": "^15.6.2", "react-dom": "^16.4.0", "react-mixin": "^5.0.0", diff --git a/packages/taro-components-rn/src/components/Swiper/index.tsx b/packages/taro-components-rn/src/components/Swiper/index.tsx index 6733ff29c441..951acec06ae3 100644 --- a/packages/taro-components-rn/src/components/Swiper/index.tsx +++ b/packages/taro-components-rn/src/components/Swiper/index.tsx @@ -53,7 +53,7 @@ import { ViewStyle } from 'react-native' // import Swiper from 'react-native-swiper' -import Swiper from '../../lib/react-native-swiper' +import Swiper from '@manjiz/react-native-swiper' import { noop } from '../../utils' import { SwiperProps } from './PropsType' diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx deleted file mode 100644 index 7a2c370a87df..000000000000 --- a/packages/taro-components-rn/src/lib/react-native-swiper/PropsType.tsx +++ /dev/null @@ -1,113 +0,0 @@ -import { - StyleProp, - ViewStyle, - ScrollViewProps, -} from 'react-native'; - -export interface ReactNativeSwiperProps extends ScrollViewProps { - children: any; - - containerStyle?: StyleProp; - scrollViewStyle?: StyleProp; - // -> ScrollView.contentContainerStyle - style?: StyleProp; - // Custom styles will merge with the default styles. - paginationStyle?: ViewStyle; - // Allow custom the active-dot element. - dotStyle?: StyleProp; - // Allow custom the active-dot element. - activeDotStyle?: StyleProp; - - // Basic - // If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column. - horizontal?: boolean; - // If no specify default enable fullscreen mode by flex: 1. - loop?: boolean; - // Set to false to disable continuous loop mode. - autoplay?: boolean; - // Index number of initial slide. - index?: number; - // Called with the new index when the user swiped - onIndexChanged?: (index: number) => void; - - // Custom basic style & content - width?: number; - // If no specify default fullscreen mode by flex: 1. - height?: number; - // Only load current index slide , loadMinimalSize slides before and after. - loadMinimal?: boolean; - // see loadMinimal - loadMinimalSize?: number; - // Custom loader to display when slides aren't loaded - loadMinimalLoader?: React.ReactNode; - - // Pagination - // Set to true make pagination visible. - showsPagination?: boolean; - // Complete control how to render pagination with three params (index, total, context) ref to this.state.index / this.state.total / this, For example: show numbers instead of dots. - renderPagination?: (index: number, total: number, swiper: any) => JSX.Element; - // Allow custom the dot element. - dot?: any; - // Allow custom the active-dot element. - activeDot?: any; - // Allow custom the active-dot element. - dotColor?: string; - // Allow custom the active-dot element. - activeDotColor?: string; - - // Autoplay - // Delay between auto play transitions (in second). - autoplayTimeout?: number; - // Cycle direction control. - autoplayDirection?: boolean; - - // Supported ScrollResponder - // When animation begins after letting up - onScrollBeginDrag?: any; - // Makes no sense why this occurs first during bounce - onMomentumScrollEnd?: any; - // Immediately after onMomentumScrollEnd - onTouchStartCapture?: any; - // Same, but bubble phase - onTouchStart?: any; - // You could hold the touch start for a long time - onTouchEnd?: any; - // When lifting up - you could pause forever before * lifting - onResponderRelease?: any; - - // ...ScrollViewProps - // pagingEnabled?: boolean; - // showsHorizontalScrollIndicator?: boolean; - // showsVerticalScrollIndicator?: boolean; - // bounces?: boolean; - // scrollsToTop?: boolean; - // removeClippedSubviews?: boolean; - // automaticallyAdjustContentInsets?: boolean; - // scrollEnabled?: boolean; -} - -export interface ReactNativeSwiperState { - width: number; - height: number; - offset: Offset, - autoplayEnd?: boolean; - loopJump?: boolean; - total: number; - index: number; - dir: 'x' | 'y'; - pIndex: number; -} - -export type Offset = { - x: number; - y: number; -} - -export type ScrollEventSim = { - nativeEvent: { - contentOffset: { - x: number; - y: number; - } - } -} diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.bak20190619tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.bak20190619tsx deleted file mode 100644 index e31e9b24b3c5..000000000000 --- a/packages/taro-components-rn/src/lib/react-native-swiper/index.bak20190619tsx +++ /dev/null @@ -1,529 +0,0 @@ -/** - * react-native-swiper - * - * react-native >= 0.55.4 - * react >= 16.3.1 - * - * 组件由 `react-native-swiper` 修改而来 - * - * @author leecade - * @author Manjiz - */ - -import React, { Component } from 'react' -import { - View, - ScrollView, - Dimensions, - ActivityIndicator, - LayoutChangeEvent, - NativeSyntheticEvent, - NativeScrollEvent, - Platform, - InteractionManager, -} from 'react-native' -import { ReactNativeSwiperProps, ReactNativeSwiperState, Offset } from './PropsType' -import { noop } from '../../utils' -import styles from './styles' - -const isAndroid = Platform.OS === 'android' - -const getOffset = (dir: 'x'|'y', index: number, width: number, height: number): Offset => { - const tmp: Offset = { x: 0, y: 0 } - tmp[dir] = (dir === 'x' ? width : height) * index - return tmp -} - -export default class extends Component { - /** - * @see http://facebook.github.io/react-native/docs/scrollview.html - */ - static defaultProps = { - horizontal: true, - pagingEnabled: true, - removeClippedSubviews: true, - showsPagination: true, - loop: true, - loadMinimalSize: 1, - autoplayTimeout: 2.5, - autoplayDirection: true, - index: 0, - - showsHorizontalScrollIndicator: true, - showsVerticalScrollIndicator: false, - bounces: false, - scrollsToTop: false, - automaticallyAdjustContentInsets: false, - } - - static getDerivedStateFromProps (props: ReactNativeSwiperProps, state: ReactNativeSwiperState) { - const initState: any = { - autoplayEnd: false, - loopJump: false, - offset: {} - } - - initState.total = props.children ? props.children.length || 1 : 0 - - const updateIndex = state.pIndex !== props.index - - if (state.total === initState.total && !updateIndex) { - // retain the index - initState.index = state.index - } else { - initState.index = initState.total > 1 ? Math.min(props.index as number, initState.total - 1) : 0 - initState.pIndex = props.index as number - } - - const { width, height } = Dimensions.get('window') - - initState.dir = props.horizontal ? 'x' : 'y' - initState.width = props.width || state.width || width - initState.height = props.height || state.height || height - initState.offset[initState.dir] = (initState.dir === 'x' ? initState.width : initState.height) * (props.index as number + (props.loop ? 1 : 0)) - - return initState - } - - state: ReactNativeSwiperState = { - width: 0, - height: 0, - offset: { x: 0, y: 0 }, - total: 0, - pIndex: 0, - index: 0, - dir: 'x' - } - initialRender: boolean = true - autoplayTimer: any - loopJumpTimer: any - scrolling: boolean = false - realtimeOffset: Partial = { x: 0, y: 0 } - $scrollView: any = React.createRef() - - onContentSizeChange = (contentWidth: number, contentHeight: number): void => { - console.log('1123 onContentSizeChange=----') - const { loop } = this.props - const { index, width, height, dir } = this.state - const offset: Offset = getOffset(dir, index + (loop ? 1 : 0), width, height) - InteractionManager.runAfterInteractions(() => { - const node = this.$scrollView.current - node && node.scrollTo({ ...offset, animated: isAndroid }, false) - }) - } - - getSnapshotBeforeUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState) { - this.scrolling = false - return { - propsChanged: prevProps !== this.props, - shouldClearAutoPlay: !this.props.autoplay && this.autoplayTimer, - ifIndexChange: prevState.index !== this.state.index, - } - } - - componentDidUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState, snapshot: any) { - if (snapshot.shouldClearAutoPlay) { - clearTimeout(this.autoplayTimer as number) - } - // If the index has changed, we notify the parent via the onIndexChanged callback - if (snapshot.ifIndexChange) { - const { onIndexChanged = noop } = this.props - onIndexChanged(this.state.index) - } - if (!snapshot.propsChanged && prevState.offset !== this.state.offset) { - const node = this.$scrollView.current - // workaround-1: android scrollTo not work after offset changed. (In real device) - node && node.scrollTo({ - ...this.state.offset, - animated: isAndroid || this.isAutoScroll, - duration: this.isAutoScroll ? 500 : 1 - }) - this.isAutoScroll = false - } - } - - componentDidMount () { - this.autoplay() - } - - componentWillUnmount () { - this.autoplayTimer && clearTimeout(this.autoplayTimer) - this.loopJumpTimer && clearTimeout(this.loopJumpTimer) - } - - fullState () { - return Object.assign({}, this.state, { offset: this.realtimeOffset }) - } - - onLayout = (event: LayoutChangeEvent) => { - const { loop } = this.props - const { - index, - total, - dir, - width, - height, - } = this.state - // const { width: layoutWidth, height: layoutHeight } = event.nativeEvent.layout - const layoutWidth = Math.round(event.nativeEvent.layout.width) - const layoutHeight = Math.round(event.nativeEvent.layout.height) - let offsetWouldBeSet: Partial = this.realtimeOffset = {} - const stateWouldBeSet: any = { width: layoutWidth, height: layoutHeight } - - if (total > 1) { - let actualIndex = index - loop && actualIndex++ - offsetWouldBeSet = getOffset(dir, actualIndex, layoutWidth, layoutHeight) - } - - // only update the offset in state if needed, updating offset while swiping - // causes some bad jumping / stuttering - if (layoutWidth !== width || layoutHeight !== height) { - stateWouldBeSet.offset = offsetWouldBeSet - } - - this.setState(stateWouldBeSet) - } - - autoScrollOffset?: Offset - - /** - * Scroll by index - */ - isAutoScroll: boolean = false - scrollBy = (step: number, animated: boolean = true) => { - const { loop } = this.props - const { dir, width, height, index, total } = this.state - console.log('scrollBy', this.scrolling, total) - if (this.scrolling || total < 2) return - const actualIndex = (loop ? 1 : 0) + index - const newActualIndex = actualIndex + step - let x = 0 - let y = 0 - dir === 'x' ? (x = newActualIndex * width) : (y = newActualIndex * height) - - // const node = this.$scrollView.current - // node && node.scrollTo({ x, y, animated, duration: 500 }) - this.isAutoScroll = true - this.setState({ offset: { x, y } }) - this.autoScrollOffset = { x, y } - - // update scroll state - this.scrolling = true - - this.setState({ autoplayEnd: false }) - } - - /** - * Automatic rolling - */ - autoplay = () => { - const { - children, - autoplay, - autoplayTimeout, - loop, - autoplayDirection - } = this.props - const { index, total, autoplayEnd } = this.state - if (!Array.isArray(children) || !autoplay || this.scrolling || autoplayEnd) return - - this.autoplayTimer && clearTimeout(this.autoplayTimer) - this.autoplayTimer = setTimeout(() => { - if (!loop && (autoplayDirection ? index === total - 1 : index === 0)) { - return this.setState({ autoplayEnd: true }) - } else { - this.scrollBy(autoplayDirection ? 1 : -1) - } - }, (autoplayTimeout as number) * 1000) - } - - onScroll = (e: NativeSyntheticEvent) => { - if (isAndroid && this.autoScrollOffset) { - const contentOffset = e.nativeEvent.contentOffset - const { dir, width, height } = this.state - if (Math.abs(contentOffset[dir] - this.autoScrollOffset[dir]) <= 1) { - this.onScrollEnd(e) - } - } - } - - - /** - * Scroll begin handle - */ - onScrollBegin = (e?: NativeSyntheticEvent) => { - const { onScrollBeginDrag = noop } = this.props - // update scroll state - this.scrolling = true - onScrollBeginDrag(e, this.fullState(), this) - } - - /** - * Scroll end handle - */ - onScrollEnd = (e: NativeSyntheticEvent) => { - console.log('onScrollEnd---') - const { onMomentumScrollEnd = noop } = this.props - - // update scroll state - this.scrolling = false - - // making our events coming from android compatible to updateIndex logic - const contentOffset = e.nativeEvent.contentOffset - - this.updateIndexByOffset(contentOffset, () => { - this.autoplay() - - // if `onMomentumScrollEnd` registered will be called here - onMomentumScrollEnd(e, this.fullState(), this) - }) - } - - /* - * Drag end handle - */ - onScrollEndDrag = (e: NativeSyntheticEvent) => { - const { horizontal, children } = this.props - const { index } = this.state - const { contentOffset } = e.nativeEvent - const previousOffset = horizontal ? this.realtimeOffset.x : this.realtimeOffset.y - const newOffset = horizontal ? contentOffset.x : contentOffset.y - - if (previousOffset === newOffset && (index === 0 || index === children.length - 1)) { - this.scrolling = false - } - } - - /** - * Update index after scroll - */ - updateIndexByOffset = (contentOffset: Offset, cb: any) => { - const { loop } = this.props - let { index, dir, width, height, total } = this.state - - // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582 - !this.realtimeOffset && (this.realtimeOffset = {}) - - const diff = (contentOffset[dir] || 0) - (this.realtimeOffset[dir] || 0) - const step = dir === 'x' ? width : height - let loopJump = false - - // Do nothing if offset no change. - if (!this.initialRender && !diff) return - - // Note: if touch very very quickly and continuous, - // the variation of `index` more than 1. - // parseInt() ensures it's always an integer - // index = parseInt(index + Math.round(diff / step) + '') - let actualIndex = parseInt(Math.round((contentOffset[dir] || 0) / step) + '') - - if (loop) { - if (actualIndex === 0) { - index = total - 1 - contentOffset[dir] = step * total - loopJump = true - } else if (actualIndex === total + 1) { - index = 0 - contentOffset[dir] = step - loopJump = true - } else { - index = actualIndex - 1 - } - } - - const stateWouldBeSet: any = { index, loopJump } - - this.realtimeOffset = contentOffset - - // only update offset in state if loopJump is true - if (loopJump) { - // when swiping to the beginning of a looping set for the third time, - // the new offset will be the same as the last one set in state. - // Setting the offset to the same thing will not do anything, - // so we increment it by 1 then immediately set it to what it should be, - // after render. - if (contentOffset[dir] === this.realtimeOffset[dir]) { - stateWouldBeSet.offset = { x: 0, y: 0 } - stateWouldBeSet.offset[dir] = (contentOffset[dir] || 0) + 1 - this.setState(stateWouldBeSet, () => { - this.setState({ offset: contentOffset }, cb) - }) - } else { - stateWouldBeSet.offset = contentOffset - this.setState(stateWouldBeSet, cb) - } - } else { - this.setState(stateWouldBeSet, cb) - } - } - - scrollViewPropOverrides = () => { - const overrides: any = {} - - for (let prop in this.props) { - // if(~scrollResponders.indexOf(prop) - if ( - typeof this.props[prop as keyof ReactNativeSwiperProps] === 'function' - && prop !== 'onMomentumScrollEnd' - && prop !== 'renderPagination' - && prop !== 'onScrollBeginDrag' - ) { - const originResponder = this.props[prop as keyof ReactNativeSwiperProps] || noop - overrides[prop] = (e: any) => originResponder(e, this.fullState(), this) - } - } - - return overrides - } - - /** - * Render pagination - * By default, dots only show when `total` >= 2 - */ - renderPagination = (): React.ReactNode => { - if (this.state.total <= 1) return null - - const dots = [] - const ActiveDot = this.props.activeDot || ( - - ) - - const Dot = this.props.dot || ( - - ) - - for (let i = 0; i < this.state.total; i++) { - dots.push(i === this.state.index - ? React.cloneElement(ActiveDot, { key: i }) - : React.cloneElement(Dot, { key: i }) - ) - } - - return ( - - {dots} - - ) - } - - renderScrollView = (pages: any) => { - return ( - - {pages} - - ) - } - - /** - * Default render - */ - render () { - const { - index, - total, - width, - height - } = this.state - const { - children, - containerStyle, - loop, - loadMinimal, - loadMinimalSize, - loadMinimalLoader, - renderPagination, - showsPagination, - } = this.props - // let dir = state.dir - // let key = 0 - const loopVal = loop ? 1 : 0 - let pages: Element[] | Element = [] - - const pageStyle = [{ width, height }, styles.slide] - const pageStyleLoading: any = { - width, - height, - flex: 1, - justifyContent: 'center', - alignItems: 'center' - } - - // For make infinite at least total > 1 - if (total > 1) { - // Re-design a loop model for avoid img flickering - const pagesKeys = Object.keys(children) - if (loop) { - pagesKeys.unshift(total - 1 + '') - pagesKeys.push('0') - } - - pages = pagesKeys.map((pageIdx: string, i: number) => { - if (loadMinimal) { - if (i >= (index + loopVal - (loadMinimalSize as number)) && - i <= (index + loopVal + (loadMinimalSize as number))) { - return {children[parseInt(pageIdx)]} - } else { - return ( - - {loadMinimalLoader ? loadMinimalLoader : } - - ) - } - } else { - return {children[parseInt(pageIdx)]} - } - }) - } else { - pages = {children} - } - - return ( - - {this.renderScrollView(pages)} - {showsPagination && (renderPagination ? renderPagination(index, total, this) : this.renderPagination())} - - ) - } -} diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx deleted file mode 100644 index f9ddb1326a37..000000000000 --- a/packages/taro-components-rn/src/lib/react-native-swiper/index.tsx +++ /dev/null @@ -1,534 +0,0 @@ -/** - * react-native-swiper - * - * react-native >= 0.55.4 - * react >= 16.3.1 - * - * 组件由 `react-native-swiper` 修改而来 - * - * @author leecade - * @author Manjiz - */ - -import React, { Component } from 'react' -import { - View, - ScrollView, - Dimensions, - ActivityIndicator, - LayoutChangeEvent, - NativeSyntheticEvent, - NativeScrollEvent, - Platform, - InteractionManager, -} from 'react-native' -import { ReactNativeSwiperProps, ReactNativeSwiperState, Offset, ScrollEventSim } from './PropsType' -import { noop } from '../../utils' -import styles from './styles' - -const isAndroid = Platform.OS === 'android' - -const getOffset = (dir: 'x'|'y', index: number, width: number, height: number): Offset => { - const tmp: Offset = { x: 0, y: 0 } - tmp[dir] = (dir === 'x' ? width : height) * index - return tmp -} - -export default class extends Component { - /** - * @see http://facebook.github.io/react-native/docs/scrollview.html - */ - static defaultProps = { - horizontal: true, - pagingEnabled: true, - removeClippedSubviews: true, - showsPagination: true, - loop: true, - loadMinimalSize: 1, - autoplayTimeout: 2.5, - autoplayDirection: true, - index: 0, - - showsHorizontalScrollIndicator: false, - showsVerticalScrollIndicator: false, - bounces: false, - scrollsToTop: false, - automaticallyAdjustContentInsets: false, - } - - static getDerivedStateFromProps (props: ReactNativeSwiperProps, state: ReactNativeSwiperState) { - const initState: any = { - autoplayEnd: false, - loopJump: false, - offset: {} - } - - initState.total = props.children ? props.children.length || 1 : 0 - - const updateIndex = state.pIndex !== props.index - - if (state.total === initState.total && !updateIndex) { - // retain the index - initState.index = state.index - } else { - initState.index = initState.total > 1 ? Math.min(props.index as number, initState.total - 1) : 0 - initState.pIndex = props.index as number - } - - const { width, height } = Dimensions.get('window') - - initState.dir = props.horizontal ? 'x' : 'y' - initState.width = props.width || state.width || width - initState.height = props.height || state.height || height - initState.offset[initState.dir] = (initState.dir === 'x' ? initState.width : initState.height) * (props.index as number + (props.loop ? 1 : 0)) - - return initState - } - - state: ReactNativeSwiperState = { - width: 0, - height: 0, - offset: { x: 0, y: 0 }, - total: 0, - pIndex: 0, - index: 0, - dir: 'x', - } - - autoplayTimer: any - loopJumpTimer: any - autoScrolling: boolean = false - scrolling: boolean = false - scrollAnimated: boolean = false - realtimeOffset: Partial = { x: 0, y: 0 } - onAndroidScrollEndTimer: any - - $scrollView: any = React.createRef() - - componentDidMount () { - this.autoplay() - } - - componentDidUpdate (prevProps: ReactNativeSwiperProps, prevState: ReactNativeSwiperState) { - const shouldClearAutoPlay = !this.props.autoplay && this.autoplayTimer - const indexChanged = prevState.index !== this.state.index - this.scrolling = false - shouldClearAutoPlay && clearTimeout(this.autoplayTimer as number) - // If the index has changed, we notify the parent via the onIndexChanged callback - if (indexChanged) { - const { onIndexChanged = noop } = this.props - onIndexChanged(this.state.index) - } - const { dir } = this.state - if (prevState.offset !== this.state.offset && prevState.offset[dir] !== this.state.offset[dir]) { - const node = this.$scrollView.current - // workaround-1: android scrollTo not work after offset changed. (In real device) - // Android scrollTo didn't trigger onMomentumScrollEnd. - node && node.scrollTo({ - ...this.state.offset, - animated: isAndroid || this.scrollAnimated, - duration: this.scrollAnimated ? 500 : 1 - }) - } - } - - componentWillUnmount () { - this.autoplayTimer && clearTimeout(this.autoplayTimer) - this.loopJumpTimer && clearTimeout(this.loopJumpTimer) - this.onAndroidScrollEndTimer && clearTimeout(this.onAndroidScrollEndTimer) - } - - /** - * Reset index and autoplay if contentSizeChange. - */ - onContentSizeChange = (contentWidth: number, contentHeight: number): void => { - const { loop } = this.props - const { width, total, height, dir } = this.state - const offset: Offset = getOffset(dir, loop && total > 1 ? 1 : 0, width, height) - this.realtimeOffset = offset - this.setState({ index: 0, offset }, () => { - this.autoplay() - // workaround-2: In android, - if (isAndroid) { - const node = this.$scrollView.current - node && node.scrollTo(offset) - } - }) - } - - fullState () { - return Object.assign({}, this.state, { offset: this.realtimeOffset }) - } - - onLayout = (event: LayoutChangeEvent) => { - const { loop } = this.props - const { - index, - total, - dir, - width, - height, - } = this.state - const { width: layoutWidth, height: layoutHeight } = event.nativeEvent.layout - // const layoutWidth = Math.round(event.nativeEvent.layout.width) - // const layoutHeight = Math.round(event.nativeEvent.layout.height) - let offsetWouldBeSet: Partial = this.realtimeOffset = {} - const stateWouldBeSet: any = { width: layoutWidth, height: layoutHeight } - - if (total > 1) { - let actualIndex = index - loop && actualIndex++ - offsetWouldBeSet = getOffset(dir, actualIndex, layoutWidth, layoutHeight) - } - - // only update the offset in state if needed, updating offset while swiping - // causes some bad jumping / stuttering - if (layoutWidth !== width || layoutHeight !== height) { - stateWouldBeSet.offset = offsetWouldBeSet - } - - this.setState(stateWouldBeSet) - } - - /** - * Scroll by index - */ - scrollBy = (step: number, animated: boolean = true) => { - const { loop } = this.props - const { dir, width, height, index, total } = this.state - if (this.scrolling || total < 2) return - const actualIndex = (loop ? 1 : 0) + index - const newActualIndex = actualIndex + step - let x = 0 - let y = 0 - dir === 'x' ? (x = newActualIndex * width) : (y = newActualIndex * height) - - this.scrolling = true - this.autoScrolling = true - this.scrollAnimated = animated - this.setState({ - offset: { x, y }, - autoplayEnd: false - }, () => { - this.scrollAnimated = false - }) - } - - /** - * Automatic rolling - */ - autoplay = () => { - const { - children, - autoplay, - autoplayTimeout, - loop, - autoplayDirection - } = this.props - const { index, total, autoplayEnd } = this.state - if (!Array.isArray(children) || !autoplay || this.scrolling || autoplayEnd) return - - this.autoplayTimer && clearTimeout(this.autoplayTimer) - this.autoplayTimer = setTimeout(() => { - if (!loop && (autoplayDirection ? index === total - 1 : index === 0)) { - return this.setState({ autoplayEnd: true }) - } else { - this.scrollBy(autoplayDirection ? 1 : -1) - } - }, (autoplayTimeout as number) * 1000) - } - - /** - * Scroll begin handle - */ - onScrollBegin = (e?: ScrollEventSim) => { - const { onScrollBeginDrag = noop } = this.props - this.scrolling = true - onScrollBeginDrag(e, this.fullState(), this) - } - - /** - * workaround-3: Android didn't trigger onMomentumScrollEnd after scrollTo(). - */ - onScroll = (e: ScrollEventSim) => { - if (isAndroid && this.autoScrolling) { - const contentOffset = e.nativeEvent.contentOffset - const { dir, offset } = this.state - if (Math.abs(Math.round(contentOffset[dir]) - Math.round(offset[dir])) < 2) { - this.onAndroidScrollEndTimer && clearTimeout(this.onAndroidScrollEndTimer) - // Protect nativeEvent object. - const tmpEvent: ScrollEventSim = { nativeEvent: { contentOffset: { x: contentOffset.x, y: contentOffset.y } } } - this.onAndroidScrollEndTimer = setTimeout(() => { - this.onScrollEnd(tmpEvent) - }, 50) - } - } - } - - /** - * Scroll end handle - */ - onScrollEnd = (e: ScrollEventSim) => { - const { onMomentumScrollEnd = noop } = this.props - - this.scrolling = false - this.autoScrolling = false - - // making our events coming from android compatible to updateIndex logic - const contentOffset = e.nativeEvent.contentOffset - - this.updateIndexByOffset(contentOffset, () => { - this.autoplay() - - // if `onMomentumScrollEnd` registered will be called here - onMomentumScrollEnd(e, this.fullState(), this) - }) - } - - /* - * Drag end handle - */ - onScrollEndDrag = (e: ScrollEventSim) => { - const { horizontal, children } = this.props - const { index } = this.state - const { contentOffset } = e.nativeEvent - const previousOffset = horizontal ? this.realtimeOffset.x : this.realtimeOffset.y - const newOffset = horizontal ? contentOffset.x : contentOffset.y - - if (previousOffset === newOffset && (index === 0 || index === children.length - 1)) { - this.scrolling = false - } - } - - /** - * Update index after scroll - */ - updateIndexByOffset = (contentOffset: Offset, cb: any) => { - const { loop } = this.props - let { index, dir, width, height, total } = this.state - - // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582 - !this.realtimeOffset && (this.realtimeOffset = {}) - - const diff = (contentOffset[dir] || 0) - (this.realtimeOffset[dir] || 0) - const step = dir === 'x' ? width : height - let loopJump = false - - // Do nothing if offset no change. - if (!diff) return - - // Note: if touch very very quickly and continuous, - // the variation of `index` more than 1. - // parseInt() ensures it's always an integer - // index = parseInt(index + Math.round(diff / step) + '') - let actualIndex = parseInt(Math.round((contentOffset[dir] || 0) / step) + '') - - if (loop) { - if (actualIndex === 0) { - index = total - 1 - contentOffset[dir] = step * total - loopJump = true - } else if (actualIndex === total + 1) { - index = 0 - contentOffset[dir] = step - loopJump = true - } else { - index = actualIndex - 1 - } - } - - const stateWouldBeSet: any = { index, loopJump } - - this.realtimeOffset = contentOffset - - // only update offset in state if loopJump is true - if (loopJump) { - // when swiping to the beginning of a looping set for the third time, - // the new offset will be the same as the last one set in state. - // Setting the offset to the same thing will not do anything, - // so we increment it by 1 then immediately set it to what it should be, - // after render. - if (contentOffset[dir] === this.realtimeOffset[dir]) { - stateWouldBeSet.offset = { x: 0, y: 0 } - stateWouldBeSet.offset[dir] = (contentOffset[dir] || 0) + 1 - this.setState(stateWouldBeSet, () => { - this.setState({ offset: contentOffset }, cb) - }) - } else { - stateWouldBeSet.offset = contentOffset - this.setState(stateWouldBeSet, cb) - } - } else { - this.setState(stateWouldBeSet, cb) - } - } - - scrollViewPropOverrides = () => { - const overrides: any = {} - - for (let prop in this.props) { - // if(~scrollResponders.indexOf(prop) - if ( - typeof this.props[prop as keyof ReactNativeSwiperProps] === 'function' - && prop !== 'onMomentumScrollEnd' - && prop !== 'renderPagination' - && prop !== 'onScrollBeginDrag' - ) { - const originResponder = this.props[prop as keyof ReactNativeSwiperProps] || noop - overrides[prop] = (e: any) => originResponder(e, this.fullState(), this) - } - } - - return overrides - } - - /** - * Render pagination - * By default, dots only show when `total` >= 2 - */ - renderPagination = (): React.ReactNode => { - if (this.state.total <= 1) return null - - const dots = [] - const ActiveDot = this.props.activeDot || ( - - ) - - const Dot = this.props.dot || ( - - ) - - for (let i = 0; i < this.state.total; i++) { - dots.push(i === this.state.index - ? React.cloneElement(ActiveDot, { key: i }) - : React.cloneElement(Dot, { key: i }) - ) - } - - return ( - - {dots} - - ) - } - - renderScrollView = (pages: any) => { - return ( - - {pages} - - ) - } - - /** - * Default render - */ - render () { - const { - index, - total, - width, - height - } = this.state - const { - children, - containerStyle, - loop, - loadMinimal, - loadMinimalSize, - loadMinimalLoader, - renderPagination, - showsPagination, - } = this.props - // let dir = state.dir - // let key = 0 - const loopVal = loop ? 1 : 0 - let pages: Element[] | Element = [] - - const pageStyle = [{ width, height }, styles.slide] - const pageStyleLoading: any = { - width, - height, - flex: 1, - justifyContent: 'center', - alignItems: 'center' - } - - // For make infinite at least total > 1 - if (total > 1) { - // Re-design a loop model for avoid img flickering - const pagesKeys = Object.keys(children) - if (loop) { - pagesKeys.unshift(total - 1 + '') - pagesKeys.push('0') - } - - pages = pagesKeys.map((pageIdx: string, i: number) => { - if (loadMinimal) { - if (i >= (index + loopVal - (loadMinimalSize as number)) && - i <= (index + loopVal + (loadMinimalSize as number))) { - return {children[parseInt(pageIdx)]} - } else { - return ( - - {loadMinimalLoader ? loadMinimalLoader : } - - ) - } - } else { - return {children[parseInt(pageIdx)]} - } - }) - } else { - pages = {children} - } - - return ( - - {this.renderScrollView(pages)} - {showsPagination && (renderPagination ? renderPagination(index, total, this) : this.renderPagination())} - - ) - } -} diff --git a/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx b/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx deleted file mode 100644 index 98f064f1a769..000000000000 --- a/packages/taro-components-rn/src/lib/react-native-swiper/styles.tsx +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Default styles - * @type {StyleSheetPropType} - */ - -import { - StyleSheet -} from 'react-native' - -export default StyleSheet.create({ - container: { - backgroundColor: 'transparent', - position: 'relative', - flex: 1 - }, - - wrapper: { - backgroundColor: 'transparent', - }, - - slide: { - backgroundColor: 'transparent', - overflow: 'hidden' - }, - - pagination_x: { - position: 'absolute', - bottom: 25, - left: 0, - right: 0, - flexDirection: 'row', - flex: 1, - justifyContent: 'center', - alignItems: 'center', - backgroundColor: 'transparent' - }, - - pagination_y: { - position: 'absolute', - right: 15, - top: 0, - bottom: 0, - flexDirection: 'column', - flex: 1, - justifyContent: 'center', - alignItems: 'center', - backgroundColor: 'transparent' - } -}) diff --git a/packages/taro-components-rn/yarn.lock b/packages/taro-components-rn/yarn.lock index a6e16ffd3a36..11b7da85f2dd 100644 --- a/packages/taro-components-rn/yarn.lock +++ b/packages/taro-components-rn/yarn.lock @@ -519,6 +519,11 @@ resolved "https://registry.npm.taobao.org/@bang88/react-native-ultimate-listview/download/@bang88/react-native-ultimate-listview-3.3.0.tgz#b09199105b942aee4ae05729e4bd229353217ab6" integrity sha1-sJGZEFuUKu5K4Fcp5L0ik1MherY= +"@manjiz/react-native-swiper@^0.0.3": + version "0.0.3" + resolved "https://registry.npm.taobao.org/@manjiz/react-native-swiper/download/@manjiz/react-native-swiper-0.0.3.tgz#bcc03e573121751d50579050ef38461e21f33233" + integrity sha1-vMA+VzEhdR1QV5BQ7zhGHiHzMjM= + "@sinonjs/commons@^1", "@sinonjs/commons@^1.0.2": version "1.4.0" resolved "http://registry.npm.taobao.org/@sinonjs/commons/download/@sinonjs/commons-1.4.0.tgz#7b3ec2d96af481d7a0321252e7b1c94724ec5a78" From 14b135ad2ab44bb31a7a24413a1d7c162a693e1a Mon Sep 17 00:00:00 2001 From: Xiaoli <544028951@qq.com> Date: Wed, 26 Jun 2019 16:55:40 +0800 Subject: [PATCH 067/158] =?UTF-8?q?fix(cli):=20=E4=BF=AE=E5=A4=8D=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=9B=AE=E5=BD=95=E5=B8=A6'src'=E6=97=B6=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98,=20fix?= =?UTF-8?q?=20#3431?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/h5/index.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/taro-cli/src/h5/index.ts b/packages/taro-cli/src/h5/index.ts index 0b5051fd6081..a7ba5d32e098 100644 --- a/packages/taro-cli/src/h5/index.ts +++ b/packages/taro-cli/src/h5/index.ts @@ -232,8 +232,9 @@ class Compiler { .on('unlink', filePath => { const relativePath = path.relative(appPath, filePath) const extname = path.extname(relativePath) + const distDirname = this.getTempDir(filePath) const isScriptFile = REG_SCRIPTS.test(extname) - const dist = this.getDist(filePath, isScriptFile) + const dist = this.getDist(distDirname, filePath, isScriptFile) printLog(processTypeEnum.UNLINK, '删除文件', relativePath) fs.unlinkSync(dist) }) @@ -1142,16 +1143,23 @@ class Compiler { } } - processFiles (filePath) { - const sourceRoot = this.sourceRoot + getTempDir (filePath) { + const appPath = this.appPath + const sourcePath = this.sourcePath const tempDir = this.tempDir - const file = fs.readFileSync(filePath) const dirname = path.dirname(filePath) + const relPath = path.relative(sourcePath, dirname) + + return path.resolve(appPath, tempDir, relPath) + } + + processFiles (filePath) { + const file = fs.readFileSync(filePath) const extname = path.extname(filePath) - const distDirname = dirname.replace(sourceRoot, tempDir) + const distDirname = this.getTempDir(filePath) const isScriptFile = REG_SCRIPTS.test(extname) - const distPath = this.getDist(filePath, isScriptFile) + const distPath = this.getDist(distDirname, filePath, isScriptFile) try { if (isScriptFile) { @@ -1178,12 +1186,7 @@ class Compiler { } } - getDist (filename, isScriptFile) { - const sourceRoot = this.sourceRoot - const tempDir = this.tempDir - - const dirname = path.dirname(filename) - const distDirname = dirname.replace(sourceRoot, tempDir) + getDist (distDirname, filename, isScriptFile) { return isScriptFile ? path.format({ dir: distDirname, From 08aa12d6bed7f39ad93a24e9590c8628bbd6cd7d Mon Sep 17 00:00:00 2001 From: Xiaoli <544028951@qq.com> Date: Thu, 27 Jun 2019 10:11:43 +0800 Subject: [PATCH 068/158] =?UTF-8?q?fix(h5):=20h5=E7=9A=84chooseImage?= =?UTF-8?q?=E5=9C=A8count=E8=AE=BE=E7=BD=AE=E4=B8=BA1=E6=97=B6=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E4=BA=86multiple=E5=B1=9E=E6=80=A7,=20fix=20#3401?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-h5/src/api/image/chooseImage.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/taro-h5/src/api/image/chooseImage.js b/packages/taro-h5/src/api/image/chooseImage.js index 82286f5940ef..ac9cfed13382 100644 --- a/packages/taro-h5/src/api/image/chooseImage.js +++ b/packages/taro-h5/src/api/image/chooseImage.js @@ -1,6 +1,17 @@ import { shouleBeObject, getParameterError } from '../utils' -export default function chooseImage (options) { +/** + * 从本地相册选择图片或使用相机拍照。 + * @param {Object} object 参数 + * @param {string[]} [object.sourceType=['album', 'camera']] 选择图片的来源(h5端未实现) + * @param {string[]} [object.sizeType=['original', 'compressed']] 所选的图片的尺寸(h5端未实现) + * @param {number} [object.count=9] 最多可以选择的图片张数 + * @param {function} [object.success] 接口调用成功的回调函数 + * @param {function} [object.fail] 接口调用失败的回调函数 + * @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行) + * @param {string} [object.imageId] 用来上传的input元素ID(仅h5端) + */ +const chooseImage = function (options) { // options must be an Object const isObject = shouleBeObject(options) if (!isObject.res) { @@ -34,7 +45,9 @@ export default function chooseImage (options) { let obj = document.createElement('input') obj.setAttribute('type', 'file') obj.setAttribute('id', imageId) - obj.setAttribute('multiple', 'multiple') + if (count > 1) { + obj.setAttribute('multiple', 'multiple') + } obj.setAttribute('accept', 'image/*') obj.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;') document.body.appendChild(obj) @@ -61,3 +74,5 @@ export default function chooseImage (options) { } return taroChooseImagePromise } + +export default chooseImage From 4ef490494b244560a41fbda8d6f443a614a476db Mon Sep 17 00:00:00 2001 From: Xiaoli <544028951@qq.com> Date: Thu, 27 Jun 2019 10:12:26 +0800 Subject: [PATCH 069/158] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85=E4=BA=86choo?= =?UTF-8?q?seImage=E7=9A=84=E6=96=87=E6=A1=A3,=20fix=20#3361?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/apis/multimedia/images/chooseImage.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/apis/multimedia/images/chooseImage.md b/docs/apis/multimedia/images/chooseImage.md index e9a85b977c0b..7e4fab2d5225 100644 --- a/docs/apis/multimedia/images/chooseImage.md +++ b/docs/apis/multimedia/images/chooseImage.md @@ -8,6 +8,28 @@ sidebar_label: chooseImage 注:RN 端该 API 不支持 `count` 属性;不支持相机与相册同时选择,只会取 `sourceType` 数组里的第一个值。默认从相册选取图片。 +## 参数 + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| object | Object | | 参数 | +| [object.sourceType] | Array.<string> | ['album', 'camera'] | 选择图片的来源(h5端未实现) | +| [object.sizeType] | Array.<string> | ['original', 'compressed'] | 所选的图片的尺寸(h5端未实现) | +| [object.count] | number | 9 | 最多可以选择的图片张数 | +| [object.success] | function | | 接口调用成功的回调函数 | +| [object.fail] | function | | 接口调用失败的回调函数 | +| [object.complete] | function | | 接口调用结束的回调函数(调用成功、失败都会执行) | +| [object.imageId] | string | | 用来上传的input元素ID(仅h5端) | + +## 返回值 + +### Promise <object res> + +| Name | Type | Description | +| --- | --- | --- | +| res.tempFilePaths | Array. | 图片的本地临时文件路径列表 +| res.tempFiles | Array. | 图片的本地临时文件列表 + ## 示例代码 ```jsx From 11a8fd23c0b439778d3a71dc35c43d2003059c8b Mon Sep 17 00:00:00 2001 From: Xiaoli <544028951@qq.com> Date: Thu, 27 Jun 2019 10:37:15 +0800 Subject: [PATCH 070/158] =?UTF-8?q?fix(h5):=20=E4=BF=AE=E5=A4=8DpreviewIma?= =?UTF-8?q?ge=E7=9A=84=E7=82=B9=E9=80=8F=E9=97=AE=E9=A2=98,=20fix=20#3071?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../image/react-wx-images-viewer/components/ImageContainer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-h5/src/api/image/react-wx-images-viewer/components/ImageContainer.js b/packages/taro-h5/src/api/image/react-wx-images-viewer/components/ImageContainer.js index 2a0923af946f..2c4f0183e26e 100644 --- a/packages/taro-h5/src/api/image/react-wx-images-viewer/components/ImageContainer.js +++ b/packages/taro-h5/src/api/image/react-wx-images-viewer/components/ImageContainer.js @@ -319,7 +319,7 @@ class ImageContainer extends PureComponent { handleTouchEnd = (event) => { // console.info('handleTouchEnd', event.touches.length) - // event.preventDefault() + event.preventDefault() if (this.isTwoFingerMode) { // 双指操作结束 const touchLen = event.touches.length From 775c9539f041f8c6b2a8c0cd95f8c7cf56244a9b Mon Sep 17 00:00:00 2001 From: Xiaoli <544028951@qq.com> Date: Thu, 27 Jun 2019 14:05:54 +0800 Subject: [PATCH 071/158] =?UTF-8?q?fix(h5):=20=E4=BF=AE=E5=A4=8Dbuild?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8Bh5=20api=E7=9A=84=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E8=A2=ABtreeshake=E6=8E=89=E7=9A=84=E9=97=AE=E9=A2=98,=20fix?= =?UTF-8?q?=20#3497?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-h5/package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json index 66fcd69041f4..dd3aabf95c2e 100644 --- a/packages/taro-h5/package.json +++ b/packages/taro-h5/package.json @@ -12,6 +12,8 @@ "types" ], "sideEffects": [ + "*.scss", + "*.css", "./src/taro/index.js" ], "scripts": { From 3ef3d5b4fa54cd75a78303eb3c1c0d6681f9ef12 Mon Sep 17 00:00:00 2001 From: Xiaoli <544028951@qq.com> Date: Thu, 27 Jun 2019 14:14:23 +0800 Subject: [PATCH 072/158] =?UTF-8?q?feat(webpack-runner):=20mainFields?= =?UTF-8?q?=E8=A1=A5=E4=B8=8A=E4=BA=86browser=E5=AD=97=E6=AE=B5,=20close?= =?UTF-8?q?=20#3415?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-webpack-runner/src/config/base.conf.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-webpack-runner/src/config/base.conf.ts b/packages/taro-webpack-runner/src/config/base.conf.ts index 1e12327c6fdf..ea16560085ee 100644 --- a/packages/taro-webpack-runner/src/config/base.conf.ts +++ b/packages/taro-webpack-runner/src/config/base.conf.ts @@ -8,7 +8,7 @@ export default (appPath: string) => { chain.merge({ resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'], - mainFields: ['main:h5', 'module', 'main'], + mainFields: ['main:h5', 'browser', 'module', 'main'], symlinks: true, modules: [ path.join(appPath, 'node_modules'), From b826b117a57704dbe100bd4c02f907e3424b568f Mon Sep 17 00:00:00 2001 From: Boris Dai Date: Thu, 27 Jun 2019 16:08:06 +0800 Subject: [PATCH 073/158] =?UTF-8?q?fix(taroize):=20=E5=AD=97=E6=AF=8D?= =?UTF-8?q?=E9=9B=86=E4=BB=8Ea-j=E8=B0=83=E6=95=B4=E4=B8=BAb-k=20(#3569)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 生成tmpl文件时,在windows系统下,TaroParseATmpl.js文件会与TaroParseaTmpl.js文件命名冲突,导致TaroParseaTmpl.js文件生成不了,代码运行时报TaroParseaTmpl.js文件找不到,因为windows不区分文件名字母大小写,会认为是同一个文件。 --- packages/taroize/src/template.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taroize/src/template.ts b/packages/taroize/src/template.ts index 587e58175ad0..8df0fec7141c 100644 --- a/packages/taroize/src/template.ts +++ b/packages/taroize/src/template.ts @@ -10,7 +10,7 @@ function isNumeric (n) { return !isNaN(parseFloat(n)) && isFinite(n) } -const NumberWords = ['z', 'a','b','c','d','e', 'f','g','h','i','j'] +const NumberWords = ['z', 'b','c','d','e', 'f','g','h','i','j','k'] function buildTemplateName (name: string) { if (/wx/i.test(name)) { From eda6750abef1363987df8ec9ba65e3df154779ab Mon Sep 17 00:00:00 2001 From: yuche Date: Thu, 27 Jun 2019 15:56:54 +0800 Subject: [PATCH 074/158] =?UTF-8?q?feat(transformer):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20render=20props?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/class.ts | 27 ++++++- .../taro-transformer-wx/src/functional.ts | 18 +++++ packages/taro-transformer-wx/src/index.ts | 2 +- packages/taro-transformer-wx/src/jsx.ts | 3 +- .../taro-transformer-wx/src/render-props.ts | 76 +++++++++++++++++++ packages/taro-transformer-wx/src/utils.ts | 1 + 6 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 packages/taro-transformer-wx/src/render-props.ts diff --git a/packages/taro-transformer-wx/src/class.ts b/packages/taro-transformer-wx/src/class.ts index c2680d826f52..e320e8a4b621 100644 --- a/packages/taro-transformer-wx/src/class.ts +++ b/packages/taro-transformer-wx/src/class.ts @@ -26,6 +26,7 @@ import { LoopRef } from './interface' import generate from 'babel-generator' import { isTestEnv } from './env' import { Status } from './functional' +import { injectRenderPropsEmiter } from './render-props' type ClassMethodsMap = Map> @@ -640,6 +641,10 @@ class Transformer { calleeExpr.get('object').isMemberExpression() && calleeExpr.get('property').isIdentifier({ name: 'bind' })) // is not bind ) { + const calleeName = calleeExpr.isIdentifier() && calleeExpr.node.name + if (typeof calleeName === 'string' && isDerivedFromProps(calleeExpr.scope, calleeName)) { + return + } generateAnonymousState(scope, expression, jsxReferencedIdentifiers) } else { if (parentPath.isJSXAttribute()) { @@ -675,7 +680,7 @@ class Transformer { if ( (!isNewPropsSystem()) || (t.isJSXIdentifier(jsx.node.name) && DEFAULT_Component_SET.has(jsx.node.name.name)) - ) { + ) { self.buildPropsAnonymousFunc(attr, expr as any, false) } } else if (!t.isLiteral(expr)) { @@ -689,6 +694,7 @@ class Transformer { if (!t.isJSXIdentifier(jsxName)) return if (expression.isJSXElement()) return if (DEFAULT_Component_SET.has(jsxName.name) || expression.isIdentifier() || expression.isMemberExpression() || expression.isLiteral() || expression.isLogicalExpression() || expression.isConditionalExpression() || key.name.startsWith('on') || expression.isCallExpression()) return + if (isContainJSXElement(path)) return generateAnonymousState(scope, expression, jsxReferencedIdentifiers) }, Identifier (path) { @@ -700,6 +706,12 @@ class Transformer { slot.openingElement.attributes.push(t.jSXAttribute(t.jSXIdentifier('name'), t.stringLiteral(getSlotName(path.node.name)))) self.setMultipleSlots() } + if (parentPath.isCallExpression() && parentPath.parentPath.isJSXExpressionContainer()) { + if (isDerivedFromProps(path.scope, path.node.name)) { + parentPath.replaceWith(slot) + injectRenderPropsEmiter(parentPath, path.node.name) + } + } if (parentPath.isMemberExpression() && parentPath.isReferenced() && parentPath.parentPath.isJSXExpressionContainer()) { const object = parentPath.get('object') if (object.isIdentifier()) { @@ -783,9 +795,16 @@ class Transformer { parentPath.replaceWith(t.jSXElement(t.jSXOpeningElement(t.jSXIdentifier('slot'), [], true), t.jSXClosingElement(t.jSXIdentifier('slot')), [], true)) } else if (/^render[A-Z]/.test(name)) { const slotName = getSlotName(name) - parentPath.replaceWith(t.jSXElement(t.jSXOpeningElement(t.jSXIdentifier('slot'), [ - t.jSXAttribute(t.jSXIdentifier('name'), t.stringLiteral(slotName)) - ], true), t.jSXClosingElement(t.jSXIdentifier('slot')), [])) + if (parentPath.parentPath.isCallExpression()) { + parentPath.parentPath.replaceWith(t.jSXElement(t.jSXOpeningElement(t.jSXIdentifier('slot'), [ + t.jSXAttribute(t.jSXIdentifier('name'), t.stringLiteral(slotName)) + ], true), t.jSXClosingElement(t.jSXIdentifier('slot')), [])) + injectRenderPropsEmiter(parentPath.parentPath, name) + } else { + parentPath.replaceWith(t.jSXElement(t.jSXOpeningElement(t.jSXIdentifier('slot'), [ + t.jSXAttribute(t.jSXIdentifier('name'), t.stringLiteral(slotName)) + ], true), t.jSXClosingElement(t.jSXIdentifier('slot')), [])) + } this.setMultipleSlots() } else { self.componentProperies.add(siblingProp.node.name) diff --git a/packages/taro-transformer-wx/src/functional.ts b/packages/taro-transformer-wx/src/functional.ts index dee3762d75e6..1860e1b2dff7 100644 --- a/packages/taro-transformer-wx/src/functional.ts +++ b/packages/taro-transformer-wx/src/functional.ts @@ -3,6 +3,8 @@ import { codeFrameError, buildConstVariableDeclaration } from './utils' import * as t from 'babel-types' import { cloneDeep } from 'lodash' import generate from 'babel-generator' +import { DEFAULT_Component_SET } from './constant' +import { injectRenderPropsListener } from './render-props' function initialIsCapital (word: string) { return word[0] !== word[0].toLowerCase() @@ -124,6 +126,22 @@ const ${id.name} = ${generate(t.arrowFunctionExpression(params, body)).code} ]), []) functionDecl.replaceWith(classDecl) } + }, + JSXAttribute (path) { + const { name, value } = path.node + const jsxElementPath = path.parentPath.parentPath + if (t.isJSXIdentifier(name) && jsxElementPath.isJSXElement()) { + const componentName = (jsxElementPath.node.openingElement as any).name.name + if (/^render[A-Z]/.test(name.name) && !DEFAULT_Component_SET.has(componentName)) { + if (!t.isJSXExpressionContainer(value)) { + throw codeFrameError(value, '以 render 开头的 props 只能传入包含一个 JSX 元素的 JSX 表达式。') + } + const expression = value.expression + if (t.isArrowFunctionExpression(expression)) { + injectRenderPropsListener(path, name.name, expression, componentName) + } + } + } } } } diff --git a/packages/taro-transformer-wx/src/index.ts b/packages/taro-transformer-wx/src/index.ts index 8f2dacaf5dd9..ada065e73a38 100644 --- a/packages/taro-transformer-wx/src/index.ts +++ b/packages/taro-transformer-wx/src/index.ts @@ -108,7 +108,7 @@ function handleClosureJSXFunc (jsx: NodePath, mainClass: NodePath< const parentPath = arrowFunc.parentPath if (parentPath.isVariableDeclarator()) { const id = parentPath.node.id - if (t.isIdentifier(id) && id.name.startsWith('render')) { + if (t.isIdentifier(id) && /^render[A-Z]/.test(id.name)) { const funcName = `renderClosure${id.name.slice(6, id.name.length)}` mainClass.node.body.body.push( t.classProperty( diff --git a/packages/taro-transformer-wx/src/jsx.ts b/packages/taro-transformer-wx/src/jsx.ts index 8f858271490d..8754b444efe7 100644 --- a/packages/taro-transformer-wx/src/jsx.ts +++ b/packages/taro-transformer-wx/src/jsx.ts @@ -86,7 +86,8 @@ export function setJSXAttr ( return } const element = jsx.openingElement - if (!t.isJSXIdentifier(element.name)) { + // tslint:disable-next-line: strict-type-predicates + if (element == null || !t.isJSXIdentifier(element.name)) { return } if (element.name.name === 'Block' || element.name.name === 'block' || !path) { diff --git a/packages/taro-transformer-wx/src/render-props.ts b/packages/taro-transformer-wx/src/render-props.ts new file mode 100644 index 000000000000..049c42e4e0c0 --- /dev/null +++ b/packages/taro-transformer-wx/src/render-props.ts @@ -0,0 +1,76 @@ +import * as t from 'babel-types' +import { buildConstVariableDeclaration, createRandomLetters, codeFrameError } from './utils' +import { NodePath } from 'babel-traverse' +import { buildBlockElement } from './jsx' +import { get as safeGet } from 'lodash' + +const renderPropsMap = new Map() + +export function injectRenderPropsListener (attrPath: NodePath, attrName: string, attrExpr: t.ArrowFunctionExpression, componentName: string) { + const randomLetters = createRandomLetters(5) + const renderClosureFuncName = attrName + randomLetters + const jsxDecl = buildConstVariableDeclaration(renderClosureFuncName, attrExpr) + const block = buildBlockElement() + const renderPropsArgs = t.memberExpression(t.thisExpression(), t.identifier(renderClosureFuncName)) + renderPropsMap.set(componentName + '_' + attrName, renderClosureFuncName) + block.children = [ + t.jSXExpressionContainer(t.callExpression(t.identifier(renderClosureFuncName), [renderPropsArgs])) + ] + const listener = buildListener(renderPropsArgs) + const stemParent = attrPath.getStatementParent() + stemParent.insertBefore(listener) + stemParent.insertBefore(jsxDecl) + attrPath.get('value').replaceWith(t.jSXExpressionContainer(block)) +} + +export function injectRenderPropsEmiter (callExpr: NodePath, attrName: string) { + const classDecl = callExpr.findParent(p => p.isClassDeclaration()) + const classDeclName = classDecl && classDecl.isClassDeclaration() && safeGet(classDecl, 'node.id.name', '') + if (typeof classDeclName !== 'string') { + throw codeFrameError(classDecl, '使用 render props 必须指定 class 的名称。') + } + const renderClosureFuncName = renderPropsMap.get(classDeclName + '_' + attrName) || '' + const args: (t.Expression | t.SpreadElement)[] = [t.stringLiteral(renderClosureFuncName)] + if (Array.isArray(callExpr.node.arguments) && callExpr.node.arguments.length) { + args.push(callExpr.node.arguments[0]) + } + const emiter = t.callExpression( + t.memberExpression(buildEventCenterMemberExpr(), t.identifier('trigger')), + args + ) + const stemParent = callExpr.getStatementParent() + stemParent.insertBefore(t.expressionStatement(emiter)) +} + +function buildListener (renderPropsArgs: t.MemberExpression) { + return t.expressionStatement( + t.callExpression( + t.memberExpression( + buildEventCenterMemberExpr(), + t.identifier('only') + ), + [t.arrowFunctionExpression([t.identifier('e')], t.blockStatement([ + t.ifStatement( + t.callExpression( + t.memberExpression(t.identifier('Taro'), t.identifier('shaowEqual')), + [t.identifier('e'), renderPropsArgs] + ), + t.blockStatement([ + t.expressionStatement(t.assignmentExpression('=', renderPropsArgs, t.identifier('e'))), + t.expressionStatement(t.callExpression( + t.memberExpression(t.thisExpression(), t.identifier('setState')), + [t.objectExpression([])] + )) + ]) + ) + ]))] + ) + ) +} + +function buildEventCenterMemberExpr () { + return t.memberExpression( + t.identifier('Taro'), + t.identifier('eventCenter') + ) +} diff --git a/packages/taro-transformer-wx/src/utils.ts b/packages/taro-transformer-wx/src/utils.ts index f7e4a321d56a..fee59ec7fb6f 100644 --- a/packages/taro-transformer-wx/src/utils.ts +++ b/packages/taro-transformer-wx/src/utils.ts @@ -246,6 +246,7 @@ export function generateAnonymousState ( if (isArrowFunctionInJSX) { return } + // tslint:disable-next-line: strict-type-predicates if (t.isIdentifier(id) && !id.name.startsWith(LOOP_STATE) && !id.name.startsWith('_$') && init != null) { const newId = scope.generateDeclaredUidIdentifier('$' + id.name) refIds.forEach((refId) => { From 6f15795327873fd779732d1241578aea391099c0 Mon Sep 17 00:00:00 2001 From: yuche Date: Thu, 27 Jun 2019 19:48:10 +0800 Subject: [PATCH 075/158] =?UTF-8?q?refactor(transformer):=20=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=20render=20props=20=E7=9A=84=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=BE=AA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/class.ts | 4 ++-- packages/taro-transformer-wx/src/jsx.ts | 7 +++++-- packages/taro-transformer-wx/src/render-props.ts | 16 ++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/taro-transformer-wx/src/class.ts b/packages/taro-transformer-wx/src/class.ts index e320e8a4b621..338b0ddb22ef 100644 --- a/packages/taro-transformer-wx/src/class.ts +++ b/packages/taro-transformer-wx/src/class.ts @@ -708,8 +708,8 @@ class Transformer { } if (parentPath.isCallExpression() && parentPath.parentPath.isJSXExpressionContainer()) { if (isDerivedFromProps(path.scope, path.node.name)) { - parentPath.replaceWith(slot) injectRenderPropsEmiter(parentPath, path.node.name) + parentPath.replaceWith(slot) } } if (parentPath.isMemberExpression() && parentPath.isReferenced() && parentPath.parentPath.isJSXExpressionContainer()) { @@ -796,10 +796,10 @@ class Transformer { } else if (/^render[A-Z]/.test(name)) { const slotName = getSlotName(name) if (parentPath.parentPath.isCallExpression()) { + injectRenderPropsEmiter(parentPath.parentPath, name) parentPath.parentPath.replaceWith(t.jSXElement(t.jSXOpeningElement(t.jSXIdentifier('slot'), [ t.jSXAttribute(t.jSXIdentifier('name'), t.stringLiteral(slotName)) ], true), t.jSXClosingElement(t.jSXIdentifier('slot')), [])) - injectRenderPropsEmiter(parentPath.parentPath, name) } else { parentPath.replaceWith(t.jSXElement(t.jSXOpeningElement(t.jSXIdentifier('slot'), [ t.jSXAttribute(t.jSXIdentifier('name'), t.stringLiteral(slotName)) diff --git a/packages/taro-transformer-wx/src/jsx.ts b/packages/taro-transformer-wx/src/jsx.ts index 8754b444efe7..e0ce743276d1 100644 --- a/packages/taro-transformer-wx/src/jsx.ts +++ b/packages/taro-transformer-wx/src/jsx.ts @@ -123,8 +123,11 @@ export function isAllLiteral (...args) { return args.every(p => t.isLiteral(p)) } -export function buildBlockElement (attrs: t.JSXAttribute[] = []) { - const blockName = Adapter.type === Adapters.quickapp ? 'div' : 'block' +export function buildBlockElement (attrs: t.JSXAttribute[] = [], isView = false) { + let blockName = Adapter.type === Adapters.quickapp ? 'div' : 'block' + if (isView) { + blockName = 'View' + } return t.jSXElement( t.jSXOpeningElement(t.jSXIdentifier(blockName), attrs), t.jSXClosingElement(t.jSXIdentifier(blockName)), diff --git a/packages/taro-transformer-wx/src/render-props.ts b/packages/taro-transformer-wx/src/render-props.ts index 049c42e4e0c0..7f6843b6c6ff 100644 --- a/packages/taro-transformer-wx/src/render-props.ts +++ b/packages/taro-transformer-wx/src/render-props.ts @@ -10,13 +10,13 @@ export function injectRenderPropsListener (attrPath: NodePath, a const randomLetters = createRandomLetters(5) const renderClosureFuncName = attrName + randomLetters const jsxDecl = buildConstVariableDeclaration(renderClosureFuncName, attrExpr) - const block = buildBlockElement() + const block = buildBlockElement([], true) const renderPropsArgs = t.memberExpression(t.thisExpression(), t.identifier(renderClosureFuncName)) renderPropsMap.set(componentName + '_' + attrName, renderClosureFuncName) block.children = [ t.jSXExpressionContainer(t.callExpression(t.identifier(renderClosureFuncName), [renderPropsArgs])) ] - const listener = buildListener(renderPropsArgs) + const listener = buildListener(renderClosureFuncName, renderPropsArgs) const stemParent = attrPath.getStatementParent() stemParent.insertBefore(listener) stemParent.insertBefore(jsxDecl) @@ -42,19 +42,19 @@ export function injectRenderPropsEmiter (callExpr: NodePath, a stemParent.insertBefore(t.expressionStatement(emiter)) } -function buildListener (renderPropsArgs: t.MemberExpression) { +function buildListener (renderClosureFuncName: string, renderPropsArgs: t.MemberExpression) { return t.expressionStatement( t.callExpression( t.memberExpression( buildEventCenterMemberExpr(), - t.identifier('only') + t.identifier('on') ), - [t.arrowFunctionExpression([t.identifier('e')], t.blockStatement([ + [t.stringLiteral(renderClosureFuncName), t.arrowFunctionExpression([t.identifier('e')], t.blockStatement([ t.ifStatement( - t.callExpression( - t.memberExpression(t.identifier('Taro'), t.identifier('shaowEqual')), + t.unaryExpression('!', t.callExpression( + t.memberExpression(t.identifier('Taro'), t.identifier('shallowEqual')), [t.identifier('e'), renderPropsArgs] - ), + )), t.blockStatement([ t.expressionStatement(t.assignmentExpression('=', renderPropsArgs, t.identifier('e'))), t.expressionStatement(t.callExpression( From 279becb16d58e4d5bb0d3e39fd78e5ca2ad8a579 Mon Sep 17 00:00:00 2001 From: yuche Date: Thu, 27 Jun 2019 19:54:41 +0800 Subject: [PATCH 076/158] =?UTF-8?q?feat(weapp):=20=E6=8A=8A=20`shallowEqua?= =?UTF-8?q?l`=20=E5=AF=BC=E5=87=BA=E5=88=B0=E5=90=84=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=AB=AF=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-alipay/src/index.js | 4 +++- packages/taro-qq/src/index.js | 4 +++- packages/taro-quickapp/src/index.js | 4 +++- packages/taro-swan/src/index.js | 4 +++- packages/taro-tt/src/index.js | 4 +++- packages/taro-weapp/src/index.js | 4 +++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/taro-alipay/src/index.js b/packages/taro-alipay/src/index.js index e37a20738346..44a1e3423e29 100644 --- a/packages/taro-alipay/src/index.js +++ b/packages/taro-alipay/src/index.js @@ -23,6 +23,7 @@ import { createContext, memo } from '@tarojs/taro' +import { shallowEqual } from '@tarojs/utils' import Component from './component' import PureComponent from './pure-component' @@ -62,7 +63,8 @@ export const Taro = { useImperativeHandle, useContext, createContext, - memo + memo, + shallowEqual } export default Taro diff --git a/packages/taro-qq/src/index.js b/packages/taro-qq/src/index.js index ff864907dc71..af4e9de0fdb2 100644 --- a/packages/taro-qq/src/index.js +++ b/packages/taro-qq/src/index.js @@ -23,6 +23,7 @@ import { createContext, memo } from '@tarojs/taro' +import { shallowEqual } from '@tarojs/utils' import Component from './component' import PureComponent from './pure-component' @@ -57,7 +58,8 @@ export const Taro = { useImperativeHandle, useContext, createContext, - memo + memo, + shallowEqual } export default Taro diff --git a/packages/taro-quickapp/src/index.js b/packages/taro-quickapp/src/index.js index ef1b9fe07edf..7805866e233d 100644 --- a/packages/taro-quickapp/src/index.js +++ b/packages/taro-quickapp/src/index.js @@ -10,6 +10,7 @@ import { internal_inline_style, internal_get_original } from '@tarojs/taro' +import { shallowEqual } from '@tarojs/utils' import Component from './component' import PureComponent from './pure-component' @@ -31,7 +32,8 @@ export const Taro = { internal_safe_set, internal_inline_style, createComponent, - internal_get_original + internal_get_original, + shallowEqual } export default Taro diff --git a/packages/taro-swan/src/index.js b/packages/taro-swan/src/index.js index e37a20738346..44a1e3423e29 100644 --- a/packages/taro-swan/src/index.js +++ b/packages/taro-swan/src/index.js @@ -23,6 +23,7 @@ import { createContext, memo } from '@tarojs/taro' +import { shallowEqual } from '@tarojs/utils' import Component from './component' import PureComponent from './pure-component' @@ -62,7 +63,8 @@ export const Taro = { useImperativeHandle, useContext, createContext, - memo + memo, + shallowEqual } export default Taro diff --git a/packages/taro-tt/src/index.js b/packages/taro-tt/src/index.js index 87336b9e0097..418cbe714337 100644 --- a/packages/taro-tt/src/index.js +++ b/packages/taro-tt/src/index.js @@ -23,6 +23,7 @@ import { createContext, memo } from '@tarojs/taro' +import { shallowEqual } from '@tarojs/utils' import Component from './component' import PureComponent from './pure-component' @@ -62,7 +63,8 @@ export const Taro = { useImperativeHandle, useContext, createContext, - memo + memo, + shallowEqual } export default Taro diff --git a/packages/taro-weapp/src/index.js b/packages/taro-weapp/src/index.js index ad8d06ded568..023f116d9622 100644 --- a/packages/taro-weapp/src/index.js +++ b/packages/taro-weapp/src/index.js @@ -23,6 +23,7 @@ import { createContext, memo } from '@tarojs/taro' +import { shallowEqual } from '@tarojs/utils' import Component from './component' import PureComponent from './pure-component' @@ -62,7 +63,8 @@ export const Taro = { useImperativeHandle, useContext, createContext, - memo + memo, + shallowEqual } export default Taro From 72849464e62393c58dacfed08e9db3eddc74ef64 Mon Sep 17 00:00:00 2001 From: yuche Date: Fri, 28 Jun 2019 17:36:19 +0800 Subject: [PATCH 077/158] =?UTF-8?q?perf(transformer):=20=08=08=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=8D=B8=E8=BD=BD=E6=97=B6=E6=B8=85=E7=90=86=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-alipay/src/create-component.js | 9 +++++-- packages/taro-qq/src/create-component.js | 8 ++++-- packages/taro-swan/src/create-component.js | 8 ++++-- .../taro-transformer-wx/src/render-props.ts | 26 +++++++++++++++++++ packages/taro-tt/src/create-component.js | 8 ++++-- packages/taro-weapp/src/create-component.js | 11 +++++--- 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/packages/taro-alipay/src/create-component.js b/packages/taro-alipay/src/create-component.js index f37fcbe64d1e..62703164150d 100644 --- a/packages/taro-alipay/src/create-component.js +++ b/packages/taro-alipay/src/create-component.js @@ -1,6 +1,6 @@ import { getCurrentPageUrl } from '@tarojs/utils' -import { commitAttachRef, detachAllRef, Current } from '@tarojs/taro' -import { isEmptyObject, isFunction } from './util' +import { commitAttachRef, detachAllRef, Current, eventCenter } from '@tarojs/taro' +import { isEmptyObject, isFunction, isArray } from './util' import { mountComponent } from './lifecycle' import { cacheDataSet, cacheDataGet, cacheDataHas } from './data-cache' import propsManager from './propsManager' @@ -286,6 +286,11 @@ function createComponent (ComponentClass, isPage) { onUnload () { componentTrigger(this.$component, 'componentWillUnmount') + const component = this.$component + const events = component.$$renderPropsEvents + if (isArray(events)) { + events.forEach(e => eventCenter.off(e)) + } }, onShow () { diff --git a/packages/taro-qq/src/create-component.js b/packages/taro-qq/src/create-component.js index 269c12b7d268..9c96bc7a920f 100644 --- a/packages/taro-qq/src/create-component.js +++ b/packages/taro-qq/src/create-component.js @@ -1,6 +1,6 @@ import { getCurrentPageUrl } from '@tarojs/utils' -import { commitAttachRef, detachAllRef, Current } from '@tarojs/taro' -import { isEmptyObject, isFunction } from './util' +import { commitAttachRef, detachAllRef, Current, eventCenter } from '@tarojs/taro' +import { isEmptyObject, isFunction, isArray } from './util' import { mountComponent } from './lifecycle' import { cacheDataSet, cacheDataGet, cacheDataHas } from './data-cache' import propsManager from './propsManager' @@ -345,6 +345,10 @@ function createComponent (ComponentClass, isPage) { hook.cleanup() } }) + const events = component.$$renderPropsEvents + if (isArray(events)) { + events.forEach(e => eventCenter.off(e)) + } } } if (isPage) { diff --git a/packages/taro-swan/src/create-component.js b/packages/taro-swan/src/create-component.js index 992e2762d05b..90c3f6ab758f 100644 --- a/packages/taro-swan/src/create-component.js +++ b/packages/taro-swan/src/create-component.js @@ -1,6 +1,6 @@ import { getCurrentPageUrl } from '@tarojs/utils' -import { commitAttachRef, detachAllRef, Current } from '@tarojs/taro' -import { isEmptyObject, isFunction } from './util' +import { commitAttachRef, detachAllRef, Current, eventCenter } from '@tarojs/taro' +import { isEmptyObject, isFunction, isArray } from './util' import { mountComponent } from './lifecycle' import { cacheDataGet, cacheDataHas } from './data-cache' import propsManager from './propsManager' @@ -287,6 +287,10 @@ function createComponent (ComponentClass, isPage) { hook.cleanup() } }) + const events = component.$$renderPropsEvents + if (isArray(events)) { + events.forEach(e => eventCenter.off(e)) + } } } if (isPage) { diff --git a/packages/taro-transformer-wx/src/render-props.ts b/packages/taro-transformer-wx/src/render-props.ts index 7f6843b6c6ff..e76855ec74ea 100644 --- a/packages/taro-transformer-wx/src/render-props.ts +++ b/packages/taro-transformer-wx/src/render-props.ts @@ -6,6 +6,8 @@ import { get as safeGet } from 'lodash' const renderPropsMap = new Map() +const RENDER_PROPS_EVENTS = '$$renderPropsEvents' + export function injectRenderPropsListener (attrPath: NodePath, attrName: string, attrExpr: t.ArrowFunctionExpression, componentName: string) { const randomLetters = createRandomLetters(5) const renderClosureFuncName = attrName + randomLetters @@ -21,6 +23,30 @@ export function injectRenderPropsListener (attrPath: NodePath, a stemParent.insertBefore(listener) stemParent.insertBefore(jsxDecl) attrPath.get('value').replaceWith(t.jSXExpressionContainer(block)) + setRenderPropsEvents(attrPath, renderClosureFuncName) +} + +function setRenderPropsEvents (attrPath: NodePath, renderClosureFuncName: string) { + const classDecl = attrPath.findParent(p => p.isClassDeclaration()) + if (classDecl && classDecl.isClassDeclaration()) { + let hasEvent = false + for (const s of classDecl.node.body.body) { + if (t.isClassProperty(s) && s.key.name === RENDER_PROPS_EVENTS && t.isArrayExpression(s.value)) { + hasEvent = true + if (s.value.elements.some(e => t.isStringLiteral(e) && e.value === renderClosureFuncName)) { + break + } + s.value.elements.push(t.stringLiteral(renderClosureFuncName)) + } + } + + if (!hasEvent) { + classDecl.node.body.body.push(t.classProperty( + t.identifier(RENDER_PROPS_EVENTS), + t.arrayExpression([t.stringLiteral(renderClosureFuncName)]) + )) + } + } } export function injectRenderPropsEmiter (callExpr: NodePath, attrName: string) { diff --git a/packages/taro-tt/src/create-component.js b/packages/taro-tt/src/create-component.js index 8cbc44ee690a..27b0a3151eb6 100644 --- a/packages/taro-tt/src/create-component.js +++ b/packages/taro-tt/src/create-component.js @@ -1,6 +1,6 @@ import { getCurrentPageUrl } from '@tarojs/utils' -import { commitAttachRef, detachAllRef, Current } from '@tarojs/taro' -import { isEmptyObject, isFunction } from './util' +import { commitAttachRef, detachAllRef, Current, eventCenter } from '@tarojs/taro' +import { isEmptyObject, isFunction, isArray } from './util' import { mountComponent } from './lifecycle' import { cacheDataSet, cacheDataGet, cacheDataHas } from './data-cache' import propsManager from './propsManager' @@ -317,6 +317,10 @@ function createComponent (ComponentClass, isPage) { hook.cleanup() } }) + const events = component.$$renderPropsEvents + if (isArray(events)) { + events.forEach(e => eventCenter.off(e)) + } } } if (isPage) { diff --git a/packages/taro-weapp/src/create-component.js b/packages/taro-weapp/src/create-component.js index e53f5a174cfa..1f993414fe70 100644 --- a/packages/taro-weapp/src/create-component.js +++ b/packages/taro-weapp/src/create-component.js @@ -1,9 +1,8 @@ import { getCurrentPageUrl } from '@tarojs/utils' -import { commitAttachRef, detachAllRef, Current } from '@tarojs/taro' -import { isEmptyObject, isFunction } from './util' -import { mountComponent } from './lifecycle' +import { commitAttachRef, detachAllRef, Current, eventCenter } from '@tarojs/taro' +import { isEmptyObject, isFunction, isArray } from './util' +import { mountComponent, updateComponent } from './lifecycle' import { cacheDataSet, cacheDataGet, cacheDataHas } from './data-cache' -import { updateComponent } from './lifecycle' import nextTick from './next-tick' import propsManager from './propsManager' @@ -369,6 +368,10 @@ function createComponent (ComponentClass, isPage) { hook.cleanup() } }) + const events = component.$$renderPropsEvents + if (isArray(events)) { + events.forEach(e => eventCenter.off(e)) + } } } if (isPage) { From 7ea3f37549581758f844784700d2f33b8dca8413 Mon Sep 17 00:00:00 2001 From: Tom Huang Date: Sun, 30 Jun 2019 17:24:54 +0800 Subject: [PATCH 078/158] =?UTF-8?q?fix(rn):=20=E5=AF=BC=E5=87=BA=20hooks?= =?UTF-8?q?=20=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=20RN=20=E7=AB=AF=E6=8E=A5=E5=8F=A3=E6=9C=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E9=97=AE=E9=A2=98=20(#3579)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-rn/src/index.ts | 36 +++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/taro-rn/src/index.ts b/packages/taro-rn/src/index.ts index dedb36604ddf..632b4217f666 100644 --- a/packages/taro-rn/src/index.ts +++ b/packages/taro-rn/src/index.ts @@ -12,6 +12,20 @@ import { import initNativeApi from './native-api' import { Component, PureComponent } from './component' +import { + createContext, + useState, + useEffect, + useReducer, + useCallback, + useMemo, + useRef, + useLayoutEffect, + useContext +} from 'react' + +import { permanentlyNotSupport } from '../api/utils' + const Taro = { getEnv, ENV_TYPE, @@ -22,7 +36,16 @@ const Taro = { internal_safe_get, internal_safe_set, Component, - PureComponent + PureComponent, + createContext, + useState, + useEffect, + useReducer, + useCallback, + useMemo, + useRef, + useLayoutEffect, + useContext } export { @@ -35,7 +58,16 @@ export { internal_safe_get, internal_safe_set, Component, - PureComponent + PureComponent, + createContext, + useState, + useEffect, + useReducer, + useCallback, + useMemo, + useRef, + useLayoutEffect, + useContext } initNativeApi(Taro) From d78ee160922e946168f627904693b2ebe8ac261a Mon Sep 17 00:00:00 2001 From: Kan Chen Date: Sun, 30 Jun 2019 17:26:19 +0800 Subject: [PATCH 079/158] =?UTF-8?q?feat(cli):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E5=8D=8E=E4=B8=BA=E5=8E=9F=E5=AD=90=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=96=87=E4=BB=B6=E7=9A=84=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=20(#3571)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加对华为原子服务定义文件的规范检查 * 检查原子服务定义文件前增加对应用类型的判断,只对快应用进行检查 --- packages/taro-cli/bin/taro-doctor | 5 +++ .../src/doctor/abilityXMLValidator.ts | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 packages/taro-cli/src/doctor/abilityXMLValidator.ts diff --git a/packages/taro-cli/bin/taro-doctor b/packages/taro-cli/bin/taro-doctor index 9801ac55a135..a1b259cc717e 100755 --- a/packages/taro-cli/bin/taro-doctor +++ b/packages/taro-cli/bin/taro-doctor @@ -16,6 +16,11 @@ if (!fs.existsSync(PROJECT_CONF_PATH)) { } const { validators } = require('../dist/doctor').default +const abilityXMLValidator = require('../dist/doctor/abilityXMLValidator').default +const QUICKAPP_CONF_PATH = path.join(appPath, 'project.quickapp.json') +if (fs.existsSync(QUICKAPP_CONF_PATH)) { + validators.push(abilityXMLValidator) +} const NOTE_ALL_RIGHT = chalk.green('[✓] ') const NOTE_VALID = chalk.yellow('[!] ') diff --git a/packages/taro-cli/src/doctor/abilityXMLValidator.ts b/packages/taro-cli/src/doctor/abilityXMLValidator.ts new file mode 100644 index 000000000000..d620acb15ccc --- /dev/null +++ b/packages/taro-cli/src/doctor/abilityXMLValidator.ts @@ -0,0 +1,34 @@ +import * as _ from 'lodash/fp' +import * as fs from 'fs-extra' +import * as path from 'path' +import chalk from 'chalk' + +import { IErrorLine } from './interface' + +const ABILITYXML = ['ability.xml'] + +export default async function ({ appPath }) { + const PROJECT_PACKAGE_PATH = path.join(appPath, 'package.json') + const PROJECT_FOLDER_FILES = fs.readdirSync('./') + if (!fs.existsSync(PROJECT_PACKAGE_PATH)) { + console.log(chalk.red(`找不到${PROJECT_PACKAGE_PATH},请确定当前目录是Taro项目根目录!`)) + process.exit(1) + } + + const inProjectFolder = filenames => (_.intersectionBy(_.toLower, PROJECT_FOLDER_FILES, filenames)).length > 0 + const hasAbilityXML = inProjectFolder(ABILITYXML) + + const errorLines: IErrorLine[] = [] + + if (!hasAbilityXML) { + errorLines.push({ + desc: '没有检查到 ability.xml, 编写 ability.xml可以让其他应用方便地叫起应用内服务', + valid: true + }) + } + + return { + desc: '检查原子化服务规范', + lines: errorLines + } +} From 0418ee274d703eaa42890ba4edfa14fe796068fe Mon Sep 17 00:00:00 2001 From: Isaac Young Date: Mon, 1 Jul 2019 10:37:57 +0800 Subject: [PATCH 080/158] chore(transformer): use shorthand name in render (#3107) --- packages/taroize/src/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/taroize/src/utils.ts b/packages/taroize/src/utils.ts index cf46febf2acb..802ff01d2530 100644 --- a/packages/taroize/src/utils.ts +++ b/packages/taroize/src/utils.ts @@ -79,7 +79,7 @@ export function buildRender ( const stateDecl = t.variableDeclaration('const', [ t.variableDeclarator( t.objectPattern(Array.from(new Set(stateKeys)).filter(s => !propsKeys.includes(s)).map(s => - t.objectProperty(t.identifier(s), t.identifier(s)) + t.objectProperty(t.identifier(s), t.identifier(s), false, true) ) as any), t.memberExpression(t.thisExpression(), t.identifier('state')) ) @@ -89,7 +89,7 @@ export function buildRender ( if (propsKeys.length) { let patterns = t.objectPattern(Array.from(new Set(propsKeys)).map(s => - t.objectProperty(t.identifier(s), t.identifier(s)) + t.objectProperty(t.identifier(s), t.identifier(s), false, true) ) as any) if (typeof templateType === 'string') { patterns = t.objectPattern([ From 19eef476e06b42f4aa6617ea64fee95ce70da8fe Mon Sep 17 00:00:00 2001 From: onelong Date: Mon, 1 Jul 2019 10:38:42 +0800 Subject: [PATCH 081/158] =?UTF-8?q?fix(taro):=20=E5=9C=A8memo=E4=B8=AD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9state=E7=9A=84=E6=B5=85=E5=88=A4?= =?UTF-8?q?=E6=96=AD=20(#3563)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #3527 --- packages/taro/src/memo.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/taro/src/memo.js b/packages/taro/src/memo.js index 5f1266b25a8a..90d06ff3e98d 100644 --- a/packages/taro/src/memo.js +++ b/packages/taro/src/memo.js @@ -1,8 +1,11 @@ import { isFunction, objectIs } from './util' export function memo (component, propsAreEqual) { - component.prototype.shouldComponentUpdate = function (nextProps) { - return isFunction(propsAreEqual) ? !propsAreEqual(this.props, nextProps) : !objectIs(this.props, nextProps) + component.prototype.shouldComponentUpdate = function (nextProps, nextState) { + return ( + (isFunction(propsAreEqual) ? !propsAreEqual(this.props, nextProps) : !objectIs(this.props, nextProps)) && + !objectIs(this.state, nextState) + ) } return component From d9d9f686308c9d82066d3e86ba3686e5088ce77b Mon Sep 17 00:00:00 2001 From: sqlwwx Date: Mon, 1 Jul 2019 01:46:29 -0500 Subject: [PATCH 082/158] =?UTF-8?q?fix(taro-cli):=20=E5=B0=BD=E6=97=A9?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEwatch=E4=B8=8B=E7=9A=84NODE=5FENV=E4=B8=BAdev?= =?UTF-8?q?elopment=20(#3583)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/bin/taro-build | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/taro-cli/bin/taro-build b/packages/taro-cli/bin/taro-build index 4e64438fa681..fdb7bd92071d 100755 --- a/packages/taro-cli/bin/taro-build +++ b/packages/taro-cli/bin/taro-build @@ -25,6 +25,16 @@ let { env, plugin } = program env = process.env.NODE_ENV || env +if (env) { + process.env.NODE_ENV = env +} else { + if (watch) { + process.env.NODE_ENV = 'development' + } else { + process.env.NODE_ENV = 'production' + } +} + if (ui) { console.log(chalk.green(`开始编译 UI 库`)) build(appPath, { @@ -51,16 +61,6 @@ if (!fs.existsSync(projectConfPath)) { process.exit(1) } -if (env) { - process.env.NODE_ENV = env -} else { - if (watch) { - process.env.NODE_ENV = 'development' - } else { - process.env.NODE_ENV = 'production' - } -} - process.env.TARO_ENV = type const projectConf = require(projectConfPath)(_.merge) From 16b261366dd754551233c906db5dadf9a80143e4 Mon Sep 17 00:00:00 2001 From: Jay Fong Date: Mon, 1 Jul 2019 14:52:58 +0800 Subject: [PATCH 083/158] =?UTF-8?q?feat(taro-components):=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84=20Form=20=E7=BB=84=E4=BB=B6=E7=9A=84=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E4=B9=89=20(#2951)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-components/types/Form.d.ts | 34 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/packages/taro-components/types/Form.d.ts b/packages/taro-components/types/Form.d.ts index a592d76ce6c2..0472ba27ad56 100644 --- a/packages/taro-components/types/Form.d.ts +++ b/packages/taro-components/types/Form.d.ts @@ -3,21 +3,49 @@ import { StandardProps, CommonEventFunction } from './common' export interface FormProps extends StandardProps { /** - * 是否返回 formId 用于发送模板消息 + * 是否返回 `formId` 用于发送模板消息。 + * + * @default false */ reportSubmit?: boolean, + /** + * 等待一段时间(毫秒数)以确认 `formId` 是否生效。 + * 如果未指定这个参数,`formId` 有很小的概率是无效的(如遇到网络失败的情况)。 + * 指定这个参数将可以检测 `formId` 是否有效, + * 以这个参数的时间作为这项检测的超时时间。 + * 如果失败,将返回 `requestFormId:fail` 开头的 `formId`。 + * + * @default 0 + * + * @since 2.6.2 + */ + reportSubmitTimeout?: number, + /** * 携带 form 中的数据触发 submit 事件 * * event.detail = {value : {'name': 'value'} , formId: ''} */ - onSubmit?: CommonEventFunction, + onSubmit?: CommonEventFunction<{ + /** + * 当点击 `
` 表单中 `form-type` 为 `submit` 的 ` + + + {counter} + + ) +} - componentDidMount () {} +export default observer(Index) +``` - componentDidShow () {} +### useAsObservableSource - componentDidHide () {} +> 自 `1.3.6` 开始支持 - componentDidCatchError () {} +与 `useLocalStore` 的区别是,它将纯(不包含 `getter` 或方法)对象转换为 `observable`,主要使用场景为: - render () { +* 如果对象某个属性的值需经过复杂运算才能获得,可通过该方法进行包装,这样在组件的生命周期中该运算只需要运算一次。 +* 一般情况下 `useLocalStore` 仅用于组件内部,如果 `useLocalStore` 中的对象需要依赖外部传递的属性,那么可通过 + `useAsObservableSource` 将这些属性进行转换,而后在 `useLocalStore` 对象中进行引用,这样在外部属性改变时自动通知 + `useLocalStore` 对象对变化进行响应,比如: + + ```jsx + import Taro from '@tarojs/taro' + import { View, Button, Text } from '@tarojs/components' + import { useAsObservableSource, useLocalStore, observer } from '@tarojs/mobx' + + function Multiplier(props) { + const observableProps = useAsObservableSource(props) + const store = useLocalStore(() => ({ + counter: 1, + get multiplied() { + return observableProps.multiplier * store.counter + }, + increment() { + store.counter += 1 + } + })) + const { multiplier } = observableProps + const { multiplied, counter, increment } = store return ( - - - + + multiplier({multiplier}) * counter({counter}) = {multiplied} + + ) } -} -Taro.render(, document.getElementById('app')) + export default observer(Multiplier) + ``` -``` + 该场景也可直接使用 `useLocalStore` 中的第二种用法来实现: -然后,我们在页面中可通过 `@tarojs/mobx` 提供的 `inject` 以及 `observer` 方法将 `mobx` 与我们的页面进行关联 + ```jsx + import Taro from '@tarojs/taro' + import { View, Button, Text } from '@tarojs/components' + import { useLocalStore, observer } from '@tarojs/mobx' + + function Multiplier(props) { + const store = useLocalStore(source => ({ + counter: 1, + + get multiplier() { + return source.multiplier + }, + + get multiplied() { + return source.multiplier * store.counter + }, + increment() { + store.counter += 1 + } + }), props) + const { multiplied, counter, increment, multiplier } = store + return ( + + multiplier({multiplier}) * counter({counter}) = {multiplied} + + + ) + } -```jsx -// src/pages/index/index.js -import Taro, { Component } from '@tarojs/taro' -import { View, Button, Text } from '@tarojs/components' -import { observer, inject } from '@tarojs/mobx' + export default observer(Multiplier) + ``` -import './index.scss' +### observer -@inject('counterStore') -@observer -class Index extends Component { +将组件设置为监听者,以便在可观察对象的值改变后触发页面的重新渲染。 - config = { - navigationBarTitleText: '首页' - } +注: - componentWillMount () { - console.log('componentWillMount') - } +* 不要在 `JSX` 中对可观察对象进行引用,比如: - /** - * 该方法将在 observable 对象更新时触发 - */ - componentWillReact () { - console.log('componentWillReact') - } + ```jsx + // 错误,在小程序中值改变后将无法触发重新渲染 + const { counterStore } = this.props + return ( + {counterStore.counter} + ) - componentDidMount () { - console.log('componentDidMount') - } + // 正确 + const { counterStore: { counter } } = this.props + return ( + {counter} + ) + ``` - componentWillUnmount () { - console.log('componentWillUnmount') - } + > 这是因为 `@tarojs/mobx` 通过监听组件的 `render`(小程序编译后为 `_createData`)方法来触发更新;在小程序中,`JSX` + > 的代码会被编译到 `wxml` 文件中,此时对可观察对象的引用(比如:`counterStore.counter`)早已脱离了 + > `@tarojs/mobx` 的监控,故此对该属性的更改并不会触发更新操作。 - componentDidShow () { - console.log('componentDidShow') - } +* 如使用 `@observable` 装饰器来定义可观察对象时,请确保该属性已经初始化,比如: - componentDidHide () { - console.log('componentDidHide') - } + ```js + @observable counter // 错误,值改变后将无法触发重新渲染 + @observable counter = 0 // 正确 + ``` - increment = () => { - const { counterStore } = this.props - counterStore.increment() - } +* 如果 `isUsingStaticRendering` 为 `true`,该方法不做任何事情。 - decrement = () => { - const { counterStore } = this.props - counterStore.decrement() - } +### Provider + +全局 `store` 设置,比如: + +```jsx +import Taro, { Component } from '@tarojs/taro' +import { Provider } from '@tarojs/mobx' +import Index from './pages/index' +import counterStore from './store/counter' - incrementAsync = () => { - const { counterStore } = this.props - counterStore.incrementAsync() +const store = { + counterStore +} + +class App extends Component { + config = { + pages: [ + 'pages/index/index' + ], + window: { + backgroundTextStyle: 'light', + navigationBarBackgroundColor: '#fff', + navigationBarTitleText: 'WeChat', + navigationBarTextStyle: 'black' + } } render () { - const { counterStore: { counter } } = this.props return ( - - - - - {counter} - + + + ) } } -export default Index - +Taro.render(, document.getElementById('app')) ``` -上例中 `Provider`、`inject`、 `observer`、`onError` 的使用方式基本上与 [mobx-react](https://github.com/mobxjs/mobx-react) 保持了一致,但也有以下几点需要注意: +注: -* `Provider` 不支持嵌套,即全局只能存在一个 `Provider` +* `Provider` 必须作用于入口文件(即:`src/app.js`),在其他地方使用无效。 +* 不支持嵌套,即全局只能存在一个 `Provider`。 * 在 `mobx-react` 中,可通过以下方式设置 `store`: ```jsx @@ -198,52 +268,76 @@ export default Index ``` -* `inject`、 `observer` 不能在 stateless 组件上使用 -* `observer` 不支持任何参数 -* 按照以下方式使用 `inject` 时,不能省略 `observer` 的显式调用: - ```jsx - @inject((stores, props) => ({ - counterStore: stores.counterStore - })) - @observer //这个不能省略 - ``` +### inject -注意事项: +将 `Provider` 中设置的 `store` 提取到组件的 `props` 中,该 `API` 只适用于`类组件`,比如: -* 在 `Component` 的 `render` 方法中,如果需要使用一个 `observable` 对象(该例中为 `counter`),您需要: +```jsx +import Taro, { Component } from '@tarojs/taro' +import { observer, inject } from '@tarojs/mobx' - ```js - const { counterStore: { counter } } = this.props - return ( - {counter} - ) - ``` +import './index.scss' - 而非: +@inject('counterStore') +@observer +class Index extends Component { + //... +} - ```js - const { counterStore } = this.props - return ( - {counterStore.counter} - ) - ``` +export default Index +``` -* 如果使用 `@observable` 装饰器来定义可观察对象时,请确保该属性已经初始化(这是很多情况下属性值改变,页面没刷新的根源所在),比如: +或 - ```js - @observable counter // 错误 - @observable counter = 0 // 正确 - ``` +```jsx +import Taro, { Component } from '@tarojs/taro' +import { observer, inject } from '@tarojs/mobx' -* 自 `1.2.0-beta.5` 后,`propTypes` 已从 `taro-mobx`、`taro-mobx-h5`、`taro-mobx-rn` 中剥离,如需使用,请单独进行安装: +import './index.scss' + +@inject((stores, props) => ({ + counterStore: stores.counterStore +})) +@observer +class Index extends Component { + //... +} - ```bash - $ yarn add @tarojs/mobx-prop-types - # 或者使用 npm - $ npm install --save @tarojs/mobx-prop-types +export default Index +``` + +注: + +* 无论以何种方式使用 `inject`,其后的 `observer` 均不能省略。 +* 不要在 `inject` 中引用可观察对象,这将导致属性改变后页面不更新,比如: + + ```jsx + // 错误 + @inject((stores, props) => ({ + counter: stores.counterStore.counter + })) + + // 正确 + @inject((stores, props) => ({ + counterStore: stores.counterStore + })) ``` - `propTypes` 使用与 [mobx-react](https://github.com/mobxjs/mobx-react#proptypes) 一致 +### PropTypes + +> 自 `1.3.6` 开始支持 + +`@tarojs/mobx` 提供了以下 `PropTypes` 来验证 Mobx 的结构: + +* observableArray +* observableArrayOf +* observableMap +* observableObject +* arrayOrObservableArray +* arrayOrObservableArrayOf +* objectOrObservableObject + +## 资源 - > 注:自 `1.2.27-beta.0` 后,`@tarojs/mobx-prop-types` 已被移除,请使用 [mobx-react](https://github.com/mobxjs/mobx-react#proptypes) 替代。 +示例:[taro-mobx-sample](https://github.com/nanjingboy/taro-mobx-sample) \ No newline at end of file diff --git a/packages/taro-cli/src/util/constants.ts b/packages/taro-cli/src/util/constants.ts index a7989121ffad..65d91e8e06cb 100644 --- a/packages/taro-cli/src/util/constants.ts +++ b/packages/taro-cli/src/util/constants.ts @@ -308,7 +308,6 @@ export const UPDATE_PACKAGE_LIST = [ '@tarojs/mobx-h5', '@tarojs/mobx-rn', '@tarojs/mobx-common', - '@tarojs/mobx-prop-types', 'nervjs', 'nerv-devtools' ] diff --git a/packages/taro-cli/templates/mobx/appjs b/packages/taro-cli/templates/mobx/appjs index 9fd5bc8c8820..0b8570d27147 100644 --- a/packages/taro-cli/templates/mobx/appjs +++ b/packages/taro-cli/templates/mobx/appjs @@ -3,11 +3,8 @@ import Taro, { Component, Config } from '@tarojs/taro' <%} else { -%> import Taro, { Component } from '@tarojs/taro' <%}-%> -import { Provider } from '@tarojs/mobx' import Index from './pages/index' -import counterStore from './store/counter' - import './app.<%= css %>' // 如果需要在 h5 环境中开启 React Devtools @@ -16,10 +13,6 @@ import './app.<%= css %>' // require('nerv-devtools') // } -const store = { - counterStore -} - class App extends Component { <%if (locals.typescript) {-%> @@ -55,9 +48,7 @@ class App extends Component { // 请勿修改此函数 render () { return ( - - - + ) } } diff --git a/packages/taro-cli/templates/mobx/index.js b/packages/taro-cli/templates/mobx/index.js index c74ef2482c13..9f0ecad895df 100644 --- a/packages/taro-cli/templates/mobx/index.js +++ b/packages/taro-cli/templates/mobx/index.js @@ -133,11 +133,6 @@ exports.createApp = function (creator, params, helper, cb) { }) creator.template(template, path.join(configDirName, 'dev'), path.join(configDir, 'dev.js')) creator.template(template, path.join(configDirName, 'prod'), path.join(configDir, 'prod.js')) - if (typescript) { - creator.template(template, path.join('store', 'counterjs'), path.join(sourceDir, 'store', 'counter.ts')) - } else { - creator.template(template, path.join('store', 'counterjs'), path.join(sourceDir, 'store', 'counter.js')) - } if (useNpmrc) creator.template(template, 'npmrc', path.join(projectPath, '.npmrc')) if (useYarnLock) creator.template(template, yarnLockfilePath, path.join(projectPath, 'yarn.lock')) creator.fs.commit(() => { @@ -146,13 +141,10 @@ exports.createApp = function (creator, params, helper, cb) { console.log(`${chalk.green('✔ ')}${chalk.grey(`创建配置目录: ${projectName}/${configDirName}`)}`) console.log(`${chalk.green('✔ ')}${chalk.grey(`创建源码目录: ${projectName}/${src}`)}`) console.log(`${chalk.green('✔ ')}${chalk.grey(`创建页面目录: ${projectName}/${src}/pages`)}`) - console.log(`${chalk.green('✔ ')}${chalk.grey(`创建 store 目录: ${projectName}/${src}/store`)}`) if (typescript) { console.log(`${chalk.green('✔ ')}${chalk.grey(`创建页面 JS 文件: ${projectName}/${src}/pages/index/index.tsx`)}`) - console.log(`${chalk.green('✔ ')}${chalk.grey(`创建 store TS 文件: ${projectName}/${src}/store/counter.ts`)}`) } else { console.log(`${chalk.green('✔ ')}${chalk.grey(`创建页面 JS 文件: ${projectName}/${src}/pages/index/index.js`)}`) - console.log(`${chalk.green('✔ ')}${chalk.grey(`创建 store JS 文件: ${projectName}/${src}/store/counter.js`)}`) } console.log(`${chalk.green('✔ ')}${chalk.grey(`创建页面 ${currentStyleExt.toLocaleUpperCase()} 文件: ${projectName}/${src}/pages/index/${pageCSSName}`)}`) if (typescript) { diff --git a/packages/taro-cli/templates/mobx/pagejs b/packages/taro-cli/templates/mobx/pagejs index 47c6ab437d3b..78cd39f31def 100644 --- a/packages/taro-cli/templates/mobx/pagejs +++ b/packages/taro-cli/templates/mobx/pagejs @@ -1,86 +1,32 @@ -<%if (locals.typescript) {-%> -import { ComponentType } from 'react' -import Taro, { Component, Config } from '@tarojs/taro' -<%} else { -%> -import Taro, { Component } from '@tarojs/taro' -<%}-%> -import { View, Button, Text } from '@tarojs/components' -import { observer, inject } from '@tarojs/mobx' +import Taro from '@tarojs/taro' +import { View, Text, Button } from '@tarojs/components' +import { useLocalStore, observer } from '@tarojs/mobx' import './<%= pageName %>.<%= css %>' -<%if (locals.typescript) {-%> -type PageStateProps = { - counterStore: { - counter: number, - increment: Function, - decrement: Function, - incrementAsync: Function - } +function Index() { + const store = useLocalStore(() => ({ + counter: 0, + increment() { + store.counter++ + }, + decrement() { + store.counter-- + }, + incrementAsync() { + setTimeout(() => store.counter++, 1000) + } + })) + + const { counter, increment, decrement, incrementAsync } = store; + return ( + + + + + {counter} + + ) } -interface <%= _.capitalize(pageName) %> { - props: PageStateProps; -} -<%}-%> - -@inject('counterStore') -@observer -class <%= _.capitalize(pageName) %> extends Component { - -<%if (locals.typescript) {-%> - /** - * 指定config的类型声明为: Taro.Config - * - * 由于 typescript 对于 object 类型推导只能推出 Key 的基本类型 - * 对于像 navigationBarTextStyle: 'black' 这样的推导出的类型是 string - * 提示和声明 navigationBarTextStyle: 'black' | 'white' 类型冲突, 需要显示声明类型 - */ -<%}-%> - config<%if (locals.typescript) {%>: Config<%}%> = { - navigationBarTitleText: '首页' - } - - componentWillMount () { } - - componentWillReact () { - console.log('componentWillReact') - } - - componentDidMount () { } - - componentWillUnmount () { } - - componentDidShow () { } - - componentDidHide () { } - - increment = () => { - const { counterStore } = this.props - counterStore.increment() - } - - decrement = () => { - const { counterStore } = this.props - counterStore.decrement() - } - - incrementAsync = () => { - const { counterStore } = this.props - counterStore.incrementAsync() - } - - render () { - const { counterStore: { counter } } = this.props - return ( - - - - - {counter} - - ) - } -} - -export default <%= _.capitalize(pageName) %> <%if (locals.typescript) {%> as ComponentType<%}%> +export default observer(Index) \ No newline at end of file diff --git a/packages/taro-cli/templates/mobx/store/counterjs b/packages/taro-cli/templates/mobx/store/counterjs deleted file mode 100644 index bc2b1983ae2a..000000000000 --- a/packages/taro-cli/templates/mobx/store/counterjs +++ /dev/null @@ -1,20 +0,0 @@ -import { observable } from 'mobx' - -const counterStore = observable({ - counter: 0, - counterStore() { - this.counter++ - }, - increment() { - this.counter++ - }, - decrement() { - this.counter-- - }, - incrementAsync() { - setTimeout(() => { - this.counter++ - }, 1000) - } -}) -export default counterStore \ No newline at end of file diff --git a/packages/taro-mobx-common/src/index.js b/packages/taro-mobx-common/src/index.js index 0a94c3e1eac5..462df39009d0 100755 --- a/packages/taro-mobx-common/src/index.js +++ b/packages/taro-mobx-common/src/index.js @@ -2,6 +2,12 @@ import { errorsReporter } from './reporter' export const onError = fn => errorsReporter.on(fn) -export * from './inject' +export { PropTypes } from "./propTypes" + export { observer } from './observer' -export { getStore, setStore } from './store' \ No newline at end of file +export { useLocalStore } from './useLocalStore' +export { useAsObservableSource } from './useAsObservableSource' +export { isUsingStaticRendering, useStaticRendering } from './staticRendering' + +export { getStore, setStore } from './store' +export { inject, getInjectName, mapStoreToProps } from './inject' diff --git a/packages/taro-mobx-common/src/inject.js b/packages/taro-mobx-common/src/inject.js index 77b8d57f9116..4594e91e9f5a 100755 --- a/packages/taro-mobx-common/src/inject.js +++ b/packages/taro-mobx-common/src/inject.js @@ -17,31 +17,16 @@ function grabStoresByName (storeNames) { } } -export function generateDisplayName (sourceComponent, injectNames) { - let displayName = - 'inject-' + - (sourceComponent.displayName || - sourceComponent.name || - (sourceComponent.constructor && sourceComponent.constructor.name) || - 'Unknown') - if (injectNames) { - displayName += '-with-' + injectNames - } - return displayName +export function getInjectName (component, injectNames) { + const componentName = component.displayName || component.name || 'Component' + if (injectNames) { + return `inject-with-${injectNames}(${componentName})` + } + return `inject(${componentName})` } export function mapStoreToProps (grabStoresFn, props) { - let newProps = {} - for (let key in props) { - if (props.hasOwnProperty(key)) { - newProps[key] = props[key] - } - } - const additionalProps = grabStoresFn(getStore() || {}, newProps) || {} - for (let key in additionalProps) { - newProps[key] = additionalProps[key] - } - return newProps + return Object.assign({}, grabStoresFn(getStore() || {}, props || {}) || {}) } export function inject (/* fn(stores, nextProps) or ...storeNames, createStoreInjector */) { @@ -62,4 +47,4 @@ export function inject (/* fn(stores, nextProps) or ...storeNames, createStoreIn return createStoreInjector(grabStoresFn, storeNames.join('-'), componentClass) } } -} \ No newline at end of file +} diff --git a/packages/taro-mobx-common/src/observer.js b/packages/taro-mobx-common/src/observer.js old mode 100755 new mode 100644 index 41867dbccd40..645b31e2034e --- a/packages/taro-mobx-common/src/observer.js +++ b/packages/taro-mobx-common/src/observer.js @@ -1,56 +1,46 @@ -import { Reaction, _allowStateChanges } from 'mobx' +import { Reaction } from 'mobx' +import { isMiniPlatform } from './utils' import { errorsReporter } from './reporter' +import { isUsingStaticRendering } from './staticRendering' -function isStateless (component, renderMedthod) { - return !(component.prototype && component.prototype[renderMedthod]) -} - -export function observer (Component, renderMedthod) { - if (typeof Component !== 'function' || isStateless(Component, renderMedthod)) { - throw new Error("Please pass a valid component to 'observer'") +export function observer (component) { + if (isUsingStaticRendering()) { + return component } - if (Component.isMobxInjector === true) { + if (component.isMobxInjector === true) { console.warn( "Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'" ) } - class ObserverComponent extends Component { - componentWillMount () { - const initialName = - this.displayName || - this.name || - (this.constructor && (this.constructor.displayName || this.constructor.name)) || - '' - this._reaction = new Reaction(`${initialName}_${Date.now()}`, () => { - if (typeof this.componentWillReact === 'function') { - this.componentWillReact() - } - this.forceUpdate() - }) - if (typeof super.componentWillMount === 'function') { - super.componentWillMount() - } - } + const target = component.prototype + const originComponentWillMount = target.componentWillMount + const originComponentWillReact = target.componentWillReact + target.componentWillMount = function () { + const initialName = this.displayName || this.name + this._reaction = new Reaction(`${initialName}_${Date.now()}`, () => { + this.forceUpdate() + originComponentWillReact && originComponentWillReact.call(this) + }) + originComponentWillMount && originComponentWillMount.call(this) + } - componentWillUnmount () { - this._reaction.dispose() - if (typeof super.componentWillUnmount === 'function') { - super.componentWillUnmount() - } - } + const originComponentWillUnmount = target.componentWillUnmount + target.componentWillUnmount = function () { + this._reaction.dispose() + originComponentWillUnmount && originComponentWillUnmount.call(this) } - const target = ObserverComponent.prototype - const originRender = target[renderMedthod] - target[renderMedthod] = function (...args) { + const renderMethod = isMiniPlatform() ? '_createData' : 'render' + const originRender = target[renderMethod] + target[renderMethod] = function (...args) { let result let exception - if (this._reaction && this._reaction instanceof Reaction) { + if (this._reaction instanceof Reaction) { this._reaction.track(() => { try { - result = _allowStateChanges(false, () => originRender.call(this, null, null, args[2])) + result = originRender.call(this, null, null, args[2]) } catch (e) { exception = e } @@ -65,5 +55,5 @@ export function observer (Component, renderMedthod) { return result } - return ObserverComponent + return component } diff --git a/packages/taro-mobx-common/src/propTypes.js b/packages/taro-mobx-common/src/propTypes.js new file mode 100644 index 000000000000..8993ad81d859 --- /dev/null +++ b/packages/taro-mobx-common/src/propTypes.js @@ -0,0 +1,187 @@ +import { isObservableArray, isObservableObject, isObservableMap, untracked } from 'mobx' + +// Copied from React.PropTypes +function createChainableTypeChecker (validate) { + function checkType ( + isRequired, + props, + propName, + componentName, + location, + propFullName, + ...rest + ) { + return untracked(() => { + componentName = componentName || '<>' + propFullName = propFullName || propName + if (props[propName] == null) { + if (isRequired) { + const actual = props[propName] === null ? 'null' : 'undefined' + return new Error( + 'The ' + location + ' `' + propFullName + '` is marked as required ' + + 'in `' + componentName + '`, but its value is `' + actual + '`.' + ) + } + return null + } else { + return validate(props, propName, componentName, location, propFullName, ...rest) + } + }) + } + + const chainedCheckType = checkType.bind(null, false) + chainedCheckType.isRequired = checkType.bind(null, true) + return chainedCheckType +} + +// Copied from React.PropTypes +function isSymbol (propType, propValue) { + // Native Symbol. + if (propType === 'symbol') { + return true + } + + // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' + if (propValue['@@toStringTag'] === 'Symbol') { + return true + } + + // Fallback for non-spec compliant Symbols which are polyfilled. + if (typeof Symbol === 'function' && propValue instanceof Symbol) { + return true + } + + return false +} + +// Copied from React.PropTypes +function getPropType (propValue) { + const propType = typeof propValue + if (Array.isArray(propValue)) { + return 'array' + } + if (propValue instanceof RegExp) { + // Old webkits (at least until Android 4.0) return 'function' rather than + // 'object' for typeof a RegExp. We'll normalize this here so that /bla/ + // passes PropTypes.object. + return 'object' + } + if (isSymbol(propType, propValue)) { + return 'symbol' + } + return propType +} + +// This handles more types than `getPropType`. Only used for error messages. +// Copied from React.PropTypes +function getPreciseType (propValue) { + const propType = getPropType(propValue) + if (propType === 'object') { + if (propValue instanceof Date) { + return 'date' + } else if (propValue instanceof RegExp) { + return 'regexp' + } + } + return propType +} + +function createObservableTypeCheckerCreator (allowNativeType, mobxType) { + return createChainableTypeChecker(function ( + props, + propName, + componentName, + location, + propFullName + ) { + return untracked(() => { + if (allowNativeType) { + if (getPropType(props[propName]) === mobxType.toLowerCase()) return null + } + let mobxChecker + switch (mobxType) { + case 'Array': + mobxChecker = isObservableArray + break + case 'Object': + mobxChecker = isObservableObject + break + case 'Map': + mobxChecker = isObservableMap + break + default: + throw new Error(`Unexpected mobxType: ${mobxType}`) + } + const propValue = props[propName] + if (!mobxChecker(propValue)) { + const preciseType = getPreciseType(propValue) + const nativeTypeExpectationMessage = allowNativeType + ? ' or javascript `' + mobxType.toLowerCase() + '`' + : '' + return new Error( + 'Invalid prop `' + propFullName + '` of type `' + preciseType + '` supplied to' + + ' `' + componentName + '`, expected `mobx.Observable' + mobxType + + '`' + nativeTypeExpectationMessage + '.' + ) + } + return null + }) + }) +} + +function createObservableArrayOfTypeChecker (allowNativeType, typeChecker) { + return createChainableTypeChecker(function ( + props, + propName, + componentName, + location, + propFullName, + ...rest + ) { + return untracked(() => { + if (typeof typeChecker !== 'function') { + return new Error( + 'Property `' + propFullName + '` of component `' + componentName + + '` has ' + 'invalid PropType notation.' + ) + } + let error = createObservableTypeCheckerCreator(allowNativeType, 'Array')( + props, + propName, + componentName + ) + if (error instanceof Error) return error + const propValue = props[propName] + for (let i = 0; i < propValue.length; i++) { + error = typeChecker( + propValue, + i, + componentName, + location, + propFullName + '[' + i + ']', + ...rest + ) + if (error instanceof Error) return error + } + return null + }) + }) +} + +const observableArray = createObservableTypeCheckerCreator(false, 'Array') +const observableArrayOf = createObservableArrayOfTypeChecker.bind(null, false) +const observableMap = createObservableTypeCheckerCreator(false, 'Map') +const observableObject = createObservableTypeCheckerCreator(false, 'Object') +const arrayOrObservableArray = createObservableTypeCheckerCreator(true, 'Array') +const arrayOrObservableArrayOf = createObservableArrayOfTypeChecker.bind(null, true) +const objectOrObservableObject = createObservableTypeCheckerCreator(true, 'Object') + +export const PropTypes = { + observableArray, + observableArrayOf, + observableMap, + observableObject, + arrayOrObservableArray, + arrayOrObservableArrayOf, + objectOrObservableObject +} diff --git a/packages/taro-mobx-common/src/reporter.js b/packages/taro-mobx-common/src/reporter.js index 920b6e8eae51..4685adc13318 100644 --- a/packages/taro-mobx-common/src/reporter.js +++ b/packages/taro-mobx-common/src/reporter.js @@ -16,4 +16,4 @@ class EventEmitter { } } -export const errorsReporter = new EventEmitter() \ No newline at end of file +export const errorsReporter = new EventEmitter() diff --git a/packages/taro-mobx-common/src/staticRendering.js b/packages/taro-mobx-common/src/staticRendering.js new file mode 100644 index 000000000000..f309bc4c00fb --- /dev/null +++ b/packages/taro-mobx-common/src/staticRendering.js @@ -0,0 +1,9 @@ +let globalIsUsingStaticRendering = false + +export function useStaticRendering (enable) { + globalIsUsingStaticRendering = enable +} + +export function isUsingStaticRendering () { + return globalIsUsingStaticRendering +} diff --git a/packages/taro-mobx-common/src/useAsObservableSource.js b/packages/taro-mobx-common/src/useAsObservableSource.js new file mode 100644 index 000000000000..fcd55574d81f --- /dev/null +++ b/packages/taro-mobx-common/src/useAsObservableSource.js @@ -0,0 +1,29 @@ +import { observable, runInAction } from 'mobx' +import { isPlainObject } from './utils' + +export function useAsObservableSourceInternal (current, usedByLocalStore, useState) { + const culprit = usedByLocalStore ? 'useLocalStore' : 'useAsObservableSource' + if (usedByLocalStore && current === undefined) { + return undefined + } + if (process.env.NODE_ENV !== 'production' && !isPlainObject(current)) { + throw new Error( + `${culprit} expects a plain object as ${usedByLocalStore ? 'second' : 'first'} argument` + ) + } + const [res] = useState(() => observable(current, {}, { deep: false })) + if ( + process.env.NODE_ENV !== 'production' && + Object.keys(res).length !== Object.keys(current).length + ) { + throw new Error(`the shape of objects passed to ${culprit} should be stable`) + } + runInAction(() => { + Object.assign(res, current) + }) + return res +} + +export function useAsObservableSource (current, useState) { + return useAsObservableSourceInternal(current, false, useState) +} diff --git a/packages/taro-mobx-common/src/useLocalStore.js b/packages/taro-mobx-common/src/useLocalStore.js new file mode 100644 index 000000000000..fa163c18d4f8 --- /dev/null +++ b/packages/taro-mobx-common/src/useLocalStore.js @@ -0,0 +1,27 @@ +import { observable, transaction, runInAction } from 'mobx' +import { useAsObservableSourceInternal } from './useAsObservableSource' +import { isPlainObject } from './utils' + +export function useLocalStore (initializer, current, useState) { + const source = useAsObservableSourceInternal(current, true, useState) + return useState(() => { + const local = observable(initializer(source)) + if (isPlainObject(local)) { + runInAction(() => { + Object.keys(local).forEach(key => { + const value = local[key] + if (typeof value === 'function') { + local[key] = wrapInTransaction(value, local) + } + }) + }) + } + return local + })[0] +} + +function wrapInTransaction (fn, context) { + return (...args) => { + return transaction(() => fn.apply(context, args)) + } +} diff --git a/packages/taro-mobx-common/src/utils.js b/packages/taro-mobx-common/src/utils.js new file mode 100644 index 000000000000..302d440c488a --- /dev/null +++ b/packages/taro-mobx-common/src/utils.js @@ -0,0 +1,13 @@ +import Taro from '@tarojs/taro' + +export function isPlainObject (value) { + if (!value || typeof value !== 'object') { + return false + } + const proto = Object.getPrototypeOf(value) + return !proto || proto === Object.prototype +} + +export function isMiniPlatform () { + return !(/^WEB|RN$/i.test(Taro.getEnv())) +} diff --git a/packages/taro-mobx-h5/package.json b/packages/taro-mobx-h5/package.json index 3c15ff5b407e..718a042fbc8e 100644 --- a/packages/taro-mobx-h5/package.json +++ b/packages/taro-mobx-h5/package.json @@ -25,11 +25,11 @@ "index.js" ], "peerDependencies": { - "@tarojs/taro-h5": "1.2.17", "nervjs": "^1.4.0" }, "dependencies": { - "@tarojs/mobx-common": "1.3.5" + "@tarojs/mobx-common": "1.3.5", + "@tarojs/taro-h5": "1.3.5" }, "devDependencies": { "rimraf": "^2.6.2", diff --git a/packages/taro-mobx-h5/rollup.config.js b/packages/taro-mobx-h5/rollup.config.js index 3862781ce145..1b9ff63016be 100644 --- a/packages/taro-mobx-h5/rollup.config.js +++ b/packages/taro-mobx-h5/rollup.config.js @@ -14,7 +14,7 @@ export default { format: 'esm', file: 'dist/index.esm.js' }], - external: ['nervjs', 'mobx', '@tarojs/taro-h5', '@tarojs/mobx-common'], + external: ['@tarojs/taro-h5', '@tarojs/mobx-common'], plugins: [ babel({ presets: [ diff --git a/packages/taro-mobx-h5/src/Provider.js b/packages/taro-mobx-h5/src/Provider.js old mode 100755 new mode 100644 diff --git a/packages/taro-mobx-h5/src/index.js b/packages/taro-mobx-h5/src/index.js index b2f7ceb9af7e..e94225869f74 100644 --- a/packages/taro-mobx-h5/src/index.js +++ b/packages/taro-mobx-h5/src/index.js @@ -1,14 +1,46 @@ -import { createStoreInjector } from './inject' -import { observer as originObserver, inject as originInject } from '@tarojs/mobx-common' +import { useState } from '@tarojs/taro-h5' -export function inject () { - return originInject(...arguments, createStoreInjector) +import { + PropTypes, + onError, + observer, + isUsingStaticRendering, + useStaticRendering, + useLocalStore as originUseLocalStore, + useAsObservableSource as originUseAsObservableSource +} from '@tarojs/mobx-common' + +import Provider from './Provider' +import { inject } from './inject' + +function useLocalStore (initializer, current) { + return originUseLocalStore(initializer, current, useState) } -export function observer (Component) { - return originObserver(Component, 'render') +function useAsObservableSource (current) { + return originUseAsObservableSource(current, useState) } -export { onError } from '@tarojs/mobx-common' +export default { + PropTypes, + onError, + observer, + inject, + Provider, + useLocalStore, + useAsObservableSource, + isUsingStaticRendering, + useStaticRendering +} -export { default as Provider } from './Provider' \ No newline at end of file +export { + PropTypes, + onError, + observer, + inject, + Provider, + useLocalStore, + useAsObservableSource, + isUsingStaticRendering, + useStaticRendering +} diff --git a/packages/taro-mobx-h5/src/inject.js b/packages/taro-mobx-h5/src/inject.js index be38b21f6057..7e09864f188d 100644 --- a/packages/taro-mobx-h5/src/inject.js +++ b/packages/taro-mobx-h5/src/inject.js @@ -1,12 +1,12 @@ import { createElement } from 'nervjs' import { Component } from '@tarojs/taro-h5' -import { mapStoreToProps, generateDisplayName } from '@tarojs/mobx-common' +import { mapStoreToProps, getInjectName, inject as originInject } from '@tarojs/mobx-common' -export function createStoreInjector (grabStoresFn, injectNames, sourceComponent) { +function createStoreInjector (grabStoresFn, injectNames, sourceComponent) { class Injector extends Component { static isMobxInjector = true static config = sourceComponent.config || {} - static displayName = generateDisplayName(sourceComponent, injectNames) + static displayName = getInjectName(sourceComponent, injectNames) __observeInstance render () { @@ -39,3 +39,7 @@ export function createStoreInjector (grabStoresFn, injectNames, sourceComponent) return Injector } + +export function inject () { + return originInject(...arguments, createStoreInjector) +} diff --git a/packages/taro-mobx-rn/package.json b/packages/taro-mobx-rn/package.json index 676e52a5aeec..bdc73ef9de02 100644 --- a/packages/taro-mobx-rn/package.json +++ b/packages/taro-mobx-rn/package.json @@ -19,6 +19,6 @@ ], "dependencies": { "@tarojs/mobx-common": "1.3.5", - "@tarojs/taro-rn": "1.1.7" + "@tarojs/taro-rn": "1.3.5" } } diff --git a/packages/taro-mobx-rn/src/Provider.js b/packages/taro-mobx-rn/src/Provider.js old mode 100755 new mode 100644 diff --git a/packages/taro-mobx-rn/src/index.js b/packages/taro-mobx-rn/src/index.js index c6228330edd7..9b6272e6336f 100644 --- a/packages/taro-mobx-rn/src/index.js +++ b/packages/taro-mobx-rn/src/index.js @@ -1,13 +1,46 @@ -import { createStoreInjector } from './inject' -import { observer as originObserver, inject as originInject } from '@tarojs/mobx-common' +import { useState } from '@tarojs/taro-rn' -export function inject () { - return originInject(...arguments, createStoreInjector) +import { + PropTypes, + onError, + observer, + isUsingStaticRendering, + useStaticRendering, + useLocalStore as originUseLocalStore, + useAsObservableSource as originUseAsObservableSource +} from '@tarojs/mobx-common' + +import Provider from './Provider' +import { inject } from './inject' + +function useLocalStore (initializer, current) { + return originUseLocalStore(initializer, current, useState) } -export function observer (Component) { - return originObserver(Component, 'render') +function useAsObservableSource (current) { + return originUseAsObservableSource(current, useState) } -export { onError } from '@tarojs/mobx-common' -export { default as Provider } from './Provider' \ No newline at end of file +export default { + PropTypes, + onError, + observer, + inject, + Provider, + useLocalStore, + useAsObservableSource, + isUsingStaticRendering, + useStaticRendering +} + +export { + PropTypes, + onError, + observer, + inject, + Provider, + useLocalStore, + useAsObservableSource, + isUsingStaticRendering, + useStaticRendering +} diff --git a/packages/taro-mobx-rn/src/inject.js b/packages/taro-mobx-rn/src/inject.js index 4ef0e778c474..a6bc83c7d5d6 100644 --- a/packages/taro-mobx-rn/src/inject.js +++ b/packages/taro-mobx-rn/src/inject.js @@ -1,31 +1,45 @@ import { createElement } from 'react' import { Component } from '@tarojs/taro-rn' -import { mapStoreToProps, generateDisplayName } from '@tarojs/mobx-common' +import { mapStoreToProps, getInjectName, inject as originInject } from '@tarojs/mobx-common' -export function createStoreInjector (grabStoresFn, injectNames, sourceComponent) { +function createStoreInjector (grabStoresFn, injectNames, sourceComponent) { class Injector extends Component { static isMobxInjector = true static config = sourceComponent.config || {} - static displayName = generateDisplayName(sourceComponent, injectNames) + static displayName = getInjectName(sourceComponent, injectNames) + __observeInstance render () { - return createElement(sourceComponent, mapStoreToProps(grabStoresFn, this.props)) + const originProps = mapStoreToProps(grabStoresFn, this.props) + return createElement(sourceComponent, { + ...originProps, + ref: ref => { + originProps.ref && originProps.ref(ref) + if (ref) { + this.__observeInstance = ref + } + } + }) } componentDidShow () { const { componentDidShow } = sourceComponent.prototype if (typeof componentDidShow === 'function') { - componentDidShow() + componentDidShow.call(this.__observeInstance) } } componentDidHide () { const { componentDidHide } = sourceComponent.prototype if (typeof componentDidHide === 'function') { - componentDidHide() + componentDidHide.call(this.__observeInstance) } } } return Injector } + +export function inject () { + return originInject(...arguments, createStoreInjector) +} diff --git a/packages/taro-mobx/package.json b/packages/taro-mobx/package.json index 40ada9218884..61d67af2cbac 100644 --- a/packages/taro-mobx/package.json +++ b/packages/taro-mobx/package.json @@ -13,8 +13,10 @@ "url": "git+https://github.com/NervJS/taro.git" }, "main": "index.js", + "typings": "types/index.d.ts", "files": [ "dist", + "types", "index.js" ], "scripts": { @@ -22,11 +24,9 @@ "clear": "rimraf dist" }, "dependencies": { + "@tarojs/taro": "1.3.5", "@tarojs/mobx-common": "1.3.5" }, - "peerDependencies": { - "mobx": "4.8.0" - }, "devDependencies": { "rimraf": "^2.6.2", "rollup": "1.1.0", diff --git a/packages/taro-mobx/rollup.config.js b/packages/taro-mobx/rollup.config.js index 5498b6e4c9b6..67889371f6ec 100644 --- a/packages/taro-mobx/rollup.config.js +++ b/packages/taro-mobx/rollup.config.js @@ -9,7 +9,7 @@ export default { format: 'cjs', file: 'dist/index.js' }], - external: ['@tarojs/mobx-common'], + external: ['@tarojs/taro', '@tarojs/mobx-common'], plugins: [ babel({ presets: [ diff --git a/packages/taro-mobx/src/index.js b/packages/taro-mobx/src/index.js index ee3b2c504d35..6f716295526d 100644 --- a/packages/taro-mobx/src/index.js +++ b/packages/taro-mobx/src/index.js @@ -1,30 +1,53 @@ -import { createStoreInjector } from './inject' -import { onError, getStore, setStore, observer as originObserver, inject as originInject } from '@tarojs/mobx-common' +import { useState } from '@tarojs/taro' + +import { + PropTypes, + onError, + getStore, + setStore, + observer, + isUsingStaticRendering, + useStaticRendering, + useLocalStore as originUseLocalStore, + useAsObservableSource as originUseAsObservableSource +} from '@tarojs/mobx-common' + +import { inject } from './inject' class Provider {} -function observer (Component) { - return originObserver(Component, '_createData') +function useLocalStore (initializer, current) { + return originUseLocalStore(initializer, current, useState) } -function inject () { - return originInject(...arguments, createStoreInjector) +function useAsObservableSource (current) { + return originUseAsObservableSource(current, useState) } export default { + PropTypes, onError, getStore, setStore, - observer, inject, - Provider + observer, + Provider, + useLocalStore, + useAsObservableSource, + isUsingStaticRendering, + useStaticRendering } export { + PropTypes, onError, getStore, setStore, - observer, inject, - Provider -} \ No newline at end of file + observer, + Provider, + useLocalStore, + useAsObservableSource, + isUsingStaticRendering, + useStaticRendering +} diff --git a/packages/taro-mobx/src/inject.js b/packages/taro-mobx/src/inject.js index e95f99fcd7a5..85f106d133d3 100644 --- a/packages/taro-mobx/src/inject.js +++ b/packages/taro-mobx/src/inject.js @@ -1,9 +1,9 @@ -import { mapStoreToProps, generateDisplayName } from '@tarojs/mobx-common' +import { mapStoreToProps, getInjectName, inject as originInject } from '@tarojs/mobx-common' -export function createStoreInjector (grabStoresFn, injectNames, Component) { +function createStoreInjector (grabStoresFn, injectNames, Component) { class Injector extends Component { static isMobxInjector = true - static displayName = generateDisplayName(Component, injectNames) + static displayName = getInjectName(Component, injectNames) constructor (props, isPage) { super(Object.assign(...arguments, mapStoreToProps(grabStoresFn, props)), isPage) } @@ -17,9 +17,13 @@ export function createStoreInjector (grabStoresFn, injectNames, Component) { } const target = Injector.prototype const originCreateData = target._createData - target._createData = function () { + target._createData = function (...args) { Object.assign(this.props, mapStoreToProps(grabStoresFn, this.props)) - return originCreateData.call(this) + return originCreateData.call(this, null, null, args[2]) } return Injector -} \ No newline at end of file +} + +export function inject () { + return originInject(...arguments, createStoreInjector) +} diff --git a/packages/taro-mobx/types/index.d.ts b/packages/taro-mobx/types/index.d.ts new file mode 100644 index 000000000000..dc544859fd52 --- /dev/null +++ b/packages/taro-mobx/types/index.d.ts @@ -0,0 +1,30 @@ +import Taro from '@tarojs/taro' + +export type IValueMap = { [key: string]: any }; + +export function onError(fn: (error: Error) => void); + +export function isUsingStaticRendering(): boolean; + +export function useStaticRendering(enable: boolean); +export function useLocalStore, TSource extends object = any>( + initializer: (source: TSource) => TStore, + current?: TSource +): TStore; +export function useAsObservableSource(current: TSource): TSource; + +export function observer(component); +export function inject(...stores: string[]); +export function inject(fn: (stores: IValueMap, nextProps: IValueMap) => IValueMap); + +export class Provider extends Taro.Component {} + +export const PropTypes: { + observableArray: React.Requireable + observableArrayOf: (type: React.Validator) => React.Requireable + observableMap: React.Requireable + observableObject: React.Requireable + arrayOrObservableArray: React.Requireable + arrayOrObservableArrayOf: (type: React.Validator) => React.Requireable + objectOrObservableObject: React.Requireable +} \ No newline at end of file From cd540614a09cb0ad3eff20b97ab28f39fae876a8 Mon Sep 17 00:00:00 2001 From: YuanQuan Date: Wed, 3 Jul 2019 17:35:39 +0800 Subject: [PATCH 129/158] =?UTF-8?q?fix(h5):=20Page=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0$component=E5=AF=B9=E8=B1=A1=EF=BC=8C?= =?UTF-8?q?=E4=B8=8E=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=BB=9F?= =?UTF-8?q?=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-h5/src/taro/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/taro-h5/src/taro/index.js b/packages/taro-h5/src/taro/index.js index 07b504d66747..fe8cbc678552 100644 --- a/packages/taro-h5/src/taro/index.js +++ b/packages/taro-h5/src/taro/index.js @@ -101,6 +101,14 @@ class Component extends Nerv.Component { set $app (app) { console.warn('Property "$app" is read-only.') } + + get $component () { + return this + } + + set $component (app) { + console.warn('Property "$component" is read-only.') + } } class PureComponent extends Nerv.PureComponent { @@ -118,6 +126,14 @@ class PureComponent extends Nerv.PureComponent { set $app (app) { console.warn('Property "$app" is read-only.') } + + get $component () { + return this + } + + set $component (app) { + console.warn('Property "$component" is read-only.') + } } const initPxTransform = originalInitPxTransform.bind(taro) From a88225e760b6ff36951758ffc4a2fd5f8dbaca8f Mon Sep 17 00:00:00 2001 From: WaterMan Date: Mon, 8 Jul 2019 10:33:16 +0800 Subject: [PATCH 130/158] =?UTF-8?q?fix(router):=20=E8=A7=A3=E5=86=B3getCur?= =?UTF-8?q?rentPages=E6=9C=89=E6=97=B6=E5=80=99=E5=8F=AA=E8=83=BD=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=95=BF=E5=BA=A6=E4=BD=86=E6=B2=A1=E6=9C=89=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E7=9A=84=E9=97=AE=E9=A2=98=20(#3669)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-router/src/router/router.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/taro-router/src/router/router.tsx b/packages/taro-router/src/router/router.tsx index 101405f6d8af..f92143054aae 100644 --- a/packages/taro-router/src/router/router.tsx +++ b/packages/taro-router/src/router/router.tsx @@ -102,7 +102,12 @@ class Router extends Taro.Component { } collectComponent = (comp, k) => { - this.currentPages[k] = comp + if(this.currentPages[k]){ + this.currentPages[k] = comp; + } + else{ + this.currentPages.push(comp); + } } componentDidMount () { @@ -138,9 +143,7 @@ class Router extends Taro.Component { } render () { - const router = this const currentLocation = Taro._$router - router.currentPages.length = this.state.routeStack.length return (
Date: Mon, 8 Jul 2019 10:47:36 +0800 Subject: [PATCH 131/158] =?UTF-8?q?fix(taro-cli):=20=E6=B7=BB=E5=8A=A0=20j?= =?UTF-8?q?son=20=E6=96=87=E4=BB=B6=E7=BC=BA=E5=A4=B1=E7=9A=84=E9=80=97?= =?UTF-8?q?=E5=8F=B7=20(#3707)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/config/manifest.default.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-cli/src/config/manifest.default.json b/packages/taro-cli/src/config/manifest.default.json index e25e88c1c022..34b07c10b7fd 100644 --- a/packages/taro-cli/src/config/manifest.default.json +++ b/packages/taro-cli/src/config/manifest.default.json @@ -16,7 +16,7 @@ { "name": "system.sensor" }, { "name": "system.geolocation" }, { "name": "system.share" }, - { "name": "system.notification" } + { "name": "system.notification" }, { "name": "system.device" }, { "name": "system.webview" }, { "name": "system.request" }, From 24e717f625317918d471fda3619c20cdb358776e Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 8 Jul 2019 13:41:56 +0800 Subject: [PATCH 132/158] =?UTF-8?q?fix(transformer):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=2011964f8=20=E5=AF=B9=20JSX=20=E5=B1=9E=E6=80=A7=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=94=99=E8=AF=AF=EF=BC=8Cclose=20#3697?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-transformer-wx/src/utils.ts b/packages/taro-transformer-wx/src/utils.ts index edff32b8e085..d396dc16a94c 100644 --- a/packages/taro-transformer-wx/src/utils.ts +++ b/packages/taro-transformer-wx/src/utils.ts @@ -662,7 +662,7 @@ export function setAncestorCondition (jsx: NodePath, expr: t.Expression) Adapter.if, Adapter.else ]) - const logicalJSX = jsx.findParent(p => p.isJSXElement() && p.node.openingElement.attributes.some(a => t.isIdentifier(a.name) && ifAttrSet.has(a.name.name))) as NodePath + const logicalJSX = jsx.findParent(p => p.isJSXElement() && p.node.openingElement.attributes.some(a => t.isJSXIdentifier(a.name) && ifAttrSet.has(a.name.name))) as NodePath if (logicalJSX) { const attr = logicalJSX.node.openingElement.attributes.find(a => ifAttrSet.has(a.name.name as string)) if (attr) { From 0ecb3995001e761e12d3b8524dcb0dcc6aa1ff54 Mon Sep 17 00:00:00 2001 From: jinjinjin0731 <709899428@qq.com> Date: Mon, 8 Jul 2019 14:36:19 +0800 Subject: [PATCH 133/158] =?UTF-8?q?fix(component):=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?Swiper=20=E7=BB=84=E4=BB=B6=E6=8C=87=E7=A4=BA=E6=A0=87=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E4=B8=BA=20false=20=EF=BC=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98,=20close=20#3676?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/{taro-webview => webview}/index.ux | 0 .../src/components/swiper/index.js | 15 +++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) rename packages/taro-components-qa/src/components/{taro-webview => webview}/index.ux (100%) diff --git a/packages/taro-components-qa/src/components/taro-webview/index.ux b/packages/taro-components-qa/src/components/webview/index.ux similarity index 100% rename from packages/taro-components-qa/src/components/taro-webview/index.ux rename to packages/taro-components-qa/src/components/webview/index.ux diff --git a/packages/taro-components/src/components/swiper/index.js b/packages/taro-components/src/components/swiper/index.js index a04410b3c745..4fbfe6174bb8 100644 --- a/packages/taro-components/src/components/swiper/index.js +++ b/packages/taro-components/src/components/swiper/index.js @@ -18,10 +18,10 @@ class SwiperItem extends Nerv.Component { const createEvent = type => { let e try { - e = new TouchEvent(type); + e = new TouchEvent(type) } catch (err) { - e = document.createEvent('Event'); - e.initEvent(type, true, true); + e = document.createEvent('Event') + e.initEvent(type, true, true) } return e } @@ -133,6 +133,13 @@ class Swiper extends Nerv.Component { let defaultIndicatorColor = indicatorColor || 'rgba(0, 0, 0, .3)' let defaultIndicatorActiveColor = indicatorActiveColor || '#000' const cls = classNames(`taro-swiper-${this._id}`, 'swiper-container', className) + const paginationCls = classNames( + 'swiper-pagination', + { + 'swiper-pagination-hidden': !this.props.indicatorDots, + 'swiper-pagination-bullets': this.props.indicatorDots + } + ) return (
{ this.$el = el }}>
{this.props.children}
- {this.props.indicatorDots ?
: null} +
) } From 2ada5a2188302705b3b67608392d90dac0950c1d Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Mon, 8 Jul 2019 15:11:39 +0800 Subject: [PATCH 134/158] =?UTF-8?q?fix(taro):=20interceptor=20=E6=9A=B4?= =?UTF-8?q?=E9=9C=B2=20request=20=E8=BF=94=E5=9B=9E=E7=9A=84=20requestTask?= =?UTF-8?q?=E3=80=82close=20#3654?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro/src/interceptor/chain.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/taro/src/interceptor/chain.js b/packages/taro/src/interceptor/chain.js index dc959849bfce..fee90abc9a71 100644 --- a/packages/taro/src/interceptor/chain.js +++ b/packages/taro/src/interceptor/chain.js @@ -12,7 +12,10 @@ export default class Chain { } const nextInterceptor = this._getNextInterceptor() const nextChain = this._getNextChain() - return nextInterceptor(nextChain).catch(err => Promise.reject(err)) + const p = nextInterceptor(nextChain) + const res = p.catch(err => Promise.reject(err)) + if (typeof p.abort === 'function') res.abort = p.abort + return res } _getNextInterceptor () { From 697c74bfa5e4996f97c71201fe1926807b50d4a7 Mon Sep 17 00:00:00 2001 From: jinjinjin0731 <709899428@qq.com> Date: Mon, 8 Jul 2019 16:29:41 +0800 Subject: [PATCH 135/158] =?UTF-8?q?fix(components):=20=20H5=20=E4=B8=8D?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20camera=20=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/components/media/camera.md | 6 +- .../src/components/camera/index.js | 73 +------------------ 2 files changed, 6 insertions(+), 73 deletions(-) diff --git a/docs/components/media/camera.md b/docs/components/media/camera.md index 0c545a97aadb..b93890725d16 100755 --- a/docs/components/media/camera.md +++ b/docs/components/media/camera.md @@ -9,9 +9,9 @@ sidebar_label: Camera | H5 | ReactNative| 属性名 | 类型 | 默认值 | 说明 | | :-: | :-: | :- | :- | :- | :- | -| √ | | devicePosition | String | back | 前置或后置,值为 front, back | -| √ | | onStop | EventHandle | | 摄像头在非正常终止时触发,如退出后台等情况 | -| √ | | onError | EventHandle | | 用户不允许使用摄像头时触发 | +| | | devicePosition | String | back | 前置或后置,值为 front, back | +| | | onStop | EventHandle | | 摄像头在非正常终止时触发,如退出后台等情况 | +| | | onError | EventHandle | | 用户不允许使用摄像头时触发 | >其他相关属性请看各小程序官方文档 diff --git a/packages/taro-components/src/components/camera/index.js b/packages/taro-components/src/components/camera/index.js index 0884abdc32f3..d6516e91dbcd 100644 --- a/packages/taro-components/src/components/camera/index.js +++ b/packages/taro-components/src/components/camera/index.js @@ -1,84 +1,17 @@ -import 'weui' import Nerv from 'nervjs' class Camera extends Nerv.Component { constructor () { super(...arguments) } - componentDidMount () { - this.initCamera() - let context = this.show.getContext('2d') - - // 绑定事件 - this.getCamera.addEventListener('click', () => { - context.drawImage(this.vide, 0, 0, 480, 320) - }) - } - initCamera () { - // 区分前后摄像头 - const {devicePosition} = this.props - let device - if (devicePosition === 'front') { - device = 'user' - } else { - device = 'environment' - } - - if (navigator.mediaDevices.getUserMedia || navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia) { - // 调用用户媒体设备,访问摄像头 - this.getUserMedia({ - audio: true, - video: { facingMode: device } - }, (stream) => { - // 兼容webkit内核浏览器 - let CompatibleURL = window.URL || window.webkitURL - this.vide.src = CompatibleURL.createObjectURL(stream) - // 播放视频 - this.vide.play() - }, (error) => { - if (error.name === 'NotAllowedError') { - this.props.binderror(error) - } else { - this.props.bindstop(error) - } - }) - } else { - alert('你的浏览器不支持访问用户媒体设备') - } - } - - // 访问用户媒体设备的兼容方法 - getUserMedia (constrains, success, error) { - if (navigator.mediaDevices.getUserMedia) { - // 最新标准API - navigator.mediaDevices.getUserMedia(constrains).then(success).catch(error) - } else if (navigator.webkitGetUserMedia) { - // webkit内核浏览器 - navigator.webkitGetUserMedia(constrains).then(success).catch(error) - } else if (navigator.getUserMedia) { - // 旧版API - navigator.getUserMedia(constrains).then(success).catch(error) - } + componentDidMount () { + console.error('h5 暂不支持 Camera 组件') } render () { - return ( -
-
- ) + return
} } -// 默认配置 -Camera.defaultProps = { - devicePosition: 'back' -} - export default Camera From 2dfeafe8b3827d1da4067b59443b521bbd1c63f3 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 8 Jul 2019 17:21:28 +0800 Subject: [PATCH 136/158] =?UTF-8?q?fix(quickapp):=20=E5=BF=AB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=94=AF=E6=8C=81=20Block=20=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=EF=BC=8Cclose=20#3686?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/mini/constants.ts | 3 ++- packages/taro-transformer-wx/src/index.ts | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/taro-cli/src/mini/constants.ts b/packages/taro-cli/src/mini/constants.ts index 829b14276110..572b8a827ed4 100644 --- a/packages/taro-cli/src/mini/constants.ts +++ b/packages/taro-cli/src/mini/constants.ts @@ -1,5 +1,6 @@ export const QUICKAPP_SPECIAL_COMPONENTS = new Set([ 'View', - 'Text' + 'Text', + 'Block' ]) diff --git a/packages/taro-transformer-wx/src/index.ts b/packages/taro-transformer-wx/src/index.ts index 7579422a9b44..7481502f6362 100644 --- a/packages/taro-transformer-wx/src/index.ts +++ b/packages/taro-transformer-wx/src/index.ts @@ -515,9 +515,15 @@ export default function transform (options: Options): TransformResult { } } } - if (name === 'View' && Adapter.type === Adapters.quickapp) { - path.node.name = t.jSXIdentifier('div') + if (Adapter.type === Adapters.quickapp) { + if (name === 'View') { + path.node.name = t.jSXIdentifier('div') + } + if (name === 'Block') { + path.node.name = t.jSXIdentifier('block') + } } + if (name === 'Provider') { const modules = path.scope.getAllBindings('module') const providerBinding = Object.values(modules).some((m: Binding) => m.identifier.name === 'Provider') From adf68af04f1565cb2eabd3b748c0491889babaa7 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 8 Jul 2019 17:50:12 +0800 Subject: [PATCH 137/158] =?UTF-8?q?fix(cli):=20=E5=BF=AB=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E7=AB=AF=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?close=20#3685?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/mini/component.ts | 15 +++++++++------ packages/taro-cli/src/mini/helper.ts | 4 ++-- packages/taro-cli/src/mini/page.ts | 15 +++++++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/taro-cli/src/mini/component.ts b/packages/taro-cli/src/mini/component.ts index a26574742366..328faf9bc46b 100644 --- a/packages/taro-cli/src/mini/component.ts +++ b/packages/taro-cli/src/mini/component.ts @@ -254,6 +254,9 @@ export async function buildSingleComponent ( }) transfromNativeComponents(outputComponentJSONPath.replace(buildConfig.outputDir || buildOutputDir, sourceDirPath), res.configObj) } + let realComponentsPathList: IComponentObj[] = [] + realComponentsPathList = getRealComponentsPathList(component, componentDepComponents) + if (!isQuickApp) { resCode = await compileScriptFile(resCode, component, outputComponentJSPath, buildAdapter) if (isProduction) { @@ -262,9 +265,11 @@ export async function buildSingleComponent ( } else { // 快应用编译,搜集创建组件 ux 文件 const importTaroSelfComponents = getImportTaroSelfComponents(outputComponentJSPath, res.taroSelfComponents) - const importCustomComponents = new Set(componentDepComponents.map(item => { - delete item.type - return item + const importCustomComponents = new Set(realComponentsPathList.map(item => { + return { + path: path.relative(path.dirname(component), item.path as string).replace(path.extname(item.path as string), ''), + name: item.name as string + } })) let styleRelativePath if (res.styleFiles.length) { @@ -288,9 +293,7 @@ export async function buildSingleComponent ( media: [] } // 编译依赖的组件文件 - let realComponentsPathList: IComponentObj[] = [] - if (componentDepComponents.length) { - realComponentsPathList = getRealComponentsPathList(component, componentDepComponents) + if (realComponentsPathList.length) { res.scriptFiles = res.scriptFiles.map(item => { for (let i = 0; i < realComponentsPathList.length; i++) { const componentObj = realComponentsPathList[i] diff --git a/packages/taro-cli/src/mini/helper.ts b/packages/taro-cli/src/mini/helper.ts index e65469d08f2e..271dc6fb4f70 100644 --- a/packages/taro-cli/src/mini/helper.ts +++ b/packages/taro-cli/src/mini/helper.ts @@ -239,7 +239,7 @@ export function getRealComponentsPathList ( ): IComponentObj[] { const { appPath, isProduction, buildAdapter, projectConfig, npmConfig } = BuildData const pathAlias = projectConfig.alias || {} - return components.map(component => { + return components.length ? components.map(component => { let componentPath = component.path if (isAliasPath(componentPath as string, pathAlias)) { componentPath = replaceAliasPath(filePath, componentPath as string, pathAlias) @@ -262,7 +262,7 @@ export function getRealComponentsPathList ( name: component.name, type: component.type } - }) + }) : [] } export function isFileToBePage (filePath: string): boolean { diff --git a/packages/taro-cli/src/mini/page.ts b/packages/taro-cli/src/mini/page.ts index 0266b9db7196..348f385c2479 100644 --- a/packages/taro-cli/src/mini/page.ts +++ b/packages/taro-cli/src/mini/page.ts @@ -153,6 +153,9 @@ export async function buildSinglePage (page: string) { transfromNativeComponents(outputPageJSONPath.replace(outputDir, sourceDir), res.configObj) } + let realComponentsPathList: IComponentObj[] = [] + realComponentsPathList = getRealComponentsPathList(pageJs, pageDepComponents) + if (!isQuickApp) { resCode = await compileScriptFile(resCode, pageJs, outputPageJSPath, buildAdapter) if (isProduction) { @@ -161,9 +164,11 @@ export async function buildSinglePage (page: string) { } else { // 快应用编译,搜集创建页面 ux 文件 const importTaroSelfComponents = getImportTaroSelfComponents(outputPageJSPath, res.taroSelfComponents) - const importCustomComponents = new Set(pageDepComponents.map(item => { - delete item.type - return item + const importCustomComponents = new Set(realComponentsPathList.map(item => { + return { + path: path.relative(path.dirname(pageJs), item.path as string).replace(path.extname(item.path as string), ''), + name: item.name as string + } })) // 生成页面 ux 文件 let styleRelativePath @@ -180,9 +185,7 @@ export async function buildSinglePage (page: string) { printLog(processTypeEnum.GENERATE, '页面文件', `${outputDirName}/${page}${outputFilesTypes.TEMPL}`) } // 编译依赖的组件文件 - let realComponentsPathList: IComponentObj[] = [] - if (pageDepComponents.length) { - realComponentsPathList = getRealComponentsPathList(pageJs, pageDepComponents) + if (realComponentsPathList.length) { res.scriptFiles = res.scriptFiles.map(item => { for (let i = 0; i < realComponentsPathList.length; i++) { const componentObj = realComponentsPathList[i] From f035fc27aca4fde97554f0a0d708faf458369576 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 8 Jul 2019 17:54:42 +0800 Subject: [PATCH 138/158] chore(release): publish v1.3.6 --- lerna.json | 2 +- .../package.json | 2 +- .../package.json | 4 ++-- packages/css-to-react-native/package.json | 2 +- packages/eslint-config-taro/package.json | 4 ++-- packages/eslint-plugin-taro/package.json | 2 +- .../postcss-plugin-constparse/package.json | 2 +- packages/postcss-pxtransform/package.json | 2 +- packages/postcss-unit-transform/package.json | 2 +- .../stylelint-config-taro-rn/package.json | 4 ++-- packages/stylelint-taro-rn/package.json | 2 +- packages/taro-alipay/package.json | 6 ++--- packages/taro-async-await/package.json | 2 +- packages/taro-cli/package.json | 22 +++++++++---------- packages/taro-components-qa/package.json | 2 +- packages/taro-components-rn/package.json | 2 +- packages/taro-components/package.json | 6 ++--- packages/taro-h5/package.json | 6 ++--- packages/taro-mobx-common/package.json | 2 +- packages/taro-mobx-h5/package.json | 6 ++--- packages/taro-mobx-rn/package.json | 6 ++--- packages/taro-mobx/package.json | 6 ++--- packages/taro-plugin-babel/package.json | 2 +- packages/taro-plugin-csso/package.json | 2 +- packages/taro-plugin-less/package.json | 2 +- packages/taro-plugin-sass/package.json | 2 +- packages/taro-plugin-stylus/package.json | 2 +- packages/taro-plugin-typescript/package.json | 2 +- packages/taro-plugin-uglifyjs/package.json | 2 +- packages/taro-qq/package.json | 6 ++--- packages/taro-quickapp/package.json | 6 ++--- packages/taro-redux-h5/package.json | 4 ++-- packages/taro-redux-rn/package.json | 2 +- packages/taro-redux/package.json | 6 ++--- packages/taro-rn-runner/package.json | 2 +- packages/taro-rn/package.json | 4 ++-- packages/taro-router-rn/package.json | 2 +- packages/taro-router/package.json | 4 ++-- packages/taro-swan/package.json | 6 ++--- packages/taro-transformer-wx/package.json | 6 ++--- packages/taro-tt/package.json | 6 ++--- packages/taro-utils/package.json | 2 +- packages/taro-weapp/package.json | 6 ++--- packages/taro-webpack-runner/package.json | 10 ++++----- packages/taro-with-weapp/package.json | 4 ++-- packages/taro/package.json | 2 +- packages/taroize/package.json | 2 +- 47 files changed, 94 insertions(+), 94 deletions(-) diff --git a/lerna.json b/lerna.json index 4f222c121c24..d84edc86433b 100644 --- a/lerna.json +++ b/lerna.json @@ -53,6 +53,6 @@ "message": "chore(release): publish %s" } }, - "version": "1.3.5", + "version": "1.3.6", "npmClient": "npm" } diff --git a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json index 03a8f5683c9e..7889e2563023 100644 --- a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json +++ b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-jsx-to-stylesheet", - "version": "1.3.5", + "version": "1.3.6", "description": "Transform stylesheet selector to style in JSX Elements.", "license": "MIT", "main": "src/index.js", diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json index 092577be92c3..20b189bfd2e0 100644 --- a/packages/babel-plugin-transform-taroapi/package.json +++ b/packages/babel-plugin-transform-taroapi/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-taroapi", - "version": "1.3.5", + "version": "1.3.6", "main": "dist/index.js", "license": "MIT", "scripts": { @@ -10,7 +10,7 @@ "test": "jest" }, "devDependencies": { - "@tarojs/taro-h5": "1.3.5", + "@tarojs/taro-h5": "1.3.6", "@types/babel-core": "^6.25.5", "@types/babel-traverse": "^6.25.4", "@types/babel-types": "^7.0.4", diff --git a/packages/css-to-react-native/package.json b/packages/css-to-react-native/package.json index f316eb123748..d37dcabb72cc 100644 --- a/packages/css-to-react-native/package.json +++ b/packages/css-to-react-native/package.json @@ -1,7 +1,7 @@ { "name": "taro-css-to-react-native", "description": "Convert CSS text to a React Native stylesheet object", - "version": "1.3.5", + "version": "1.3.6", "main": "dist/index.js", "license": "MIT", "scripts": { diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json index 4d42adf89212..7c5cddb67c10 100644 --- a/packages/eslint-config-taro/package.json +++ b/packages/eslint-config-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-taro", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro specific linting rules for ESLint", "main": "index.js", "files": [ @@ -27,6 +27,6 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "eslint-plugin-taro": "1.3.5" + "eslint-plugin-taro": "1.3.6" } } diff --git a/packages/eslint-plugin-taro/package.json b/packages/eslint-plugin-taro/package.json index b92347c37ef3..4eb9e68a883f 100644 --- a/packages/eslint-plugin-taro/package.json +++ b/packages/eslint-plugin-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-taro", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro specific linting plugin for ESLint", "main": "index.js", "files": [ diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json index ab7aa4ddddf2..0ea0e4449a68 100644 --- a/packages/postcss-plugin-constparse/package.json +++ b/packages/postcss-plugin-constparse/package.json @@ -1,6 +1,6 @@ { "name": "postcss-plugin-constparse", - "version": "1.3.5", + "version": "1.3.6", "description": "parse constants defined in config", "main": "index.js", "author": "Simba", diff --git a/packages/postcss-pxtransform/package.json b/packages/postcss-pxtransform/package.json index 2f946faa5399..ec3baeb3587c 100644 --- a/packages/postcss-pxtransform/package.json +++ b/packages/postcss-pxtransform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-pxtransform", - "version": "1.3.5", + "version": "1.3.6", "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位", "keywords": [ "postcss", diff --git a/packages/postcss-unit-transform/package.json b/packages/postcss-unit-transform/package.json index cbfe0970002a..b83ffa206293 100644 --- a/packages/postcss-unit-transform/package.json +++ b/packages/postcss-unit-transform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-taro-unit-transform", - "version": "1.3.5", + "version": "1.3.6", "description": "小程序单位转换", "main": "index.js", "scripts": { diff --git a/packages/stylelint-config-taro-rn/package.json b/packages/stylelint-config-taro-rn/package.json index eae83e149e44..1540a6bc9dab 100644 --- a/packages/stylelint-config-taro-rn/package.json +++ b/packages/stylelint-config-taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-config-taro-rn", - "version": "1.3.5", + "version": "1.3.6", "description": "Shareable stylelint config for React Native CSS modules", "main": "index.js", "files": [ @@ -28,6 +28,6 @@ "jest": "^23.6.0", "npmpub": "^4.1.0", "stylelint": "9.3.0", - "stylelint-taro-rn": "1.3.5" + "stylelint-taro-rn": "1.3.6" } } diff --git a/packages/stylelint-taro-rn/package.json b/packages/stylelint-taro-rn/package.json index e9d15f407191..2dab890bb48e 100644 --- a/packages/stylelint-taro-rn/package.json +++ b/packages/stylelint-taro-rn/package.json @@ -1,7 +1,7 @@ { "name": "stylelint-taro-rn", "description": "A collection of React Native specific rules for stylelint", - "version": "1.3.5", + "version": "1.3.6", "main": "dist/index.js", "babel": { "presets": [ diff --git a/packages/taro-alipay/package.json b/packages/taro-alipay/package.json index 8c47d798c171..b6cfdbee3331 100644 --- a/packages/taro-alipay/package.json +++ b/packages/taro-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-alipay", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro alipay framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.5", - "@tarojs/utils": "1.3.5", + "@tarojs/taro": "1.3.6", + "@tarojs/utils": "1.3.6", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-async-await/package.json b/packages/taro-async-await/package.json index 367f00293190..ea8c94d18981 100644 --- a/packages/taro-async-await/package.json +++ b/packages/taro-async-await/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/async-await", - "version": "1.3.5", + "version": "1.3.6", "description": "taro async await", "main": "index.js", "scripts": { diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json index 6f7ad69b8715..b67f38ba632c 100644 --- a/packages/taro-cli/package.json +++ b/packages/taro-cli/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/cli", - "version": "1.3.5", + "version": "1.3.6", "description": "cli tool for taro", "main": "index.js", "scripts": { @@ -30,8 +30,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taroize": "1.3.5", - "@tarojs/transformer-wx": "1.3.5", + "@tarojs/taroize": "1.3.6", + "@tarojs/transformer-wx": "1.3.6", "@types/request": "^2.48.1", "autoprefixer": "^8.4.1", "babel-core": "^6.26.3", @@ -41,7 +41,7 @@ "babel-plugin-remove-dead-code": "^1.3.2", "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-define": "^1.3.0", - "babel-plugin-transform-jsx-to-stylesheet": "1.3.5", + "babel-plugin-transform-jsx-to-stylesheet": "1.3.6", "babel-plugin-transform-react-jsx": "^6.24.1", "babel-template": "^6.26.0", "babel-traverse": "^6.26.0", @@ -57,10 +57,10 @@ "ejs": "^2.6.1", "envinfo": "^6.0.1", "eslint": "^4.15.0", - "eslint-config-taro": "1.3.5", + "eslint-config-taro": "1.3.6", "eslint-plugin-import": "^2.8.0", "eslint-plugin-react": "^7.4.0", - "eslint-plugin-taro": "1.3.5", + "eslint-plugin-taro": "1.3.6", "eslint-plugin-typescript": "^0.12.0", "fbjs": "^1.0.0", "fs-extra": "^5.0.0", @@ -82,7 +82,7 @@ "postcss-modules-resolve-imports": "^1.3.0", "postcss-modules-scope": "^1.1.0", "postcss-modules-values": "^1.3.0", - "postcss-pxtransform": "1.3.5", + "postcss-pxtransform": "1.3.6", "postcss-reporter": "^6.0.1", "postcss-taro-unit-transform": "1.2.15", "postcss-url": "^7.3.2", @@ -93,9 +93,9 @@ "semver": "^5.5.0", "shelljs": "^0.8.1", "stylelint": "9.3.0", - "stylelint-config-taro-rn": "1.3.5", - "stylelint-taro-rn": "1.3.5", - "taro-css-to-react-native": "1.3.5", + "stylelint-config-taro-rn": "1.3.6", + "stylelint-taro-rn": "1.3.6", + "taro-css-to-react-native": "1.3.6", "through2": "^2.0.3", "vinyl": "^2.1.0", "vinyl-fs": "^3.0.2", @@ -103,7 +103,7 @@ "yauzl": "2.10.0" }, "devDependencies": { - "@tarojs/taro": "1.3.5", + "@tarojs/taro": "1.3.6", "@types/autoprefixer": "^9.1.1", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.2", diff --git a/packages/taro-components-qa/package.json b/packages/taro-components-qa/package.json index 2ffb5813df81..23650ae1ec2d 100644 --- a/packages/taro-components-qa/package.json +++ b/packages/taro-components-qa/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-qa", - "version": "1.3.5", + "version": "1.3.6", "description": "多端解决方案基础组件(快应用)", "main": "./index.js", "files": [ diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index e0da120a10e8..d16e007f6074 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-rn", - "version": "1.3.5", + "version": "1.3.6", "description": "多端解决方案基础组件(RN)", "main": "./dist/index.js", "scripts": { diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json index 892c107e5b58..e03a63c8c402 100644 --- a/packages/taro-components/package.json +++ b/packages/taro-components/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components", - "version": "1.3.5", + "version": "1.3.6", "description": "", "main:h5": "src/index.js", "main": "dist/index.js", @@ -49,14 +49,14 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0", "@babel/plugin-transform-react-jsx": "^7.0.0", "@babel/preset-env": "^7.1.5", - "@tarojs/taro-h5": "1.3.5", + "@tarojs/taro-h5": "1.3.6", "@types/react": "^16.4.6", "@types/urijs": "^1.15.38", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "10.0.1", "babel-jest": "^22.4.4", "babel-loader": "^8.0.5", - "babel-plugin-transform-taroapi": "1.3.5", + "babel-plugin-transform-taroapi": "1.3.6", "css-loader": "^2.1.1", "file-loader": "^3.0.1", "jest": "^22.4.4", diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json index 996e9efa0a7b..d915fc064dc9 100644 --- a/packages/taro-h5/package.json +++ b/packages/taro-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-h5", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro h5 framework", "main:h5": "src/index.js", "main": "dist/index.js", @@ -45,8 +45,8 @@ "@babel/plugin-proposal-object-rest-spread": "^7.3.4", "@babel/plugin-transform-react-jsx": "^7.2.2", "@babel/preset-env": "^7.3.4", - "@tarojs/components": "1.3.5", - "@tarojs/taro": "1.3.5", + "@tarojs/components": "1.3.6", + "@tarojs/taro": "1.3.6", "babel-core": "7.0.0-bridge.0", "babel-jest": "24.4.0", "eslint": "^4.18.2", diff --git a/packages/taro-mobx-common/package.json b/packages/taro-mobx-common/package.json index 84627a949664..3e2d2998253d 100644 --- a/packages/taro-mobx-common/package.json +++ b/packages/taro-mobx-common/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-common", - "version": "1.3.5", + "version": "1.3.6", "description": "mobx library for taro", "keywords": [ "mobx", diff --git a/packages/taro-mobx-h5/package.json b/packages/taro-mobx-h5/package.json index 718a042fbc8e..12244e84b80d 100644 --- a/packages/taro-mobx-h5/package.json +++ b/packages/taro-mobx-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-h5", - "version": "1.3.5", + "version": "1.3.6", "description": "mobx-h5 for taro", "keywords": [ "mobx", @@ -28,8 +28,8 @@ "nervjs": "^1.4.0" }, "dependencies": { - "@tarojs/mobx-common": "1.3.5", - "@tarojs/taro-h5": "1.3.5" + "@tarojs/mobx-common": "1.3.6", + "@tarojs/taro-h5": "1.3.6" }, "devDependencies": { "rimraf": "^2.6.2", diff --git a/packages/taro-mobx-rn/package.json b/packages/taro-mobx-rn/package.json index bdc73ef9de02..1740824d4cc1 100644 --- a/packages/taro-mobx-rn/package.json +++ b/packages/taro-mobx-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-rn", - "version": "1.3.5", + "version": "1.3.6", "description": "mobx-rn for taro", "keywords": [ "mobx", @@ -18,7 +18,7 @@ "src" ], "dependencies": { - "@tarojs/mobx-common": "1.3.5", - "@tarojs/taro-rn": "1.3.5" + "@tarojs/mobx-common": "1.3.6", + "@tarojs/taro-rn": "1.3.6" } } diff --git a/packages/taro-mobx/package.json b/packages/taro-mobx/package.json index 61d67af2cbac..cd7c757dedb7 100644 --- a/packages/taro-mobx/package.json +++ b/packages/taro-mobx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx", - "version": "1.3.5", + "version": "1.3.6", "description": "mobx for taro", "keywords": [ "mobx", @@ -24,8 +24,8 @@ "clear": "rimraf dist" }, "dependencies": { - "@tarojs/taro": "1.3.5", - "@tarojs/mobx-common": "1.3.5" + "@tarojs/mobx-common": "1.3.6", + "@tarojs/taro": "1.3.6" }, "devDependencies": { "rimraf": "^2.6.2", diff --git a/packages/taro-plugin-babel/package.json b/packages/taro-plugin-babel/package.json index 5250f5195ec2..b7fa0aedf3f1 100644 --- a/packages/taro-plugin-babel/package.json +++ b/packages/taro-plugin-babel/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-babel", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro babel编译", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-csso/package.json b/packages/taro-plugin-csso/package.json index a7fbfebfb256..b27cc50d7fca 100644 --- a/packages/taro-plugin-csso/package.json +++ b/packages/taro-plugin-csso/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-csso", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro压缩CSS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-less/package.json b/packages/taro-plugin-less/package.json index 1662d6cdb50b..27c0628d6ad4 100644 --- a/packages/taro-plugin-less/package.json +++ b/packages/taro-plugin-less/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-less", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro 编译 less 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-sass/package.json b/packages/taro-plugin-sass/package.json index ae6d0228a41b..baaa1d1ef94f 100644 --- a/packages/taro-plugin-sass/package.json +++ b/packages/taro-plugin-sass/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-sass", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro编译sass文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-stylus/package.json b/packages/taro-plugin-stylus/package.json index af72a44ae406..aa0168c97a05 100644 --- a/packages/taro-plugin-stylus/package.json +++ b/packages/taro-plugin-stylus/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-stylus", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro 编译 stylus 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-typescript/package.json b/packages/taro-plugin-typescript/package.json index 6d14c4d2c4aa..fe37ccb211f1 100644 --- a/packages/taro-plugin-typescript/package.json +++ b/packages/taro-plugin-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-typescript", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro TypeScript 编译插件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-uglifyjs/package.json b/packages/taro-plugin-uglifyjs/package.json index 593341ffc770..3db9e94eff69 100644 --- a/packages/taro-plugin-uglifyjs/package.json +++ b/packages/taro-plugin-uglifyjs/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-uglifyjs", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro压缩JS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-qq/package.json b/packages/taro-qq/package.json index f7d3e9f958c6..6d8e444f8a45 100644 --- a/packages/taro-qq/package.json +++ b/packages/taro-qq/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-qq", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro qq framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.5", - "@tarojs/utils": "1.3.5", + "@tarojs/taro": "1.3.6", + "@tarojs/utils": "1.3.6", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-quickapp/package.json b/packages/taro-quickapp/package.json index c93058638166..a9171b097042 100644 --- a/packages/taro-quickapp/package.json +++ b/packages/taro-quickapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-quickapp", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro quickapp framework", "main": "index.js", "files": [ @@ -23,8 +23,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.5", - "@tarojs/utils": "1.3.5", + "@tarojs/taro": "1.3.6", + "@tarojs/utils": "1.3.6", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-redux-h5/package.json b/packages/taro-redux-h5/package.json index ea896d4ea41c..8dd80265404f 100644 --- a/packages/taro-redux-h5/package.json +++ b/packages/taro-redux-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux-h5", - "version": "1.3.5", + "version": "1.3.6", "description": "Forked react-redux for taro", "keywords": [ "react", @@ -46,7 +46,7 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.49", "@babel/plugin-transform-react-jsx": "^7.0.0-beta.49", "@babel/preset-env": "^7.0.0-beta.49", - "@tarojs/taro-h5": "1.3.5", + "@tarojs/taro-h5": "1.3.6", "babel-plugin-transform-react-remove-prop-types": "^0.4.13", "redux": "^4.0.0", "rimraf": "^2.6.2", diff --git a/packages/taro-redux-rn/package.json b/packages/taro-redux-rn/package.json index 41bf668acbd4..22a790b2b31f 100644 --- a/packages/taro-redux-rn/package.json +++ b/packages/taro-redux-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-redux-rn", - "version": "1.3.5", + "version": "1.3.6", "description": "taro-redux-rn", "main": "./src/index.js", "files": [ diff --git a/packages/taro-redux/package.json b/packages/taro-redux/package.json index 039a89e1b33c..d0337d6addf5 100644 --- a/packages/taro-redux/package.json +++ b/packages/taro-redux/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux", - "version": "1.3.5", + "version": "1.3.6", "description": "Redux for Taro", "main": "index.js", "typings": "types/index.d.ts", @@ -31,7 +31,7 @@ "jest": "^23.1.0" }, "dependencies": { - "@tarojs/taro": "1.3.5", - "@tarojs/utils": "1.3.5" + "@tarojs/taro": "1.3.6", + "@tarojs/utils": "1.3.6" } } diff --git a/packages/taro-rn-runner/package.json b/packages/taro-rn-runner/package.json index a54245027d32..9cc6995cf198 100644 --- a/packages/taro-rn-runner/package.json +++ b/packages/taro-rn-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-runner", - "version": "1.3.5", + "version": "1.3.6", "description": "ReactNative build tool for taro", "main": "index.js", "scripts": { diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json index 4013480a3b86..aedb4b19d450 100644 --- a/packages/taro-rn/package.json +++ b/packages/taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-rn", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro RN framework", "main": "./index.js", "files": [ @@ -27,7 +27,7 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.5", + "@tarojs/taro": "1.3.6", "base64-js": "^1.3.0", "react-native-image-crop-picker": "^0.23.1", "react-native-image-zoom-viewer": "^2.2.13", diff --git a/packages/taro-router-rn/package.json b/packages/taro-router-rn/package.json index cd970a1dbd2b..a63aba0608f5 100644 --- a/packages/taro-router-rn/package.json +++ b/packages/taro-router-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-router-rn", - "version": "1.3.5", + "version": "1.3.6", "description": "taro-router-rn", "main": "./index.js", "files": [ diff --git a/packages/taro-router/package.json b/packages/taro-router/package.json index bdc8976fdbcc..4510f658e668 100644 --- a/packages/taro-router/package.json +++ b/packages/taro-router/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/router", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro-router", "main:h5": "dist/index.esm.js", "main": "index.js", @@ -41,7 +41,7 @@ "@babel/plugin-syntax-dynamic-import": "7.0.0", "@babel/plugin-transform-react-jsx": "7.0.0", "@babel/preset-env": "7.1.5", - "@tarojs/taro-h5": "1.3.5", + "@tarojs/taro-h5": "1.3.6", "@types/history": "4.7.2", "@types/jasmine": "2.8.11", "@types/jest": "23.3.9", diff --git a/packages/taro-swan/package.json b/packages/taro-swan/package.json index ef7d09f1ed70..bf3dd3e9d4a7 100644 --- a/packages/taro-swan/package.json +++ b/packages/taro-swan/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-swan", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro swan framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.5", - "@tarojs/utils": "1.3.5", + "@tarojs/taro": "1.3.6", + "@tarojs/utils": "1.3.6", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-transformer-wx/package.json b/packages/taro-transformer-wx/package.json index 65899fe42dfd..bd316ac8bcdb 100644 --- a/packages/taro-transformer-wx/package.json +++ b/packages/taro-transformer-wx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/transformer-wx", - "version": "1.3.5", + "version": "1.3.6", "description": "Transfrom Nerv Component to Wechat mini program.", "repository": { "type": "git", @@ -62,14 +62,14 @@ "babel-types": "^6.26.0", "eslint": "^4.15.0", "eslint-plugin-react": "7.10.0", - "eslint-plugin-taro": "1.3.5", + "eslint-plugin-taro": "1.3.6", "html": "^1.0.0", "lodash": "^4.17.5", "prettier": "^1.14.2", "typescript": "^3.2.2" }, "devDependencies": { - "@tarojs/taro": "1.3.5", + "@tarojs/taro": "1.3.6", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.1", "@types/babel-template": "^6.25.0", diff --git a/packages/taro-tt/package.json b/packages/taro-tt/package.json index ff5bc25a971a..675933dbb628 100644 --- a/packages/taro-tt/package.json +++ b/packages/taro-tt/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-tt", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro toutiao framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.5", - "@tarojs/utils": "1.3.5", + "@tarojs/taro": "1.3.6", + "@tarojs/utils": "1.3.6", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-utils/package.json b/packages/taro-utils/package.json index e51ce1aef53e..1edc0295279d 100644 --- a/packages/taro-utils/package.json +++ b/packages/taro-utils/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/utils", - "version": "1.3.5", + "version": "1.3.6", "description": "Utils for Taro", "main": "index.js", "scripts": { diff --git a/packages/taro-weapp/package.json b/packages/taro-weapp/package.json index 94b7a55b8afc..8d78569e0d38 100644 --- a/packages/taro-weapp/package.json +++ b/packages/taro-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-weapp", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro weapp framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.5", - "@tarojs/utils": "1.3.5", + "@tarojs/taro": "1.3.6", + "@tarojs/utils": "1.3.6", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json index aab64289b057..3d882db3fad9 100644 --- a/packages/taro-webpack-runner/package.json +++ b/packages/taro-webpack-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/webpack-runner", - "version": "1.3.5", + "version": "1.3.6", "description": "webpack runner for taro", "main": "index.js", "scripts": { @@ -32,13 +32,13 @@ }, "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { - "@tarojs/taro-h5": "1.3.5", + "@tarojs/taro-h5": "1.3.6", "autoprefixer": "8.6.4", "babel-core": "6.26.0", "babel-loader": "7.1.4", "babel-plugin-syntax-dynamic-import": "6.18.0", "babel-plugin-transform-react-jsx": "6.24.1", - "babel-plugin-transform-taroapi": "1.3.5", + "babel-plugin-transform-taroapi": "1.3.6", "babel-types": "6.26.0", "chalk": "2.4.2", "copy-webpack-plugin": "^5.0.3", @@ -55,8 +55,8 @@ "opn": "5.3.0", "ora": "2.1.0", "postcss-loader": "2.1.6", - "postcss-plugin-constparse": "1.3.5", - "postcss-pxtransform": "1.3.5", + "postcss-plugin-constparse": "1.3.6", + "postcss-pxtransform": "1.3.6", "resolve": "1.8.1", "resolve-url-loader": "2.3.0", "sass-loader": "7.1.0", diff --git a/packages/taro-with-weapp/package.json b/packages/taro-with-weapp/package.json index d49c20bee3a6..a4807fd3bbfd 100644 --- a/packages/taro-with-weapp/package.json +++ b/packages/taro-with-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/with-weapp", - "version": "1.3.5", + "version": "1.3.6", "description": "taroize 之后的运行时", "main": "index.js", "scripts": { @@ -22,7 +22,7 @@ "author": "yuche", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.5", + "@tarojs/taro": "1.3.6", "lodash": "^4.17.11" }, "devDependencies": { diff --git a/packages/taro/package.json b/packages/taro/package.json index 4ed0b472344e..f680aa09d04a 100644 --- a/packages/taro/package.json +++ b/packages/taro/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro", - "version": "1.3.5", + "version": "1.3.6", "description": "Taro framework", "module": "dist/index.esm.js", "main": "index.js", diff --git a/packages/taroize/package.json b/packages/taroize/package.json index c7baa38e4bb8..be111b02c733 100644 --- a/packages/taroize/package.json +++ b/packages/taroize/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taroize", - "version": "1.3.5", + "version": "1.3.6", "description": "转换原生微信小程序代码为 Taro 代码", "main": "index.js", "files": [ From e6bf8292388efb29e35ce9809445ec5aef500575 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 8 Jul 2019 19:42:08 +0800 Subject: [PATCH 139/158] chore: changelog --- CHANGELOG.md | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f51eb47f85c..db1455fb40c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,38 @@ -# [](https://github.com/NervJS/taro/compare/v1.3.5...v) (2019-07-03) +# [](https://github.com/NervJS/taro/compare/v1.3.6...v) (2019-07-08) + + + + +## [1.3.6](https://github.com/NervJS/taro/compare/v1.3.5...v1.3.6) (2019-07-08) + + +### Bug Fixes + +* **cli:** 快应用支持多端组件,close [#3685](https://github.com/NervJS/taro/issues/3685) ([adf68af](https://github.com/NervJS/taro/commit/adf68af)) +* **component:** 修复 Swiper 组件指示标初始为 false ,更新不显示问题, close [#3676](https://github.com/NervJS/taro/issues/3676) ([0ecb399](https://github.com/NervJS/taro/commit/0ecb399)) +* **components:** H5 不支持 camera 组件,修改文档 ([697c74b](https://github.com/NervJS/taro/commit/697c74b)) +* **h5:** Page组件增加$component对象,与微信小程序统一 ([cd54061](https://github.com/NervJS/taro/commit/cd54061)) +* **quickapp:** 快应用支持 Block 标签,close [#3686](https://github.com/NervJS/taro/issues/3686) ([2dfeafe](https://github.com/NervJS/taro/commit/2dfeafe)) +* **router:** 解决getCurrentPages有时候只能获取长度但没有内容的问题 ([#3669](https://github.com/NervJS/taro/issues/3669)) ([a88225e](https://github.com/NervJS/taro/commit/a88225e)) +* **taro:** interceptor 暴露 request 返回的 requestTask。close [#3654](https://github.com/NervJS/taro/issues/3654) ([2ada5a2](https://github.com/NervJS/taro/commit/2ada5a2)) +* **taro:** 修复 this.$router 类型错误 close [#3650](https://github.com/NervJS/taro/issues/3650) ([#3653](https://github.com/NervJS/taro/issues/3653)) ([557938e](https://github.com/NervJS/taro/commit/557938e)) +* **taro-cli:** 添加 json 文件缺失的逗号 ([#3707](https://github.com/NervJS/taro/issues/3707)) ([b6c3be9](https://github.com/NervJS/taro/commit/b6c3be9)) +* **taro-quickapp:** 修复快应用 tabBar 图标显示问题 ([81cbdf7](https://github.com/NervJS/taro/commit/81cbdf7)) +* **taroize:** 加强对对象扩展运算符的支持,close [#3632](https://github.com/NervJS/taro/issues/3632) ([e3c638e](https://github.com/NervJS/taro/commit/e3c638e)) +* **transformer:** 使用 spread/rest 语法生成匿名函数 ([75fc37a](https://github.com/NervJS/taro/commit/75fc37a)), closes [#3577](https://github.com/NervJS/taro/issues/3577) +* **transformer:** 修复 11964f8 对 JSX 属性判断错误,close [#3697](https://github.com/NervJS/taro/issues/3697) ([24e717f](https://github.com/NervJS/taro/commit/24e717f)) +* **transformer:** 修复 46604f5 导致 indexKey 没有加入循环中 ([61c54c6](https://github.com/NervJS/taro/commit/61c54c6)), closes [#3665](https://github.com/NervJS/taro/issues/3665) +* **transformer:** 匿名变量生成位置错误 ([c3086ae](https://github.com/NervJS/taro/commit/c3086ae)) +* **transformer:** 如果循环在三元表达式中没有被 JSX 包裹住解析出错 ([f879bf6](https://github.com/NervJS/taro/commit/f879bf6)), closes [#3646](https://github.com/NervJS/taro/issues/3646) + + +### Features + +* **mobx:** 提供 Mobx Hooks API ([#3599](https://github.com/NervJS/taro/issues/3599)) ([3a3bbdb](https://github.com/NervJS/taro/commit/3a3bbdb)) +* **quickapp:** 新增快应用的一些 api 及组件 ([ddf279b](https://github.com/NervJS/taro/commit/ddf279b)) +* **taroize:** 生命周期函数支持 async/await, close [#3477](https://github.com/NervJS/taro/issues/3477) ([c7b76ab](https://github.com/NervJS/taro/commit/c7b76ab)) +* **transformer:** 支持普通函数表达式定义组件,close [#3682](https://github.com/NervJS/taro/issues/3682) ([e16e671](https://github.com/NervJS/taro/commit/e16e671)) From b007a49841eff37eae1b44d87e75375ae081124e Mon Sep 17 00:00:00 2001 From: Garfield Lee Date: Mon, 8 Jul 2019 19:46:47 +0800 Subject: [PATCH 140/158] =?UTF-8?q?fix(taro):=20=E4=B8=BA=20Taro.request?= =?UTF-8?q?=20=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89=E6=B7=BB=E5=8A=A0=20abo?= =?UTF-8?q?rt=20=E6=96=B9=E6=B3=95=EF=BC=8C=E5=AE=8C=E5=96=84=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=20#3654=20(#3715)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(taro): 为 Taro.request 类型定义添加 abort 方法,完善注释 #3654 * docs(request): 更新 Taro.request abort 相关文档 --- docs/apis/network/request/request.md | 22 ++++++- packages/taro/types/index.d.ts | 95 +++++++++++++++++----------- 2 files changed, 77 insertions(+), 40 deletions(-) diff --git a/docs/apis/network/request/request.md b/docs/apis/network/request/request.md index 34f6ae20f2a9..e0dc36122199 100644 --- a/docs/apis/network/request/request.md +++ b/docs/apis/network/request/request.md @@ -3,9 +3,10 @@ title: Taro.request(OBJECT) sidebar_label: request --- - 发起网络请求,支持 `Promise` 化使用。 +> 暂不支持使用 [RequestTask.onHeadersReceived(function callback)](https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.onHeadersReceived.html) 和 [RequestTask.offHeadersReceived(function callback)](https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.offHeadersReceived.html) 方法。 + **OBJECT 参数说明:** | 参数 | 类型 | 必填 | 默认值 | 说明 | @@ -56,12 +57,27 @@ Taro.request({ .then(res => console.log(res.data)) ``` +## 小程序端使用 RequestTask.abort() +```jsx +const requestTask = Taro.request({ + url: 'test.php', //仅为示例,并非真实的接口地址 + data: { + x: '' , + y: '' + }, + header: { + 'content-type': 'application/json' + }, + success (res) { + console.log(res.data) + } +}) +requestTask.abort() // 取消请求任务 +``` ## API支持度 - | API | 微信小程序 | H5 | React Native | 支付宝小程序 | 百度小程序 | 头条小程序 | QQ 轻应用 | | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | | Taro.request | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | - diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts index b3db2dbf0bcb..7ecff383413b 100644 --- a/packages/taro/types/index.d.ts +++ b/packages/taro/types/index.d.ts @@ -898,6 +898,17 @@ declare namespace Taro { */ header: any } + /** + * 网络请求任务对象 + * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.html + */ + interface requestTask extends Promise> { + /** + * 中断请求任务 + * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.abort.html + */ + abort(): void + } type Param < P extends any | string | ArrayBuffer = any > = { /** * 开发者服务器接口地址 @@ -1028,11 +1039,11 @@ declare namespace Taro { * 发起网络请求。**使用前请先阅读[说明](https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html)**。 * * **返回值:** + * + * @returns {request.requestTask} 返回一个 `requestTask` 对象,通过 `requestTask`,可中断请求任务。 * * @since 1.4.0 * - * 返回一个 `requestTask` 对象,通过 `requestTask`,可中断请求任务。 - * * **Bug & Tip:** * * 1. `tip`: content-type 默认为 'application/json'; @@ -1040,44 +1051,54 @@ declare namespace Taro { * 3. `bug`: 开发者工具 `0.10.102800` 版本,`header` 的 `content-type` 设置异常; * * **示例代码:** + * + * @example + * // 回调函数(Callback)用法: + * const requestTask = Taro.request({ + * url: 'test.php', //仅为示例,并非真实的接口地址 + * data: { + * x: '' , + * y: '' + * }, + * header: { + * 'content-type': 'application/json' // 默认值 + * }, + * success: function(res) { + * console.log(res.data) + * } + * }) + * requestTask.abort() + * + * // Promise 用法: + * const requestTask = Taro.request({ + * url: 'test.php', //仅为示例,并非真实的接口地址 + * data: { + * x: '' , + * y: '' + * }, + * header: { + * 'content-type': 'application/json' // 默认值 + * }, + * success: function(res) { + * console.log(res.data) + * } + * }) + * requestTask.then(res => { + * console.log(res.data) + * }) + * requestTask.abort() + * + * // async/await 用法: + * const requestTask = Taro.request(params) + * const res = await requestTask + * requestTask.abort() + * + * // 不需要 abort 的 async/await 用法: + * const res = await Taro.request(params) * - ```javascript - Taro.request({ - url: 'test.php', //仅为示例,并非真实的接口地址 - data: { - x: '' , - y: '' - }, - header: { - 'content-type': 'application/json' // 默认值 - }, - success: function(res) { - console.log(res.data) - } - }) - ``` - * - * **示例代码:** - * - ```javascript - const requestTask = Taro.request({ - url: 'test.php', //仅为示例,并非真实的接口地址 - data: { - x: '' , - y: '' - }, - header: { - 'content-type': 'application/json' - }, - success: function(res) { - console.log(res.data) - } - }) - requestTask.abort() // 取消请求任务 - ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html */ - function request(OBJECT: request.Param): Promise> + function request(OBJECT: request.Param): request.requestTask type arrayBuffer = Uint8Array | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | ArrayBuffer From ceaa48758de69398b4ef360fda32dccef52602ef Mon Sep 17 00:00:00 2001 From: Garfield Lee Date: Mon, 8 Jul 2019 19:47:11 +0800 Subject: [PATCH 141/158] =?UTF-8?q?docs(best-practice):=20=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=20typo=20(#3711)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/best-practice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/best-practice.md b/docs/best-practice.md index 070d7c7175ba..05c6cde20b04 100644 --- a/docs/best-practice.md +++ b/docs/best-practice.md @@ -172,7 +172,7 @@ class App extends Component { ### 组件 `state` 与 `props` 里字段重名的问题 -不要在 `state` 与 `props` 上用同名的字段,因为这些被字段在微信小程序中都会挂在 `data` 上。 +不要在 `state` 与 `props` 上用同名的字段,因为这些字段在微信小程序中都会挂在 `data` 上。 ### 小程序中页面生命周期 `componentWillMount` 不一致问题 From d904a7985d077b43e5286521c5018eb48235c4da Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Mon, 8 Jul 2019 20:29:13 +0800 Subject: [PATCH 142/158] =?UTF-8?q?fix(taro-alipay):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=E5=88=86=E5=8C=85=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82close=20#3445?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把 propsManager 挂在全局对象 my 上。 --- packages/taro-alipay/src/create-component.js | 7 ++- packages/taro-alipay/src/index.js | 3 +- packages/taro-transformer-wx/src/index.ts | 48 +++++++++++++++----- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/packages/taro-alipay/src/create-component.js b/packages/taro-alipay/src/create-component.js index 62703164150d..aca9e8e7e834 100644 --- a/packages/taro-alipay/src/create-component.js +++ b/packages/taro-alipay/src/create-component.js @@ -3,7 +3,6 @@ import { commitAttachRef, detachAllRef, Current, eventCenter } from '@tarojs/tar import { isEmptyObject, isFunction, isArray } from './util' import { mountComponent } from './lifecycle' import { cacheDataSet, cacheDataGet, cacheDataHas } from './data-cache' -import propsManager from './propsManager' const anonymousFnNamePreffix = 'funPrivate' const COLLECT_CHILDS = 'onTaroCollectChilds' @@ -174,7 +173,7 @@ export function componentTrigger (component, key, args) { if (key === 'componentWillUnmount') { if (component.$scope.props) { const compid = component.$scope.props.compid - if (compid) propsManager.delete(compid) + if (compid) my.propsManager.delete(compid) } } @@ -316,7 +315,7 @@ function createComponent (ComponentClass, isPage) { Object.assign(weappComponentConf, { didMount () { const compid = this.props.compid - const props = filterProps(ComponentClass.defaultProps, propsManager.map[compid], {}) + const props = filterProps(ComponentClass.defaultProps, my.propsManager.map[compid], {}) this.$component = new ComponentClass(props, isPage) this.$component._init(this) @@ -324,7 +323,7 @@ function createComponent (ComponentClass, isPage) { this.$component.__propTypes = ComponentClass.propTypes if (compid) { - propsManager.observers[compid] = { + my.propsManager.observers[compid] = { component: this.$component, ComponentClass } diff --git a/packages/taro-alipay/src/index.js b/packages/taro-alipay/src/index.js index 44a1e3423e29..5dd6a17f6642 100644 --- a/packages/taro-alipay/src/index.js +++ b/packages/taro-alipay/src/index.js @@ -33,6 +33,8 @@ import initNativeApi from './native-api' import propsManager from './propsManager' import { getElementById, genCompid } from './util' +if (!my.propsManager) my.propsManager = propsManager + export const Taro = { Component, PureComponent, @@ -51,7 +53,6 @@ export const Taro = { internal_get_original, interceptors, getElementById, - propsManager, genCompid, useEffect, useLayoutEffect, diff --git a/packages/taro-transformer-wx/src/index.ts b/packages/taro-transformer-wx/src/index.ts index 7481502f6362..a6e912fe9fa1 100644 --- a/packages/taro-transformer-wx/src/index.ts +++ b/packages/taro-transformer-wx/src/index.ts @@ -676,10 +676,14 @@ export default function transform (options: Options): TransformResult { t.importSpecifier(t.identifier(INTERNAL_GET_ORIGNAL), t.identifier(INTERNAL_GET_ORIGNAL)), t.importSpecifier(t.identifier(INTERNAL_INLINE_STYLE), t.identifier(INTERNAL_INLINE_STYLE)), t.importSpecifier(t.identifier(GEL_ELEMENT_BY_ID), t.identifier(GEL_ELEMENT_BY_ID)), - t.importSpecifier(t.identifier(PROPS_MANAGER), t.identifier(PROPS_MANAGER)), t.importSpecifier(t.identifier(GEN_COMP_ID), t.identifier(GEN_COMP_ID)), t.importSpecifier(t.identifier(GEN_LOOP_COMPID), t.identifier(GEN_LOOP_COMPID)) ) + if (Adapter.type !== Adapters.alipay) { + path.node.specifiers.push( + t.importSpecifier(t.identifier(PROPS_MANAGER), t.identifier(PROPS_MANAGER)) + ) + } } if ( source === REDUX_PACKAGE_NAME || source === MOBX_PACKAGE_NAME @@ -717,17 +721,20 @@ export default function transform (options: Options): TransformResult { }) if (!isImportTaro) { + const specifiers = [ + t.importDefaultSpecifier(t.identifier('Taro')), + t.importSpecifier(t.identifier(INTERNAL_SAFE_GET), t.identifier(INTERNAL_SAFE_GET)), + t.importSpecifier(t.identifier(INTERNAL_GET_ORIGNAL), t.identifier(INTERNAL_GET_ORIGNAL)), + t.importSpecifier(t.identifier(INTERNAL_INLINE_STYLE), t.identifier(INTERNAL_INLINE_STYLE)), + t.importSpecifier(t.identifier(GEL_ELEMENT_BY_ID), t.identifier(GEL_ELEMENT_BY_ID)), + t.importSpecifier(t.identifier(GEN_COMP_ID), t.identifier(GEN_COMP_ID)), + t.importSpecifier(t.identifier(GEN_LOOP_COMPID), t.identifier(GEN_LOOP_COMPID)) + ] + if (Adapter.type !== Adapters.alipay) { + specifiers.push(t.importSpecifier(t.identifier(PROPS_MANAGER), t.identifier(PROPS_MANAGER))) + } ast.program.body.unshift( - t.importDeclaration([ - t.importDefaultSpecifier(t.identifier('Taro')), - t.importSpecifier(t.identifier(INTERNAL_SAFE_GET), t.identifier(INTERNAL_SAFE_GET)), - t.importSpecifier(t.identifier(INTERNAL_GET_ORIGNAL), t.identifier(INTERNAL_GET_ORIGNAL)), - t.importSpecifier(t.identifier(INTERNAL_INLINE_STYLE), t.identifier(INTERNAL_INLINE_STYLE)), - t.importSpecifier(t.identifier(GEL_ELEMENT_BY_ID), t.identifier(GEL_ELEMENT_BY_ID)), - t.importSpecifier(t.identifier(PROPS_MANAGER), t.identifier(PROPS_MANAGER)), - t.importSpecifier(t.identifier(GEN_COMP_ID), t.identifier(GEN_COMP_ID)), - t.importSpecifier(t.identifier(GEN_LOOP_COMPID), t.identifier(GEN_LOOP_COMPID)) - ], t.stringLiteral('@tarojs/taro')) + t.importDeclaration(specifiers, t.stringLiteral('@tarojs/taro')) ) } @@ -735,6 +742,25 @@ export default function transform (options: Options): TransformResult { throw new Error('未找到 Taro.Component 的类定义') } + if (Adapter.type === Adapters.alipay) { + const body = ast.program.body + for (const i in body) { + if (t.isImportDeclaration(body[i]) && !t.isImportDeclaration(body[Number(i) + 1])) { + body.splice(Number(i) + 1, 0, t.variableDeclaration( + 'const', + [t.variableDeclarator( + t.identifier('propsManager'), + t.memberExpression( + t.identifier('my'), + t.identifier('propsManager') + ) + )] + )) + break + } + } + } + mainClass.node.body.body.forEach(handleThirdPartyComponent) const storeBinding = mainClass.scope.getBinding(storeName) mainClass.scope.rename('Component', '__BaseComponent') From 2b8f024e960a72cda06c263350a0085d5d6b58f8 Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Mon, 8 Jul 2019 21:03:53 +0800 Subject: [PATCH 143/158] =?UTF-8?q?fix(taro-alipay):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=E5=88=86=E5=8C=85=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82close=20#3703?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把全局事件对象 eventCenter 挂在全局对象 my 上。 --- packages/taro/src/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/taro/src/index.js b/packages/taro/src/index.js index e0cf74ebdba7..b0f78638ba28 100644 --- a/packages/taro/src/index.js +++ b/packages/taro/src/index.js @@ -33,7 +33,15 @@ import { Current } from './current' import { createContext } from './create-context' import { memo } from './memo' -const eventCenter = new Events() +let eventCenter +if (process.env.TARO_ENV === 'alipay') { + if (!my.taroEventCenter) { + my.taroEventCenter = new Events() + } + eventCenter = my.taroEventCenter +} else { + eventCenter = new Events() +} export { Component, From 2890b8cd6a7df47f2f2c6cc26591dfc761307bce Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 8 Jul 2019 21:02:23 +0800 Subject: [PATCH 144/158] =?UTF-8?q?feat(cli):=20transformer=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8F=82=E6=95=B0=20alias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/mini/component.ts | 12 ++++++++---- packages/taro-cli/src/mini/page.ts | 9 ++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/taro-cli/src/mini/component.ts b/packages/taro-cli/src/mini/component.ts index 328faf9bc46b..79b982430054 100644 --- a/packages/taro-cli/src/mini/component.ts +++ b/packages/taro-cli/src/mini/component.ts @@ -60,7 +60,8 @@ export function isFileToBeTaroComponent ( buildAdapter, sourceDir, constantsReplaceList, - jsxAttributeNameReplace + jsxAttributeNameReplace, + alias } = getBuildData() const transformResult: IWxTransformResult = wxTransformer({ code, @@ -71,7 +72,8 @@ export function isFileToBeTaroComponent ( isTyped: REG_TYPESCRIPT.test(sourcePath), adapter: buildAdapter, env: constantsReplaceList, - jsxAttributeNameReplace + jsxAttributeNameReplace, + alias }) const { ast }: IWxTransformResult = transformResult let isTaroComponent = false @@ -143,7 +145,8 @@ export async function buildSingleComponent ( outputFilesTypes, isProduction, jsxAttributeNameReplace, - projectConfig + projectConfig, + alias } = getBuildData() const isQuickApp = buildAdapter === BUILD_TYPES.QUICKAPP @@ -231,7 +234,8 @@ export async function buildSingleComponent ( isNormal: false, adapter: buildAdapter, env: constantsReplaceList, - jsxAttributeNameReplace + jsxAttributeNameReplace, + alias }) const componentWXMLContent = isProduction ? transformResult.compressedTemplate : transformResult.template const componentDepComponents = transformResult.components diff --git a/packages/taro-cli/src/mini/page.ts b/packages/taro-cli/src/mini/page.ts index 348f385c2479..5b7a105c52a9 100644 --- a/packages/taro-cli/src/mini/page.ts +++ b/packages/taro-cli/src/mini/page.ts @@ -59,7 +59,8 @@ export async function buildSinglePage (page: string) { jsxAttributeNameReplace, pageConfigs, appConfig, - projectConfig + projectConfig, + alias } = getBuildData() const pagePath = path.join(sourceDir, `${page}`) const pageJs = resolveScriptPath(pagePath) @@ -107,7 +108,8 @@ export async function buildSinglePage (page: string) { isRoot: true, isTyped: REG_TYPESCRIPT.test(pageJs), adapter: buildAdapter, - env: constantsReplaceList + env: constantsReplaceList, + alias }) const res = parseAst(PARSE_AST_TYPE.PAGE, aheadTransformResult.ast, [], pageJs, outputPageJSPath) if (res.configObj.enablePullDownRefresh || (appConfig.window && appConfig.window.enablePullDownRefresh)) { @@ -131,7 +133,8 @@ export async function buildSinglePage (page: string) { adapter: buildAdapter, env: constantsReplaceList, rootProps, - jsxAttributeNameReplace + jsxAttributeNameReplace, + alias }) const pageDepComponents = transformResult.components const pageWXMLContent = isProduction ? transformResult.compressedTemplate : transformResult.template From 397b01728d5793c291d3beb65c7f947d54c4c32a Mon Sep 17 00:00:00 2001 From: jinjinjin0731 <709899428@qq.com> Date: Tue, 9 Jul 2019 14:29:58 +0800 Subject: [PATCH 145/158] =?UTF-8?q?fix(components):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=BF=AB=E5=BA=94=E7=94=A8=20WebView=20=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82=20close=20#3451,=20#3724?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/{webview => web-view}/index.ux | 1 + 1 file changed, 1 insertion(+) rename packages/taro-components-qa/src/components/{webview => web-view}/index.ux (97%) diff --git a/packages/taro-components-qa/src/components/webview/index.ux b/packages/taro-components-qa/src/components/web-view/index.ux similarity index 97% rename from packages/taro-components-qa/src/components/webview/index.ux rename to packages/taro-components-qa/src/components/web-view/index.ux index 5c927042ce34..4010b3511f98 100644 --- a/packages/taro-components-qa/src/components/webview/index.ux +++ b/packages/taro-components-qa/src/components/web-view/index.ux @@ -2,6 +2,7 @@ Date: Tue, 9 Jul 2019 16:00:18 +0800 Subject: [PATCH 146/158] =?UTF-8?q?docs(quick-app):=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=20typo=20(#3729)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/quick-app.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/quick-app.md b/docs/quick-app.md index d26d63af5d27..f48438cf0abf 100644 --- a/docs/quick-app.md +++ b/docs/quick-app.md @@ -3,7 +3,7 @@ title: 快应用端开发流程 --- > 从 **1.3 beta** 版本开始支持快应用开发
-> 本章节主要讲解快应用端端 环境安装-开发-调试-打包-发布 原理及流程 +> 本章节主要讲解快应用端 环境安装-开发-调试-打包-发布 原理及流程 ## 简介 From 8d0b1df5f182c1a0a26ad357d5109ee9fae9a023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=87=8C=E9=9C=84?= Date: Tue, 9 Jul 2019 16:32:35 +0800 Subject: [PATCH 147/158] =?UTF-8?q?fix(taro-rn):=20=E4=BF=AE=E5=A4=8DshowL?= =?UTF-8?q?oading=E6=B2=A1=E6=9C=89=E4=BD=BF=E7=94=A8title=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-rn/src/api/interface/toast.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-rn/src/api/interface/toast.js b/packages/taro-rn/src/api/interface/toast.js index 60353668a979..2a81544fa5de 100644 --- a/packages/taro-rn/src/api/interface/toast.js +++ b/packages/taro-rn/src/api/interface/toast.js @@ -118,7 +118,7 @@ function showToast (options) { } else if (icon === 'loading') { - ToastView = + ToastView = } else if (icon === 'none') { ToastView = From 49a97e9d9e57376fa82389975a253683eac1d577 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 9 Jul 2019 21:26:04 +0800 Subject: [PATCH 148/158] =?UTF-8?q?feat(cli):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=AF=B9=20npm=20=E5=8C=85=E4=B8=AD=E6=96=87=E4=BB=B6=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taro-cli/src/util/resolve_npm_files.ts | 219 ++++++++++++------ 1 file changed, 154 insertions(+), 65 deletions(-) diff --git a/packages/taro-cli/src/util/resolve_npm_files.ts b/packages/taro-cli/src/util/resolve_npm_files.ts index 981cec0f8ed3..bd31b5499c2d 100644 --- a/packages/taro-cli/src/util/resolve_npm_files.ts +++ b/packages/taro-cli/src/util/resolve_npm_files.ts @@ -25,7 +25,9 @@ import { REG_FONT, REG_IMAGE, REG_MEDIA, - REG_JSON + REG_JSON, + taroJsFramework, + NODE_MODULES_REG } from './constants' import defaultUglifyConfig from '../config/uglify' @@ -114,6 +116,105 @@ export function resolveNpmFilesPath ({ return resolvedCache[pkgName] } +function analyzeImportUrl ({ + requirePath, + excludeRequire, + source, + filePath, + files, + isProduction, + npmConfig, + rootNpm, + npmOutputDir, + buildAdapter, + compileConfig = [], + env, + uglify, + babelConfig, + quickappManifest +}: { + requirePath: string, + excludeRequire: string[], + source: any, + filePath: string, + files: string[], + isProduction: boolean, + npmConfig: INpmConfig, + rootNpm: string, + npmOutputDir: string, + buildAdapter: BUILD_TYPES, + compileConfig: {[k: string]: any}, + env: object, + uglify: TogglableOptions, + babelConfig: object, + quickappManifest?: ITaroManifestConfig +}) { + if (excludeRequire.indexOf(requirePath) < 0) { + const quickappPkgs = quickappManifest ? quickappManifest.features : [] + if (isQuickappPkg(requirePath, quickappPkgs)) { + return + } + if (isNpmPkg(requirePath)) { + if (excludeNpmPkgs.indexOf(requirePath) < 0) { + const taroMiniAppFramework = `@tarojs/taro-${buildAdapter}` + if (requirePath === taroJsFramework + && (!NODE_MODULES_REG.test(filePath) || filePath.indexOf(taroMiniAppFramework) < 0)) { + requirePath = taroMiniAppFramework + } + const res = resolveNpmFilesPath({ + pkgName: requirePath, + isProduction, + npmConfig, + buildAdapter, + root: path.dirname(recursiveFindNodeModules(filePath)), + rootNpm, + npmOutputDir, + compileConfig, + env, + uglify, + babelConfig, + quickappManifest + }) + let relativeRequirePath = promoteRelativePath(path.relative(filePath, res.main)) + relativeRequirePath = relativeRequirePath.replace(/node_modules/g, npmConfig.name) + if (buildAdapter === BUILD_TYPES.ALIPAY) { + relativeRequirePath = relativeRequirePath.replace(/@/g, '_') + } + source.value = relativeRequirePath + } + } else { + let realRequirePath = path.resolve(path.dirname(filePath), requirePath) + const tempPathWithJS = `${realRequirePath}.js` + const tempPathWithIndexJS = `${realRequirePath}${path.sep}index.js` + if (fs.existsSync(tempPathWithJS)) { + realRequirePath = tempPathWithJS + requirePath += '.js' + } else if (fs.existsSync(tempPathWithIndexJS)) { + realRequirePath = tempPathWithIndexJS + requirePath += '/index.js' + } + if (files.indexOf(realRequirePath) < 0) { + files.push(realRequirePath) + recursiveRequire({ + filePath: realRequirePath, + files, + isProduction, + npmConfig, + buildAdapter, + rootNpm, + npmOutputDir, + compileConfig, + env, + uglify, + babelConfig, + quickappManifest + }) + } + source.value = requirePath + } + } +} + function parseAst ({ ast, filePath, @@ -174,71 +275,51 @@ function parseAst ({ Program: { exit (astPath) { astPath.traverse({ + ImportDeclaration (astPath) { + const node = astPath.node + const source = node.source + const value = source.value + analyzeImportUrl({ + requirePath: value, + excludeRequire, + source, + filePath, + files, + isProduction, + npmConfig, + rootNpm, + npmOutputDir, + buildAdapter, + compileConfig, + env, + uglify, + babelConfig, + quickappManifest + }) + }, CallExpression (astPath) { const node = astPath.node const callee = node.callee as t.Identifier if (callee.name === 'require') { const args = node.arguments as Array - let requirePath = args[0].value - if (excludeRequire.indexOf(requirePath) < 0) { - const quickappPkgs = quickappManifest ? quickappManifest.features : [] - if (isQuickappPkg(requirePath, quickappPkgs)) { - return - } - if (isNpmPkg(requirePath)) { - if (excludeNpmPkgs.indexOf(requirePath) < 0) { - const res = resolveNpmFilesPath({ - pkgName: requirePath, - isProduction, - npmConfig, - buildAdapter, - root: path.dirname(recursiveFindNodeModules(filePath)), - rootNpm, - npmOutputDir, - compileConfig, - env, - uglify, - babelConfig, - quickappManifest - }) - let relativeRequirePath = promoteRelativePath(path.relative(filePath, res.main)) - relativeRequirePath = relativeRequirePath.replace(/node_modules/g, npmConfig.name) - if (buildAdapter === BUILD_TYPES.ALIPAY) { - relativeRequirePath = relativeRequirePath.replace(/@/g, '_') - } - args[0].value = relativeRequirePath - } - } else { - let realRequirePath = path.resolve(path.dirname(filePath), requirePath) - const tempPathWithJS = `${realRequirePath}.js` - const tempPathWithIndexJS = `${realRequirePath}${path.sep}index.js` - if (fs.existsSync(tempPathWithJS)) { - realRequirePath = tempPathWithJS - requirePath += '.js' - } else if (fs.existsSync(tempPathWithIndexJS)) { - realRequirePath = tempPathWithIndexJS - requirePath += '/index.js' - } - if (files.indexOf(realRequirePath) < 0) { - files.push(realRequirePath) - recursiveRequire({ - filePath: realRequirePath, - files, - isProduction, - npmConfig, - buildAdapter, - rootNpm, - npmOutputDir, - compileConfig, - env, - uglify, - babelConfig, - quickappManifest - }) - } - args[0].value = requirePath - } - } + const requirePath = args[0].value + analyzeImportUrl({ + requirePath, + excludeRequire, + source: args[0], + filePath, + files, + isProduction, + npmConfig, + rootNpm, + npmOutputDir, + buildAdapter, + compileConfig, + env, + uglify, + babelConfig, + quickappManifest + }) } } }) @@ -346,10 +427,18 @@ async function recursiveRequire ({ if (compileInclude && compileInclude.length) { const filePathArr = filePath.split(path.sep) const nodeModulesIndex = filePathArr.indexOf('node_modules') - const npmPkgName = filePathArr[nodeModulesIndex + 1] - if (compileInclude.indexOf(npmPkgName) >= 0) { - const compileScriptRes = await npmProcess.callPlugin('babel', fileContent, filePath, babelConfig, rootNpm) - fileContent = compileScriptRes.code + if (nodeModulesIndex >= 0) { + const npmFilePath = filePathArr.slice(nodeModulesIndex + 1).join('/') + let needCompile = false + compileInclude.forEach(item => { + if (npmFilePath.indexOf(item) >= 0) { + needCompile = true + } + }) + if (needCompile) { + const compileScriptRes = await npmProcess.callPlugin('babel', fileContent, filePath, babelConfig, rootNpm) + fileContent = compileScriptRes.code + } } } if (isProduction && buildAdapter !== BUILD_TYPES.QUICKAPP) { From c9ae6b1720f884ec5e485394b88c2fba62b84454 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 9 Jul 2019 22:32:29 +0800 Subject: [PATCH 149/158] =?UTF-8?q?feat(cli):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=AF=B9=E5=BF=AB=E5=BA=94=E7=94=A8=E7=B3=BB=E7=BB=9F=E5=8C=85?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD=E4=B8=8E=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/util/index.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/taro-cli/src/util/index.ts b/packages/taro-cli/src/util/index.ts index dcfe9c756859..e7f72b981a71 100644 --- a/packages/taro-cli/src/util/index.ts +++ b/packages/taro-cli/src/util/index.ts @@ -3,7 +3,7 @@ import * as path from 'path' import * as crypto from 'crypto' import * as os from 'os' import * as child_process from 'child_process' -import * as chalk from 'chalk' +import chalk from 'chalk' import { mergeWith, isPlainObject, camelCase, flatMap } from 'lodash' import * as minimatch from 'minimatch' import * as t from 'babel-types' @@ -496,15 +496,16 @@ export function copyFiles (appPath: string, copyConfig: ICopyOptions | void) { } export function isQuickappPkg (name: string, quickappPkgs: any[] = []): boolean { - if (!quickappPkgs.length) { - return /@system\./.test(name) - } - let isQuickappPkg = false + const isQuickappPkg = /^@[a-zA-Z]{1,}\.[a-zA-Z]{1,}/.test(name) + let hasSetInManifest = false quickappPkgs.forEach(item => { if (item.name === name.replace(/^@/, '')) { - isQuickappPkg = true + hasSetInManifest = true } }) + if (isQuickappPkg && !hasSetInManifest) { + printLog(processTypeEnum.ERROR, '快应用', `需要在 ${chalk.bold('project.quickapp.json')} 文件的 ${chalk.bold('features')} 配置中添加 ${chalk.bold(name)}`) + } return isQuickappPkg } From dbfabf2ea1b83a2a0f343ce7108d8ce33e0c9520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=87=8C=E9=9C=84?= Date: Wed, 10 Jul 2019 00:24:11 +0800 Subject: [PATCH 150/158] =?UTF-8?q?fix(taro-router-rn):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DRN=E7=AB=AF=E8=A7=A6=E5=8F=91=E4=B8=8D=E4=BA=86?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E5=88=B7=E6=96=B0=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-router-rn/src/getWrappedScreen.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/taro-router-rn/src/getWrappedScreen.js b/packages/taro-router-rn/src/getWrappedScreen.js index c2e54dc6de94..0a1a87d3eb0f 100644 --- a/packages/taro-router-rn/src/getWrappedScreen.js +++ b/packages/taro-router-rn/src/getWrappedScreen.js @@ -153,6 +153,11 @@ function getWrappedScreen (Screen, Taro, globalNavigationOptions = {}) { this.willBlurSubscription && this.willBlurSubscription.remove() } + onPullDownRefresh () { + this.getScreenInstance().onPullDownRefresh && + this.getScreenInstance().onPullDownRefresh() + } + render () { const {globalEnablePullDownRefresh = false} = globalNavigationOptions const {enablePullDownRefresh, disableScroll} = getNavigationOptions(Screen.config) @@ -165,7 +170,7 @@ function getWrappedScreen (Screen, Taro, globalNavigationOptions = {}) { Taro={Taro} enablePullDownRefresh={isScreenEnablePullDownRefresh} disableScroll={disableScroll} - onPullDownRefresh={screenInstance.onPullDownRefresh && screenInstance.onPullDownRefresh.bind(screenInstance)} + onPullDownRefresh={this.onPullDownRefresh.bind(this)} onReachBottom={screenInstance.onReachBottom} onScroll={screenInstance.onScroll} {...this.props} From 0945248e2faf2a2d0f7fcf5f0e52473c85c5d073 Mon Sep 17 00:00:00 2001 From: yuche Date: Tue, 9 Jul 2019 21:35:41 +0800 Subject: [PATCH 151/158] =?UTF-8?q?fix(transformer):=20opt.isNormal=20?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E8=B5=B0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=20babel=20=E6=8F=92=E4=BB=B6=20close=20#3731?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/options.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/taro-transformer-wx/src/options.ts b/packages/taro-transformer-wx/src/options.ts index bc1a7b705ba4..a5fdee9f9c79 100644 --- a/packages/taro-transformer-wx/src/options.ts +++ b/packages/taro-transformer-wx/src/options.ts @@ -32,6 +32,17 @@ export const setTransformOptions = (options: Options) => { export const buildBabelTransformOptions: () => TransformOptions = () => { Status.isSFC = false + let plugins = [ + require('babel-plugin-transform-do-expressions'), + require('babel-plugin-transform-export-extensions'), + require('babel-plugin-transform-flow-strip-types'), + buildVistor(), + functionalComponent, + [require('babel-plugin-transform-define').default, transformOptions.env] + ] + if (!transformOptions.isNormal) { + plugins.push(buildVistor(), functionalComponent) + } return { parserOpts: { sourceType: 'module', @@ -51,14 +62,7 @@ export const buildBabelTransformOptions: () => TransformOptions = () => { 'exportExtensions' ] as any[] }, - plugins: [ - require('babel-plugin-transform-do-expressions'), - require('babel-plugin-transform-export-extensions'), - require('babel-plugin-transform-flow-strip-types'), - buildVistor(), - functionalComponent, - [require('babel-plugin-transform-define').default, transformOptions.env] - ].concat(process.env.ESLINT === 'false' || transformOptions.isNormal || transformOptions.isTyped ? [] : eslintValidation) + plugins: plugins.concat(process.env.ESLINT === 'false' || transformOptions.isNormal || transformOptions.isTyped ? [] : eslintValidation) .concat((isTestEnv) ? [] : require('babel-plugin-remove-dead-code').default) } } From 2b8180bc0979b95b6d16657e05350b153b24829b Mon Sep 17 00:00:00 2001 From: yuche Date: Wed, 10 Jul 2019 10:10:54 +0800 Subject: [PATCH 152/158] =?UTF-8?q?fix(transformer):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=200945248e2faf2a2d0f7fcf5f0e52473c85c5d073=20=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B7=BB=E5=8A=A0=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/options.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/taro-transformer-wx/src/options.ts b/packages/taro-transformer-wx/src/options.ts index a5fdee9f9c79..426669de7778 100644 --- a/packages/taro-transformer-wx/src/options.ts +++ b/packages/taro-transformer-wx/src/options.ts @@ -36,8 +36,6 @@ export const buildBabelTransformOptions: () => TransformOptions = () => { require('babel-plugin-transform-do-expressions'), require('babel-plugin-transform-export-extensions'), require('babel-plugin-transform-flow-strip-types'), - buildVistor(), - functionalComponent, [require('babel-plugin-transform-define').default, transformOptions.env] ] if (!transformOptions.isNormal) { @@ -62,7 +60,8 @@ export const buildBabelTransformOptions: () => TransformOptions = () => { 'exportExtensions' ] as any[] }, - plugins: plugins.concat(process.env.ESLINT === 'false' || transformOptions.isNormal || transformOptions.isTyped ? [] : eslintValidation) - .concat((isTestEnv) ? [] : require('babel-plugin-remove-dead-code').default) + plugins: plugins + .concat(process.env.ESLINT === 'false' || transformOptions.isNormal || transformOptions.isTyped ? [] : eslintValidation) + .concat((isTestEnv) ? [] : require('babel-plugin-remove-dead-code').default) } } From 49bef9e4e9b6d74d2b1248c9cfc5ded8c492c1ef Mon Sep 17 00:00:00 2001 From: luckyadam Date: Wed, 10 Jul 2019 13:43:41 +0800 Subject: [PATCH 153/158] =?UTF-8?q?fix(taro-utils):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20Object.is=20=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-utils/src/shallow-equal.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/taro-utils/src/shallow-equal.js b/packages/taro-utils/src/shallow-equal.js index 25f5cd9f687c..52ad4c946ed2 100644 --- a/packages/taro-utils/src/shallow-equal.js +++ b/packages/taro-utils/src/shallow-equal.js @@ -1,5 +1,5 @@ /* eslint-disable */ -Object.is = Object.is || function (x, y) { +const objectIs = Object.is || function (x, y) { if (x === y) { return x !== 0 || 1 / x === 1 / y } @@ -13,7 +13,7 @@ export default function shallowEqual (obj1, obj2) { if (obj1 === null || obj2 === null) { return false } - if (Object.is(obj1, obj2)) { + if (objectIs(obj1, obj2)) { return true } const obj1Keys = obj1 ? Object.keys(obj1) : [] @@ -24,7 +24,7 @@ export default function shallowEqual (obj1, obj2) { for (let i = 0; i < obj1Keys.length; i++) { const obj1KeyItem = obj1Keys[i] - if (!obj2.hasOwnProperty(obj1KeyItem) || !Object.is(obj1[obj1KeyItem], obj2[obj1KeyItem])) { + if (!obj2.hasOwnProperty(obj1KeyItem) || !objectIs(obj1[obj1KeyItem], obj2[obj1KeyItem])) { return false } } From 3e4e89c1e2834dcf87b3c82be73d84656c255d75 Mon Sep 17 00:00:00 2001 From: Xiaoli <544028951@qq.com> Date: Wed, 10 Jul 2019 14:08:25 +0800 Subject: [PATCH 154/158] =?UTF-8?q?fix(cli):=20h5=E7=AB=AF=E6=94=AF?= =?UTF-8?q?=E6=8C=81alias=E5=88=B0src=E4=B8=8B=E7=9A=84=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=BA=86,=20fix=20#2866?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/h5/index.ts | 41 +++++++++++++------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/packages/taro-cli/src/h5/index.ts b/packages/taro-cli/src/h5/index.ts index a7ba5d32e098..95f6bcbdb20a 100644 --- a/packages/taro-cli/src/h5/index.ts +++ b/packages/taro-cli/src/h5/index.ts @@ -7,20 +7,11 @@ import generate from 'better-babel-generator' import * as chokidar from 'chokidar' import * as fs from 'fs-extra' import * as klaw from 'klaw' -import { findLastIndex, merge } from 'lodash' +import { findLastIndex, mapValues, merge } from 'lodash' import * as path from 'path' import CONFIG from '../config' -import { - isAliasPath, - isNpmPkg, - mergeVisitors, - printLog, - promoteRelativePath, - recursiveMerge, - replaceAliasPath, - resolveScriptPath -} from '../util' +import { isNpmPkg, mergeVisitors, printLog, promoteRelativePath, recursiveMerge, resolveScriptPath } from '../util' import { convertAstExpressionToVariable as toVar, convertObjectToAstExpression as objToAst, @@ -71,7 +62,6 @@ class Compiler { entryFilePath: string entryFileName: string pxTransformConfig - pathAlias pages: string[] = [] constructor (appPath) { @@ -101,7 +91,6 @@ class Compiler { this.tempPath = path.join(appPath, this.tempDir) this.entryFilePath = resolveScriptPath(path.join(this.sourcePath, CONFIG.ENTRY)) this.entryFileName = path.basename(this.entryFilePath) - this.pathAlias = projectConfig.alias || {} this.pxTransformConfig = { designWidth: projectConfig.designWidth || 750 } if (projectConfig.hasOwnProperty(deviceRatioConfigName)) { this.pxTransformConfig.deviceRatio = projectConfig.deviceRatio @@ -179,6 +168,7 @@ class Compiler { const h5Config = this.h5Config const outputDir = this.outputDir const sourceRoot = this.sourceRoot + const sourcePath = this.sourcePath const tempPath = this.tempPath const entryFile = path.basename(entryFileName, path.extname(entryFileName)) + '.js' @@ -189,7 +179,19 @@ class Compiler { if (projectConfig.env) { h5Config.env = projectConfig.env } + + const convertAlias = (filePath: string) => { + const isAbsolute = path.isAbsolute(filePath) + if (!isAbsolute) return filePath + + const relPath = path.relative(sourcePath, filePath) + return relPath.startsWith('..') + ? filePath + : path.resolve(this.tempPath, relPath) + } + recursiveMerge(h5Config, { + alias: mapValues(projectConfig.alias, convertAlias), copy: projectConfig.copy, defineConstants: projectConfig.defineConstants, designWidth: projectConfig.designWidth, @@ -245,7 +247,6 @@ class Compiler { const routerMode = this.routerMode const routerBasename = this.routerBasename const customRoutes = this.customRoutes - const pathAlias = this.pathAlias const pxTransformConfig = this.pxTransformConfig let ast = wxTransformer({ @@ -565,10 +566,7 @@ class Compiler { const node = astPath.node const source = node.source const specifiers = node.specifiers - let value = source.value - if (isAliasPath(value, pathAlias)) { - source.value = value = replaceAliasPath(filePath, value, pathAlias) - } + const value = source.value if (!isNpmPkg(value)) { if (value.indexOf('.') === 0) { const pathArr = value.split('/') @@ -740,8 +738,6 @@ class Compiler { } processOthers (code, filePath, fileType) { - const pathAlias = this.pathAlias - const componentnameMap = new Map() const taroapiMap = new Map() const isPage = fileType === FILE_TYPE.PAGE @@ -844,11 +840,8 @@ class Compiler { enter (astPath: NodePath) { const node = astPath.node const source = node.source - let value = source.value + const value = source.value const specifiers = node.specifiers - if (isAliasPath(value, pathAlias)) { - source.value = value = replaceAliasPath(filePath, value, pathAlias) - } if (!isNpmPkg(value)) { if (REG_SCRIPTS.test(value) || path.extname(value) === '') { const absolutePath = path.resolve(filePath, '..', value) From 12c99981b5dcd83f20da823cbc4ca61ab148f946 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Wed, 10 Jul 2019 14:24:46 +0800 Subject: [PATCH 155/158] =?UTF-8?q?fix(taro-quickapp):=20=E5=BF=AB?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E8=8E=B7=E5=8F=96=E9=A1=B5=E9=9D=A2=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=97=B6=E5=A2=9E=E5=8A=A0=E5=AE=B9=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-quickapp/src/create-component.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/taro-quickapp/src/create-component.js b/packages/taro-quickapp/src/create-component.js index c3649822fdfd..f701e435a9b8 100644 --- a/packages/taro-quickapp/src/create-component.js +++ b/packages/taro-quickapp/src/create-component.js @@ -210,6 +210,9 @@ function bindProperties (componentConf, ComponentClass) { } function getPageUrlParams (url) { + if (!url) { + return {} + } const queryStr = url.replace(/^.*\?&?/, '') const params = queryToJson(queryStr) return params From 827de2df6228c0f8b1a76ea249086dcba55ae365 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Wed, 10 Jul 2019 14:33:58 +0800 Subject: [PATCH 156/158] chore(release): publish v1.3.7 --- lerna.json | 2 +- .../package.json | 2 +- .../package.json | 4 ++-- packages/css-to-react-native/package.json | 2 +- packages/eslint-config-taro/package.json | 4 ++-- packages/eslint-plugin-taro/package.json | 2 +- .../postcss-plugin-constparse/package.json | 2 +- packages/postcss-pxtransform/package.json | 2 +- packages/postcss-unit-transform/package.json | 2 +- .../stylelint-config-taro-rn/package.json | 4 ++-- packages/stylelint-taro-rn/package.json | 2 +- packages/taro-alipay/package.json | 6 ++--- packages/taro-async-await/package.json | 2 +- packages/taro-cli/package.json | 22 +++++++++---------- packages/taro-components-qa/package.json | 2 +- packages/taro-components-rn/package.json | 2 +- packages/taro-components/package.json | 6 ++--- packages/taro-h5/package.json | 6 ++--- packages/taro-mobx-common/package.json | 2 +- packages/taro-mobx-h5/package.json | 6 ++--- packages/taro-mobx-rn/package.json | 6 ++--- packages/taro-mobx/package.json | 6 ++--- packages/taro-plugin-babel/package.json | 2 +- packages/taro-plugin-csso/package.json | 2 +- packages/taro-plugin-less/package.json | 2 +- packages/taro-plugin-sass/package.json | 2 +- packages/taro-plugin-stylus/package.json | 2 +- packages/taro-plugin-typescript/package.json | 2 +- packages/taro-plugin-uglifyjs/package.json | 2 +- packages/taro-qq/package.json | 6 ++--- packages/taro-quickapp/package.json | 6 ++--- packages/taro-redux-h5/package.json | 4 ++-- packages/taro-redux-rn/package.json | 2 +- packages/taro-redux/package.json | 6 ++--- packages/taro-rn-runner/package.json | 2 +- packages/taro-rn/package.json | 4 ++-- packages/taro-router-rn/package.json | 2 +- packages/taro-router/package.json | 4 ++-- packages/taro-swan/package.json | 6 ++--- packages/taro-transformer-wx/package.json | 6 ++--- packages/taro-tt/package.json | 6 ++--- packages/taro-utils/package.json | 2 +- packages/taro-weapp/package.json | 6 ++--- packages/taro-webpack-runner/package.json | 10 ++++----- packages/taro-with-weapp/package.json | 4 ++-- packages/taro/package.json | 2 +- packages/taroize/package.json | 2 +- 47 files changed, 94 insertions(+), 94 deletions(-) diff --git a/lerna.json b/lerna.json index d84edc86433b..abe7320b7159 100644 --- a/lerna.json +++ b/lerna.json @@ -53,6 +53,6 @@ "message": "chore(release): publish %s" } }, - "version": "1.3.6", + "version": "1.3.7", "npmClient": "npm" } diff --git a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json index 7889e2563023..0c04e45fb5e6 100644 --- a/packages/babel-plugin-transform-jsx-to-stylesheet/package.json +++ b/packages/babel-plugin-transform-jsx-to-stylesheet/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-jsx-to-stylesheet", - "version": "1.3.6", + "version": "1.3.7", "description": "Transform stylesheet selector to style in JSX Elements.", "license": "MIT", "main": "src/index.js", diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json index 20b189bfd2e0..ee1b1470ad13 100644 --- a/packages/babel-plugin-transform-taroapi/package.json +++ b/packages/babel-plugin-transform-taroapi/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-taroapi", - "version": "1.3.6", + "version": "1.3.7", "main": "dist/index.js", "license": "MIT", "scripts": { @@ -10,7 +10,7 @@ "test": "jest" }, "devDependencies": { - "@tarojs/taro-h5": "1.3.6", + "@tarojs/taro-h5": "1.3.7", "@types/babel-core": "^6.25.5", "@types/babel-traverse": "^6.25.4", "@types/babel-types": "^7.0.4", diff --git a/packages/css-to-react-native/package.json b/packages/css-to-react-native/package.json index d37dcabb72cc..db8193afdfc8 100644 --- a/packages/css-to-react-native/package.json +++ b/packages/css-to-react-native/package.json @@ -1,7 +1,7 @@ { "name": "taro-css-to-react-native", "description": "Convert CSS text to a React Native stylesheet object", - "version": "1.3.6", + "version": "1.3.7", "main": "dist/index.js", "license": "MIT", "scripts": { diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json index 7c5cddb67c10..6c9b83af06e9 100644 --- a/packages/eslint-config-taro/package.json +++ b/packages/eslint-config-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-taro", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro specific linting rules for ESLint", "main": "index.js", "files": [ @@ -27,6 +27,6 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "eslint-plugin-taro": "1.3.6" + "eslint-plugin-taro": "1.3.7" } } diff --git a/packages/eslint-plugin-taro/package.json b/packages/eslint-plugin-taro/package.json index 4eb9e68a883f..2a2b571c36b9 100644 --- a/packages/eslint-plugin-taro/package.json +++ b/packages/eslint-plugin-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-taro", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro specific linting plugin for ESLint", "main": "index.js", "files": [ diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json index 0ea0e4449a68..92e5db0e2c2a 100644 --- a/packages/postcss-plugin-constparse/package.json +++ b/packages/postcss-plugin-constparse/package.json @@ -1,6 +1,6 @@ { "name": "postcss-plugin-constparse", - "version": "1.3.6", + "version": "1.3.7", "description": "parse constants defined in config", "main": "index.js", "author": "Simba", diff --git a/packages/postcss-pxtransform/package.json b/packages/postcss-pxtransform/package.json index ec3baeb3587c..bf5cb5165481 100644 --- a/packages/postcss-pxtransform/package.json +++ b/packages/postcss-pxtransform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-pxtransform", - "version": "1.3.6", + "version": "1.3.7", "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位", "keywords": [ "postcss", diff --git a/packages/postcss-unit-transform/package.json b/packages/postcss-unit-transform/package.json index b83ffa206293..51b5bce7de84 100644 --- a/packages/postcss-unit-transform/package.json +++ b/packages/postcss-unit-transform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-taro-unit-transform", - "version": "1.3.6", + "version": "1.3.7", "description": "小程序单位转换", "main": "index.js", "scripts": { diff --git a/packages/stylelint-config-taro-rn/package.json b/packages/stylelint-config-taro-rn/package.json index 1540a6bc9dab..cfca9cf2772a 100644 --- a/packages/stylelint-config-taro-rn/package.json +++ b/packages/stylelint-config-taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-config-taro-rn", - "version": "1.3.6", + "version": "1.3.7", "description": "Shareable stylelint config for React Native CSS modules", "main": "index.js", "files": [ @@ -28,6 +28,6 @@ "jest": "^23.6.0", "npmpub": "^4.1.0", "stylelint": "9.3.0", - "stylelint-taro-rn": "1.3.6" + "stylelint-taro-rn": "1.3.7" } } diff --git a/packages/stylelint-taro-rn/package.json b/packages/stylelint-taro-rn/package.json index 2dab890bb48e..b6a7b3c948f5 100644 --- a/packages/stylelint-taro-rn/package.json +++ b/packages/stylelint-taro-rn/package.json @@ -1,7 +1,7 @@ { "name": "stylelint-taro-rn", "description": "A collection of React Native specific rules for stylelint", - "version": "1.3.6", + "version": "1.3.7", "main": "dist/index.js", "babel": { "presets": [ diff --git a/packages/taro-alipay/package.json b/packages/taro-alipay/package.json index b6cfdbee3331..1df5cd171319 100644 --- a/packages/taro-alipay/package.json +++ b/packages/taro-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-alipay", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro alipay framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.6", - "@tarojs/utils": "1.3.6", + "@tarojs/taro": "1.3.7", + "@tarojs/utils": "1.3.7", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-async-await/package.json b/packages/taro-async-await/package.json index ea8c94d18981..aa3f5143130a 100644 --- a/packages/taro-async-await/package.json +++ b/packages/taro-async-await/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/async-await", - "version": "1.3.6", + "version": "1.3.7", "description": "taro async await", "main": "index.js", "scripts": { diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json index b67f38ba632c..6daaf1404810 100644 --- a/packages/taro-cli/package.json +++ b/packages/taro-cli/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/cli", - "version": "1.3.6", + "version": "1.3.7", "description": "cli tool for taro", "main": "index.js", "scripts": { @@ -30,8 +30,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taroize": "1.3.6", - "@tarojs/transformer-wx": "1.3.6", + "@tarojs/taroize": "1.3.7", + "@tarojs/transformer-wx": "1.3.7", "@types/request": "^2.48.1", "autoprefixer": "^8.4.1", "babel-core": "^6.26.3", @@ -41,7 +41,7 @@ "babel-plugin-remove-dead-code": "^1.3.2", "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-define": "^1.3.0", - "babel-plugin-transform-jsx-to-stylesheet": "1.3.6", + "babel-plugin-transform-jsx-to-stylesheet": "1.3.7", "babel-plugin-transform-react-jsx": "^6.24.1", "babel-template": "^6.26.0", "babel-traverse": "^6.26.0", @@ -57,10 +57,10 @@ "ejs": "^2.6.1", "envinfo": "^6.0.1", "eslint": "^4.15.0", - "eslint-config-taro": "1.3.6", + "eslint-config-taro": "1.3.7", "eslint-plugin-import": "^2.8.0", "eslint-plugin-react": "^7.4.0", - "eslint-plugin-taro": "1.3.6", + "eslint-plugin-taro": "1.3.7", "eslint-plugin-typescript": "^0.12.0", "fbjs": "^1.0.0", "fs-extra": "^5.0.0", @@ -82,7 +82,7 @@ "postcss-modules-resolve-imports": "^1.3.0", "postcss-modules-scope": "^1.1.0", "postcss-modules-values": "^1.3.0", - "postcss-pxtransform": "1.3.6", + "postcss-pxtransform": "1.3.7", "postcss-reporter": "^6.0.1", "postcss-taro-unit-transform": "1.2.15", "postcss-url": "^7.3.2", @@ -93,9 +93,9 @@ "semver": "^5.5.0", "shelljs": "^0.8.1", "stylelint": "9.3.0", - "stylelint-config-taro-rn": "1.3.6", - "stylelint-taro-rn": "1.3.6", - "taro-css-to-react-native": "1.3.6", + "stylelint-config-taro-rn": "1.3.7", + "stylelint-taro-rn": "1.3.7", + "taro-css-to-react-native": "1.3.7", "through2": "^2.0.3", "vinyl": "^2.1.0", "vinyl-fs": "^3.0.2", @@ -103,7 +103,7 @@ "yauzl": "2.10.0" }, "devDependencies": { - "@tarojs/taro": "1.3.6", + "@tarojs/taro": "1.3.7", "@types/autoprefixer": "^9.1.1", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.2", diff --git a/packages/taro-components-qa/package.json b/packages/taro-components-qa/package.json index 23650ae1ec2d..a210da10233c 100644 --- a/packages/taro-components-qa/package.json +++ b/packages/taro-components-qa/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-qa", - "version": "1.3.6", + "version": "1.3.7", "description": "多端解决方案基础组件(快应用)", "main": "./index.js", "files": [ diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index d16e007f6074..e141d46417a2 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-rn", - "version": "1.3.6", + "version": "1.3.7", "description": "多端解决方案基础组件(RN)", "main": "./dist/index.js", "scripts": { diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json index e03a63c8c402..d21e5faead1f 100644 --- a/packages/taro-components/package.json +++ b/packages/taro-components/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components", - "version": "1.3.6", + "version": "1.3.7", "description": "", "main:h5": "src/index.js", "main": "dist/index.js", @@ -49,14 +49,14 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0", "@babel/plugin-transform-react-jsx": "^7.0.0", "@babel/preset-env": "^7.1.5", - "@tarojs/taro-h5": "1.3.6", + "@tarojs/taro-h5": "1.3.7", "@types/react": "^16.4.6", "@types/urijs": "^1.15.38", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "10.0.1", "babel-jest": "^22.4.4", "babel-loader": "^8.0.5", - "babel-plugin-transform-taroapi": "1.3.6", + "babel-plugin-transform-taroapi": "1.3.7", "css-loader": "^2.1.1", "file-loader": "^3.0.1", "jest": "^22.4.4", diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json index d915fc064dc9..747687947942 100644 --- a/packages/taro-h5/package.json +++ b/packages/taro-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-h5", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro h5 framework", "main:h5": "src/index.js", "main": "dist/index.js", @@ -45,8 +45,8 @@ "@babel/plugin-proposal-object-rest-spread": "^7.3.4", "@babel/plugin-transform-react-jsx": "^7.2.2", "@babel/preset-env": "^7.3.4", - "@tarojs/components": "1.3.6", - "@tarojs/taro": "1.3.6", + "@tarojs/components": "1.3.7", + "@tarojs/taro": "1.3.7", "babel-core": "7.0.0-bridge.0", "babel-jest": "24.4.0", "eslint": "^4.18.2", diff --git a/packages/taro-mobx-common/package.json b/packages/taro-mobx-common/package.json index 3e2d2998253d..812ac0443fea 100644 --- a/packages/taro-mobx-common/package.json +++ b/packages/taro-mobx-common/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-common", - "version": "1.3.6", + "version": "1.3.7", "description": "mobx library for taro", "keywords": [ "mobx", diff --git a/packages/taro-mobx-h5/package.json b/packages/taro-mobx-h5/package.json index 12244e84b80d..309e64a30c05 100644 --- a/packages/taro-mobx-h5/package.json +++ b/packages/taro-mobx-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-h5", - "version": "1.3.6", + "version": "1.3.7", "description": "mobx-h5 for taro", "keywords": [ "mobx", @@ -28,8 +28,8 @@ "nervjs": "^1.4.0" }, "dependencies": { - "@tarojs/mobx-common": "1.3.6", - "@tarojs/taro-h5": "1.3.6" + "@tarojs/mobx-common": "1.3.7", + "@tarojs/taro-h5": "1.3.7" }, "devDependencies": { "rimraf": "^2.6.2", diff --git a/packages/taro-mobx-rn/package.json b/packages/taro-mobx-rn/package.json index 1740824d4cc1..1c639cdd9f64 100644 --- a/packages/taro-mobx-rn/package.json +++ b/packages/taro-mobx-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx-rn", - "version": "1.3.6", + "version": "1.3.7", "description": "mobx-rn for taro", "keywords": [ "mobx", @@ -18,7 +18,7 @@ "src" ], "dependencies": { - "@tarojs/mobx-common": "1.3.6", - "@tarojs/taro-rn": "1.3.6" + "@tarojs/mobx-common": "1.3.7", + "@tarojs/taro-rn": "1.3.7" } } diff --git a/packages/taro-mobx/package.json b/packages/taro-mobx/package.json index cd7c757dedb7..870b4c7e5c7f 100644 --- a/packages/taro-mobx/package.json +++ b/packages/taro-mobx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mobx", - "version": "1.3.6", + "version": "1.3.7", "description": "mobx for taro", "keywords": [ "mobx", @@ -24,8 +24,8 @@ "clear": "rimraf dist" }, "dependencies": { - "@tarojs/mobx-common": "1.3.6", - "@tarojs/taro": "1.3.6" + "@tarojs/mobx-common": "1.3.7", + "@tarojs/taro": "1.3.7" }, "devDependencies": { "rimraf": "^2.6.2", diff --git a/packages/taro-plugin-babel/package.json b/packages/taro-plugin-babel/package.json index b7fa0aedf3f1..4e6931118744 100644 --- a/packages/taro-plugin-babel/package.json +++ b/packages/taro-plugin-babel/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-babel", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro babel编译", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-csso/package.json b/packages/taro-plugin-csso/package.json index b27cc50d7fca..5e05c18f31d9 100644 --- a/packages/taro-plugin-csso/package.json +++ b/packages/taro-plugin-csso/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-csso", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro压缩CSS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-less/package.json b/packages/taro-plugin-less/package.json index 27c0628d6ad4..329d050fe9c6 100644 --- a/packages/taro-plugin-less/package.json +++ b/packages/taro-plugin-less/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-less", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro 编译 less 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-sass/package.json b/packages/taro-plugin-sass/package.json index baaa1d1ef94f..a1b5e494219e 100644 --- a/packages/taro-plugin-sass/package.json +++ b/packages/taro-plugin-sass/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-sass", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro编译sass文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-stylus/package.json b/packages/taro-plugin-stylus/package.json index aa0168c97a05..ee82a9ecc03e 100644 --- a/packages/taro-plugin-stylus/package.json +++ b/packages/taro-plugin-stylus/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-stylus", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro 编译 stylus 文件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-typescript/package.json b/packages/taro-plugin-typescript/package.json index fe37ccb211f1..17c19d2c304d 100644 --- a/packages/taro-plugin-typescript/package.json +++ b/packages/taro-plugin-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-typescript", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro TypeScript 编译插件", "main": "index.js", "scripts": { diff --git a/packages/taro-plugin-uglifyjs/package.json b/packages/taro-plugin-uglifyjs/package.json index 3db9e94eff69..830ca6258e8d 100644 --- a/packages/taro-plugin-uglifyjs/package.json +++ b/packages/taro-plugin-uglifyjs/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-uglifyjs", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro压缩JS文件", "main": "index.js", "scripts": { diff --git a/packages/taro-qq/package.json b/packages/taro-qq/package.json index 6d8e444f8a45..46ffd573ef13 100644 --- a/packages/taro-qq/package.json +++ b/packages/taro-qq/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-qq", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro qq framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.6", - "@tarojs/utils": "1.3.6", + "@tarojs/taro": "1.3.7", + "@tarojs/utils": "1.3.7", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-quickapp/package.json b/packages/taro-quickapp/package.json index a9171b097042..32026d23c8ff 100644 --- a/packages/taro-quickapp/package.json +++ b/packages/taro-quickapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-quickapp", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro quickapp framework", "main": "index.js", "files": [ @@ -23,8 +23,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.6", - "@tarojs/utils": "1.3.6", + "@tarojs/taro": "1.3.7", + "@tarojs/utils": "1.3.7", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-redux-h5/package.json b/packages/taro-redux-h5/package.json index 8dd80265404f..428780395aef 100644 --- a/packages/taro-redux-h5/package.json +++ b/packages/taro-redux-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux-h5", - "version": "1.3.6", + "version": "1.3.7", "description": "Forked react-redux for taro", "keywords": [ "react", @@ -46,7 +46,7 @@ "@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.49", "@babel/plugin-transform-react-jsx": "^7.0.0-beta.49", "@babel/preset-env": "^7.0.0-beta.49", - "@tarojs/taro-h5": "1.3.6", + "@tarojs/taro-h5": "1.3.7", "babel-plugin-transform-react-remove-prop-types": "^0.4.13", "redux": "^4.0.0", "rimraf": "^2.6.2", diff --git a/packages/taro-redux-rn/package.json b/packages/taro-redux-rn/package.json index 22a790b2b31f..4fecca8f8cc1 100644 --- a/packages/taro-redux-rn/package.json +++ b/packages/taro-redux-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-redux-rn", - "version": "1.3.6", + "version": "1.3.7", "description": "taro-redux-rn", "main": "./src/index.js", "files": [ diff --git a/packages/taro-redux/package.json b/packages/taro-redux/package.json index d0337d6addf5..a8488a54a2b9 100644 --- a/packages/taro-redux/package.json +++ b/packages/taro-redux/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/redux", - "version": "1.3.6", + "version": "1.3.7", "description": "Redux for Taro", "main": "index.js", "typings": "types/index.d.ts", @@ -31,7 +31,7 @@ "jest": "^23.1.0" }, "dependencies": { - "@tarojs/taro": "1.3.6", - "@tarojs/utils": "1.3.6" + "@tarojs/taro": "1.3.7", + "@tarojs/utils": "1.3.7" } } diff --git a/packages/taro-rn-runner/package.json b/packages/taro-rn-runner/package.json index 9cc6995cf198..c7b24b385e48 100644 --- a/packages/taro-rn-runner/package.json +++ b/packages/taro-rn-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-runner", - "version": "1.3.6", + "version": "1.3.7", "description": "ReactNative build tool for taro", "main": "index.js", "scripts": { diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json index aedb4b19d450..8f9904c441ee 100644 --- a/packages/taro-rn/package.json +++ b/packages/taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-rn", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro RN framework", "main": "./index.js", "files": [ @@ -27,7 +27,7 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.6", + "@tarojs/taro": "1.3.7", "base64-js": "^1.3.0", "react-native-image-crop-picker": "^0.23.1", "react-native-image-zoom-viewer": "^2.2.13", diff --git a/packages/taro-router-rn/package.json b/packages/taro-router-rn/package.json index a63aba0608f5..17d3df9cd4de 100644 --- a/packages/taro-router-rn/package.json +++ b/packages/taro-router-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-router-rn", - "version": "1.3.6", + "version": "1.3.7", "description": "taro-router-rn", "main": "./index.js", "files": [ diff --git a/packages/taro-router/package.json b/packages/taro-router/package.json index 4510f658e668..b74b561a0176 100644 --- a/packages/taro-router/package.json +++ b/packages/taro-router/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/router", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro-router", "main:h5": "dist/index.esm.js", "main": "index.js", @@ -41,7 +41,7 @@ "@babel/plugin-syntax-dynamic-import": "7.0.0", "@babel/plugin-transform-react-jsx": "7.0.0", "@babel/preset-env": "7.1.5", - "@tarojs/taro-h5": "1.3.6", + "@tarojs/taro-h5": "1.3.7", "@types/history": "4.7.2", "@types/jasmine": "2.8.11", "@types/jest": "23.3.9", diff --git a/packages/taro-swan/package.json b/packages/taro-swan/package.json index bf3dd3e9d4a7..84456ae2c431 100644 --- a/packages/taro-swan/package.json +++ b/packages/taro-swan/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-swan", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro swan framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.6", - "@tarojs/utils": "1.3.6", + "@tarojs/taro": "1.3.7", + "@tarojs/utils": "1.3.7", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-transformer-wx/package.json b/packages/taro-transformer-wx/package.json index bd316ac8bcdb..caf9e8777415 100644 --- a/packages/taro-transformer-wx/package.json +++ b/packages/taro-transformer-wx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/transformer-wx", - "version": "1.3.6", + "version": "1.3.7", "description": "Transfrom Nerv Component to Wechat mini program.", "repository": { "type": "git", @@ -62,14 +62,14 @@ "babel-types": "^6.26.0", "eslint": "^4.15.0", "eslint-plugin-react": "7.10.0", - "eslint-plugin-taro": "1.3.6", + "eslint-plugin-taro": "1.3.7", "html": "^1.0.0", "lodash": "^4.17.5", "prettier": "^1.14.2", "typescript": "^3.2.2" }, "devDependencies": { - "@tarojs/taro": "1.3.6", + "@tarojs/taro": "1.3.7", "@types/babel-core": "^6.25.5", "@types/babel-generator": "^6.25.1", "@types/babel-template": "^6.25.0", diff --git a/packages/taro-tt/package.json b/packages/taro-tt/package.json index 675933dbb628..6d67b908b9f1 100644 --- a/packages/taro-tt/package.json +++ b/packages/taro-tt/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-tt", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro toutiao framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.6", - "@tarojs/utils": "1.3.6", + "@tarojs/taro": "1.3.7", + "@tarojs/utils": "1.3.7", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-utils/package.json b/packages/taro-utils/package.json index 1edc0295279d..ce3b870a81c7 100644 --- a/packages/taro-utils/package.json +++ b/packages/taro-utils/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/utils", - "version": "1.3.6", + "version": "1.3.7", "description": "Utils for Taro", "main": "index.js", "scripts": { diff --git a/packages/taro-weapp/package.json b/packages/taro-weapp/package.json index 8d78569e0d38..193d3c2a61f2 100644 --- a/packages/taro-weapp/package.json +++ b/packages/taro-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-weapp", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro weapp framework", "main": "index.js", "files": [ @@ -24,8 +24,8 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.6", - "@tarojs/utils": "1.3.6", + "@tarojs/taro": "1.3.7", + "@tarojs/utils": "1.3.7", "lodash": "^4.17.10", "prop-types": "^15.6.1" } diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json index 3d882db3fad9..b79782cf34be 100644 --- a/packages/taro-webpack-runner/package.json +++ b/packages/taro-webpack-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/webpack-runner", - "version": "1.3.6", + "version": "1.3.7", "description": "webpack runner for taro", "main": "index.js", "scripts": { @@ -32,13 +32,13 @@ }, "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { - "@tarojs/taro-h5": "1.3.6", + "@tarojs/taro-h5": "1.3.7", "autoprefixer": "8.6.4", "babel-core": "6.26.0", "babel-loader": "7.1.4", "babel-plugin-syntax-dynamic-import": "6.18.0", "babel-plugin-transform-react-jsx": "6.24.1", - "babel-plugin-transform-taroapi": "1.3.6", + "babel-plugin-transform-taroapi": "1.3.7", "babel-types": "6.26.0", "chalk": "2.4.2", "copy-webpack-plugin": "^5.0.3", @@ -55,8 +55,8 @@ "opn": "5.3.0", "ora": "2.1.0", "postcss-loader": "2.1.6", - "postcss-plugin-constparse": "1.3.6", - "postcss-pxtransform": "1.3.6", + "postcss-plugin-constparse": "1.3.7", + "postcss-pxtransform": "1.3.7", "resolve": "1.8.1", "resolve-url-loader": "2.3.0", "sass-loader": "7.1.0", diff --git a/packages/taro-with-weapp/package.json b/packages/taro-with-weapp/package.json index a4807fd3bbfd..7c7b8dbf86e2 100644 --- a/packages/taro-with-weapp/package.json +++ b/packages/taro-with-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/with-weapp", - "version": "1.3.6", + "version": "1.3.7", "description": "taroize 之后的运行时", "main": "index.js", "scripts": { @@ -22,7 +22,7 @@ "author": "yuche", "license": "MIT", "dependencies": { - "@tarojs/taro": "1.3.6", + "@tarojs/taro": "1.3.7", "lodash": "^4.17.11" }, "devDependencies": { diff --git a/packages/taro/package.json b/packages/taro/package.json index f680aa09d04a..14403e57b2fc 100644 --- a/packages/taro/package.json +++ b/packages/taro/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro", - "version": "1.3.6", + "version": "1.3.7", "description": "Taro framework", "module": "dist/index.esm.js", "main": "index.js", diff --git a/packages/taroize/package.json b/packages/taroize/package.json index be111b02c733..86d984f37081 100644 --- a/packages/taroize/package.json +++ b/packages/taroize/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taroize", - "version": "1.3.6", + "version": "1.3.7", "description": "转换原生微信小程序代码为 Taro 代码", "main": "index.js", "files": [ From 47448155e40587d0ffe48efdc81d3c13474e3d00 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Wed, 10 Jul 2019 14:37:30 +0800 Subject: [PATCH 157/158] chore: changelog --- CHANGELOG.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db1455fb40c0..4bfd5e3fec62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ -# [](https://github.com/NervJS/taro/compare/v1.3.6...v) (2019-07-08) +# [](https://github.com/NervJS/taro/compare/v1.3.7...v) (2019-07-10) + + + + +## [1.3.7](https://github.com/NervJS/taro/compare/v1.3.6...v1.3.7) (2019-07-10) + + +### Bug Fixes + +* **cli:** h5端支持alias到src下的目录了, fix [#2866](https://github.com/NervJS/taro/issues/2866) ([3e4e89c](https://github.com/NervJS/taro/commit/3e4e89c)) +* **components:** 修复快应用 WebView 问题。 close [#3451](https://github.com/NervJS/taro/issues/3451), [#3724](https://github.com/NervJS/taro/issues/3724) ([397b017](https://github.com/NervJS/taro/commit/397b017)) +* **taro:** 为 Taro.request 类型定义添加 abort 方法,完善注释 [#3654](https://github.com/NervJS/taro/issues/3654) ([#3715](https://github.com/NervJS/taro/issues/3715)) ([b007a49](https://github.com/NervJS/taro/commit/b007a49)) +* **taro-alipay:** 修复支付宝分包问题。close [#3445](https://github.com/NervJS/taro/issues/3445) ([d904a79](https://github.com/NervJS/taro/commit/d904a79)) +* **taro-alipay:** 修复支付宝分包问题。close [#3703](https://github.com/NervJS/taro/issues/3703) ([2b8f024](https://github.com/NervJS/taro/commit/2b8f024)) +* **taro-quickapp:** 快应用获取页面参数时增加容错 ([12c9998](https://github.com/NervJS/taro/commit/12c9998)) +* **taro-rn:** 修复showLoading没有使用title属性 ([8d0b1df](https://github.com/NervJS/taro/commit/8d0b1df)) +* **taro-router-rn:** 修复RN端触发不了下拉刷新事件 ([dbfabf2](https://github.com/NervJS/taro/commit/dbfabf2)) +* **taro-utils:** 优化 Object.is 判断 ([49bef9e](https://github.com/NervJS/taro/commit/49bef9e)) +* **transformer:** opt.isNormal 不需要走自定义 babel 插件 ([0945248](https://github.com/NervJS/taro/commit/0945248)), closes [#3731](https://github.com/NervJS/taro/issues/3731) +* **transformer:** 修复 0945248e2faf2a2d0f7fcf5f0e52473c85c5d073 重复添加插件 ([2b8180b](https://github.com/NervJS/taro/commit/2b8180b)) + + +### Features + +* **cli:** transformer 增加参数 alias ([2890b8c](https://github.com/NervJS/taro/commit/2890b8c)) +* **cli:** 优化对快应用系统包的判断与提醒 ([c9ae6b1](https://github.com/NervJS/taro/commit/c9ae6b1)) +* **cli:** 支持对 npm 包中文件进行转换 ([49a97e9](https://github.com/NervJS/taro/commit/49a97e9)) From b7a327b7ac5da01aabcd2dd7d2326c64da98b10d Mon Sep 17 00:00:00 2001 From: "Jim,czj" Date: Wed, 10 Jul 2019 14:40:28 +0800 Subject: [PATCH 158/158] =?UTF-8?q?fix(h5):=20=E4=BF=AE=E5=A4=8D=20chooseI?= =?UTF-8?q?mage=20=E6=97=A0=E6=B3=95=E4=B8=A4=E6=AC=A1=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E7=9B=B8=E5=90=8C=E5=9B=BE=E7=89=87=20fix=20#3747=20(#3748)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-h5/src/api/image/chooseImage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/taro-h5/src/api/image/chooseImage.js b/packages/taro-h5/src/api/image/chooseImage.js index ac9cfed13382..8de7e705aae4 100644 --- a/packages/taro-h5/src/api/image/chooseImage.js +++ b/packages/taro-h5/src/api/image/chooseImage.js @@ -71,6 +71,7 @@ const chooseImage = function (options) { typeof success === 'function' && success(res) typeof complete === 'function' && complete(res) taroChooseImageCallback(res) + e.target.value = '' } return taroChooseImagePromise }