ReactNative中Component生命周期实现

2018-08-07  本文已影响0人  xinguoshui

在Libraries/Renderer/oss/ReactNativeRenderer.js中。

Libraries/ReactNative/AppRegistry.js runApplication
Libraries/ReactNative/renderApplication.js renderApplication
    ReactNative.render(renderable, rootTag);
Libraries/Renderer/oss/ReactNativeRenderer.*.js
    updateContainer
    scheduleRootUpdate
    scheduleWork
    performWorkOnRoot
    renderRoot
        performUnitOfWork
        appendAllChildren
    completeRoot
        commitRoot
        commitAllHostEffects
        commitPlacement
        appendChildToContainer
        UIManager.setChildren
        UIManagerModule.java
            mUIImplementation.setChildren(viewTag, childrenTags);
       commitRoot
       commitLifeCycles
       componentDidMount

render: function(element, containerTag, callback) {
    var root = roots.get(containerTag);

    if (!root) {
      // TODO (bvaughn): If we decide to keep the wrapper component,
      // We could create a wrapper for containerTag as well to reduce special casing.
      root = NativeRenderer.createContainer(containerTag, false);
      roots.set(containerTag, root);
    }
    NativeRenderer.updateContainer(element, root, null, callback);

    return NativeRenderer.getPublicRootInstance(root);
  }
上一篇 下一篇

猜你喜欢

热点阅读