Example #1
0
 getScrollableNode: function() {
   if (this._scrollComponent && this._scrollComponent.getScrollableNode) {
     return this._scrollComponent.getScrollableNode();
   } else {
     return ReactNative.findNodeHandle(this._scrollComponent);
   }
 },
Example #2
0
 getScrollableNode() {
   if (this._scrollRef && this._scrollRef.getScrollableNode) {
     return this._scrollRef.getScrollableNode();
   } else {
     return ReactNative.findNodeHandle(this._scrollRef);
   }
 }
 setPage = (selectedPage: number) => {
   UIManager.dispatchViewManagerCommand(
     ReactNative.findNodeHandle(this),
     UIManager.getViewManagerConfig('AndroidViewPager').Commands.setPage,
     [selectedPage],
   );
 };
 _dispatchPressedStateChange: function(pressed) {
   UIManager.dispatchViewManagerCommand(
     ReactNative.findNodeHandle(this),
     UIManager.RCTView.Commands.setPressed,
     [pressed]
   );
 },
Example #5
0
 requestSchedulingNavigation(cb) {
   RCTNavigatorManager.requestSchedulingJavaScriptNavigation(
     ReactNative.findNodeHandle(this),
     logError,
     cb
   );
 }
 _dispatchHotspotUpdate: function(destX, destY) {
   UIManager.dispatchViewManagerCommand(
     ReactNative.findNodeHandle(this),
     UIManager.RCTView.Commands.hotspotUpdate,
     [destX || 0, destY || 0]
   );
 },
  componentDidMount: function () {
    this._lastNativeText = this.props.value;
    const tag = ReactNative.findNodeHandle(this._inputRef);
    if (tag != null) {
      // tag is null only in unit tests
      TextInputState.registerInput(tag);
    }

    if (this.context.focusEmitter) {
      this._focusSubscription = this.context.focusEmitter.addListener(
        'focus',
        el => {
          if (this === el) {
            this._rafId = requestAnimationFrame(this.focus);
          } else if (this.isFocused()) {
            this.blur();
          }
        },
      );
      if (this.props.autoFocus) {
        this.context.onFocusRequested(this);
      }
    } else {
      if (this.props.autoFocus) {
        this._rafId = requestAnimationFrame(this.focus);
      }
    }
  },
 setPageWithoutAnimation = (selectedPage: number) => {
   UIManager.dispatchViewManagerCommand(
     ReactNative.findNodeHandle(this),
     UIManager.AndroidViewPager.Commands.setPageWithoutAnimation,
     [selectedPage],
   );
 };
 blur() {
   if (this._focusable) {
     UIManager.dispatchViewManagerCommand(
       ReactNative.findNodeHandle(this._focusable),
       UIManager.WindowsControl.Commands.blur,
       null);
   }
 }
Example #10
0
 mockClick = () => {
   const node = ReactNative.findNodeHandle(this);
   const nativeEvent = {
     target: node,
     timeStamp: Date.now(),
   };
   maybeEmitMockEvent(node, 'topClick', nativeEvent);
 };
 toggleElementInspector: function() {
   var inspector = !__DEV__ || this.state.inspector
     ? null
     : <Inspector
         rootTag={this.props.rootTag}
         inspectedViewTag={ReactNative.findNodeHandle(this.refs.main)}
       />;
   this.setState({inspector});
 },
Example #12
0
 componentWillUnmount: function() {
   this._focusSubscription && this._focusSubscription.remove();
   if (this.isFocused()) {
     this.blur();
   }
   const tag = ReactNative.findNodeHandle(this._inputRef);
   if (tag != null) {
     TextInputState.unregisterInput(tag);
   }
 },
 getScrollableNode() {
   if (this._scrollRef && this._scrollRef.getScrollableNode) {
     /* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This
      * comment suppresses an error when upgrading Flow's support for React.
      * To see the error delete this comment and run Flow. */
     return this._scrollRef.getScrollableNode();
   } else {
     return ReactNative.findNodeHandle(this._scrollRef);
   }
 }
 scrollResponderScrollNativeHandleToKeyboard: function(nodeHandle: any, additionalOffset?: number, preventNegativeScrollOffset?: bool) {
   this.additionalScrollOffset = additionalOffset || 0;
   this.preventNegativeScrollOffset = !!preventNegativeScrollOffset;
   UIManager.measureLayout(
     nodeHandle,
     ReactNative.findNodeHandle(this.getInnerViewNode()),
     this.scrollResponderTextInputFocusError,
     this.scrollResponderInputMeasureAndScrollToKeyboard
   );
 },
