How to use react-clone-referenced-element - 10 common examples

To help you get started, we’ve selected a few react-clone-referenced-element examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / ex-navigation / src / tab / ExNavigationTab.js View on Github external
let tabItem = {
        ..._.omit(tabItemProps, ['children']),
      };

      if (Children.count(tabItemProps.children) > 0) {
        let child = Children.only(tabItemProps.children);

        // NOTE: a bit hacky, identifying navigation component like StackNav
        // via initialRoute
        if (child.props.initialRoute && this.props.translucent) {
          let defaultRouteConfig = child.props.defaultRouteConfig || {};
          defaultRouteConfig = {
            ...defaultRouteConfig,
            __tabBarInset: this.props.tabBarHeight,
          };
          tabItem.element = cloneReferencedElement(child, {
            ...child.props,
            defaultRouteConfig,
          });
        } else {
          tabItem.element = child;
        }
      }

      const tabItemOnPress = () => {
        this._setActiveTab(tabItemProps.id, index);
      };

      if (typeof tabItemProps.onPress === 'function') {
        tabItem.onPress = tabItem.onPress.bind(this, tabItemOnPress);
      } else {
        tabItem.onPress = tabItemOnPress;
github lelandrichardson / react-native-animated-navigator / ExNavigator / ExNavigator.js View on Github external
// can get a ref to it
    if (!this._subscribedToFocusEvents) {
      this._subscribeToFocusEvents(navigator);
    }

    // We need to save a reference to the navigator already. Otherwise this
    // would crash if the route calls any method on us in the first render-pass.
    this.__navigator = navigator;

    let scene = this._routeRenderer.renderScene(route, this, transition, scroll);
    if (typeof this.props.augmentScene === 'function') {
      scene = this.props.augmentScene(scene, route);
    }
    let firstRoute = navigator.getCurrentRoutes()[0];
    if (route === firstRoute) {
      scene = cloneReferencedElement(scene, {
        ref: component => { this._firstScene = component; },
      });
    }
    return scene;
  }
github lelandrichardson / react-native-animated-navigator / Navigator / Navigator.js View on Github external
if (!renderNavigationBar) {
      return null;
    }

    const navBar = renderNavigationBar({
      navigator: this._navigationBarNavigator,
      navState: this.state,
      sceneMap: this._scenesByRoute, // TODO(lmr): do in a way that doesn't expose this structure
      scroll: this.props.scroll,
    });

    if (navBar === null) {
      return navBar;
    }

    return cloneReferencedElement(navBar, {
      ref: (el) => { this._navBar = el; },
    });
  },
github expo / react-native-loading-container / LoadingContainer.js View on Github external
render() {
    let loadingOverlay = cloneReferencedElement(
      this.props.renderLoadingOverlay({}),
      { ref: component => { this._loadingOverlay = component; } }
    );

    let errorOverlay = cloneReferencedElement(
      this.props.renderErrorOverlay({onRetryLoad: this._attemptLoadAsync}),
      { ref: component => { this._errorOverlay = component; } }
    );

    return (
      
    );
github expo / react-native-responsive-image / ResponsiveImage.js View on Github external
renderImageElement,
      ...props
    } = this.props;
    let optimalSource = ResponsiveImage.getClosestHighQualitySource(
      sources,
      preferredPixelRatio,
    );
    if (optimalSource) {
      source = optimalSource;
    }
    if (!source) {
      throw new Error(`Couldn't find an appropriate image source`);
    }
    if (renderImageElement) {
      let image = renderImageElement({ ...props, source });
      return cloneReferencedElement(image, {
        ref: component => { this._image = component; },
      });
    }

    return (
      <img> { this._image = component; }}
        source={source}
      /&gt;
    );
  }
}
github expo / react-native-fade-in-image / FadeIn.js View on Github external
render() {
    let image = cloneReferencedElement(onlyChild(this.props.children), {
      ref: component =&gt; {
        this._image = component;
      },
      onLoadEnd: this._onLoadEnd,
    });

    let safeImageProps = { ...StyleSheet.flatten(image.props.style) };
    delete safeImageProps.tintColor;
    delete safeImageProps.resizeMode;

    return (
github expo / react-native-infinite-scroll-view / InfiniteScrollView.js View on Github external
this.props.renderLoadingErrorIndicator({ onRetryLoadMore: this._loadMoreAsync }),
        { key: 'loading-error-indicator' }
      );
    } else if (this.state.isLoading) {
      statusIndicator = React.cloneElement(this.props.renderLoadingIndicator(), {
        key: 'loading-indicator',
      });
    }

    let { renderScrollComponent, ...props } = this.props;
    Object.assign(props, {
      onScroll: this._handleScroll,
      children: [this.props.children, statusIndicator],
    });

    return cloneReferencedElement(renderScrollComponent(props), {
      ref: component => {
        this._scrollComponent = component;
      },
    });
  }
github expo / ex-navigation / src / ExNavigationStack.js View on Github external
: { paddingTop: this._getNavigationBarHeight(routeConfig) },
        ];
      }
    } else {
      style = [...style, styles.withoutNavigationBar];
    }

    if (routeConfig.sceneStyle) {
      style = [...style, routeConfig.sceneStyle || styles.defaultSceneStyle];
    }

    return (
      
    );
  };
github expo / react-native-invertible-scroll-view / InvertibleScrollView.js View on Github external
inverted,
      renderScrollComponent,
      ...props
    } = this.props;

    if (inverted) {
      if (this.props.horizontal) {
        props.style = [styles.horizontallyInverted, props.style];
        props.children = this._renderInvertedChildren(props.children, styles.horizontallyInverted);
      } else {
        props.style = [styles.verticallyInverted, props.style];
        props.children = this._renderInvertedChildren(props.children, styles.verticallyInverted);
      }
    }

    return cloneReferencedElement(renderScrollComponent(props), {
      ref: component => { this._scrollComponent = component; },
    });
  },
github lelandrichardson / react-native-animated-navigator / ExNavigator / ExRouteRenderer.js View on Github external
renderScene(route, navigator, transition, scroll) {
    if (route.renderScene) {
      let scene = route.renderScene({ navigator, transition, scroll });
      if (!scene) {
        return scene;
      }
      return cloneReferencedElement(scene, {
        ref: component =&gt; { route.scene = component; },
      });
    }

    invariant(
      route.getSceneClass,
      'The route must implement renderScene or getSceneClass',
    );
    let Component = route.getSceneClass();
    return (
       { route.scene = component; }}
        navigator={navigator}
        transition={transition}
        scroll={scroll}
      /&gt;

react-clone-referenced-element

Clones a React element while preserving its original ref

MIT
Latest version published 3 years ago

Package Health Score

47 / 100
Full package analysis

Popular react-clone-referenced-element functions