Example #15
0
function attachNativeEvent(
  viewRef: any,
  eventName: string,
  argMapping: Array<?Mapping>,
) {
  // Find animated values in `argMapping` and create an array representing their
  // key path inside the `nativeEvent` object. Ex.: ['contentOffset', 'x'].
  const eventMappings = [];

  const traverse = (value, path) => {
    if (value instanceof AnimatedValue) {
      value.__makeNative();

      eventMappings.push({
        nativeEventPath: path,
        animatedValueTag: value.__getNativeTag(),
      });
    } else if (typeof value === 'object') {
      for (const key in value) {
        traverse(value[key], path.concat(key));
      }
    }
  };

  invariant(
    argMapping[0] && argMapping[0].nativeEvent,
    'Native driven events only support animated values contained inside `nativeEvent`.',
  );

  // Assume that the event containing `nativeEvent` is always the first argument.
  traverse(argMapping[0].nativeEvent, []);

  const viewTag = ReactNative.findNodeHandle(viewRef);

  eventMappings.forEach(mapping => {
    NativeAnimatedHelper.API.addAnimatedEventToView(
      viewTag,
      eventName,
      mapping,
    );
  });

  return {
    detach() {
      eventMappings.forEach(mapping => {
        NativeAnimatedHelper.API.removeAnimatedEventFromView(
          viewTag,
          eventName,
          mapping.animatedValueTag,
        );
      });
    },
  };
}
 _onBlur: function (event: Event) {
   // [TODO(android ISS)
   // Set the focused TextInput field info in TextInputState.
   // Delaying this to onBlur native event ensures that -
   // 1. The state is updated only after the native code completes clearing focus on the view
   // 2. In case the focus is moving from one TextInput(A) to another TextInput(B), the state of
   //    A needs to be updated (blurred) before info about B is updated in TestInputState.
   TextInputState.clearFocusedTextInput(ReactNative.findNodeHandle(this._inputRef)); // ]TODO(android ISS)
   if (this.props.onBlur) {
     this.props.onBlur(event);
   }
 },
 measureLayout: function(
   relativeToNativeNode: number,
   onSuccess: MeasureLayoutOnSuccessCallback,
   onFail: () => void /* currently unused */,
 ) {
   UIManager.measureLayout(
     ReactNative.findNodeHandle(this),
     relativeToNativeNode,
     mountSafeCallback(this, onFail),
     mountSafeCallback(this, onSuccess),
   );
 },
Example #18
0
  _measureAndUpdateScrollProps: function() {
    var scrollComponent = this.getScrollResponder();
    if (!scrollComponent || !scrollComponent.getInnerViewNode) {
      return;
    }

    // RCTScrollViewManager.calculateChildFrames is not available on
    // every platform
    RCTScrollViewManager && RCTScrollViewManager.calculateChildFrames &&
      RCTScrollViewManager.calculateChildFrames(
        ReactNative.findNodeHandle(scrollComponent),
        this._updateVisibleRows,
      );
  },
Example #19
0
 __disconnectAnimatedView(): void {
   invariant(this.__isNative, 'Expected node to be marked as "native"');
   const nativeViewTag: ?number = ReactNative.findNodeHandle(
     this._animatedView,
   );
   invariant(
     nativeViewTag != null,
     'Unable to locate attached view in the native tree',
   );
   NativeAnimatedHelper.API.disconnectAnimatedNodeFromView(
     this.__getNativeTag(),
     nativeViewTag,
   );
 }
Example #20
0
 toggleElementInspector: function() {
   var inspector = !__DEV__ || this.state.inspector
     ? null
     : <Inspector
         inspectedViewTag={ReactNative.findNodeHandle(this.refs.main)}
         onRequestRerenderApp={(updateInspectedViewTag) => {
           this.setState(
             (s) => ({mainKey: s.mainKey + 1}),
             () => updateInspectedViewTag(ReactNative.findNodeHandle(this.refs.main))
           );
         }}
       />;
   this.setState({inspector});
 },
Example #21
0
 this._tvEventHandler.enable(this, function(cmp, evt) {
   const myTag = ReactNative.findNodeHandle(cmp);
   evt.dispatchConfig = {};
   if (myTag === evt.tag) {
     if (evt.eventType === 'focus') {
       cmp.touchableHandleFocus(evt);
     } else if (evt.eventType === 'blur') {
       cmp.touchableHandleBlur(evt);
     } else if (evt.eventType === 'select') {
       cmp.touchableHandlePress &&
         !cmp.props.disabled &&
         cmp.touchableHandlePress(evt);
     }
   }
 });
Example #22
0
module.exports = function takeSnapshot(
  view?: 'window' | React$Element<any> | number,
  options?: {
    width?: number,
    height?: number,
    format?: 'png' | 'jpeg',
    quality?: number,
  },
): Promise<any> {
  if (typeof view !== 'number' && view !== 'window') {
    view = ReactNative.findNodeHandle(view) || 'window';
  }

  // Call the hidden '__takeSnapshot' method; the main one throws an error to
  // prevent accidental backwards-incompatible usage.
  return UIManager.__takeSnapshot(view, options);
};
Example #23
0
 () => {
   const Inspector = require('Inspector');
   const inspector = this.state.inspector
     ? null
     : <Inspector
         inspectedViewTag={ReactNative.findNodeHandle(this._mainRef)}
         onRequestRerenderApp={(updateInspectedViewTag) => {
           this.setState(
             (s) => ({mainKey: s.mainKey + 1}),
             () => updateInspectedViewTag(
               ReactNative.findNodeHandle(this._mainRef)
             )
           );
         }}
       />;
   this.setState({inspector});
 },
function(){
var Inspector=require('Inspector');
var inspector=_this2.state.inspector?
null:
React.createElement(Inspector,{
inspectedViewTag:ReactNative.findNodeHandle(_this2._mainRef),
onRequestRerenderApp:function onRequestRerenderApp(updateInspectedViewTag){
_this2.setState(
function(s){return{mainKey:s.mainKey+1};},
function(){return updateInspectedViewTag(
ReactNative.findNodeHandle(_this2._mainRef));});


}});

_this2.setState({inspector:inspector});
});
Example #25
0
    const hlSub = agent.sub('highlight', ({node, name, props}) => {
      clearTimeout(_hideWait);

      if (typeof node !== 'number') {
        // Fiber
        node = ReactNative.findNodeHandle(node);
      }

      UIManager.measure(node, (x, y, width, height, left, top) => {
        this.setState({
          hierarchy: [],
          inspected: {
            frame: {left, top, width, height},
            style: props ? props.style : emptyObject,
          },
        });
      });
    });
Example #26
0
    const hlSub = agent.sub('highlight', ({node, name, props}) => {
      /* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an
       * error found when Flow v0.63 was deployed. To see the error delete this
       * comment and run Flow. */
      clearTimeout(_hideWait);

      if (typeof node !== 'number') {
        // Fiber
        node = ReactNative.findNodeHandle(node);
      }

      UIManager.measure(node, (x, y, width, height, left, top) => {
        this.setState({
          hierarchy: [],
          inspected: {
            frame: {left, top, width, height},
            style: props ? props.style : {},
          },
        });
      });
    });
Example #27
0
 getInnerViewNode(): any {
   return ReactNative.findNodeHandle(this._innerViewRef);
 }
Example #28
0
 getScrollableNode(): any {
   return ReactNative.findNodeHandle(this._scrollViewRef);
 }
 isFocused: function(): boolean {
   return TextInputState.currentlyFocusedField() === ReactNative.findNodeHandle(this._inputRef)
 },
Example #30
0
 getWebViewHandle = (): any => {
   return ReactNative.findNodeHandle(this.refs[RCT_WEBVIEW_REF]);
 };