openDrawer: function() {
   UIManager.dispatchViewManagerCommand(
     this._getDrawerLayoutHandle(),
     UIManager.getViewManagerConfig('AndroidDrawerLayout').Commands.openDrawer,
     null,
   );
 },
  render: function() {
    const nativeProps = {
      ...this.props,
    };
    if (this.props.logo) {
      nativeProps.logo = resolveAssetSource(this.props.logo);
    }
    if (this.props.navIcon) {
      nativeProps.navIcon = resolveAssetSource(this.props.navIcon);
    }
    if (this.props.overflowIcon) {
      nativeProps.overflowIcon = resolveAssetSource(this.props.overflowIcon);
    }
    if (this.props.actions) {
      const nativeActions = [];
      for (let i = 0; i < this.props.actions.length; i++) {
        const action = {
          ...this.props.actions[i],
        };
        if (action.icon) {
          action.icon = resolveAssetSource(action.icon);
        }
        if (action.show) {
          action.show = UIManager.getViewManagerConfig(
            'ToolbarAndroid',
          ).Constants.ShowAsAction[action.show];
        }
        nativeActions.push(action);
      }
      nativeProps.nativeActions = nativeActions;
    }

    return <NativeToolbar onSelect={this._onSelect} {...nativeProps} />;
  },
 setPage = (selectedPage: number) => {
   UIManager.dispatchViewManagerCommand(
     ReactNative.findNodeHandle(this),
     UIManager.getViewManagerConfig('AndroidViewPager').Commands.setPage,
     [selectedPage],
   );
 };
 _dispatchPressedStateChange: function(pressed) {
   UIManager.dispatchViewManagerCommand(
     ReactNative.findNodeHandle(this),
     UIManager.getViewManagerConfig('RCTView').Commands.setPressed,
     [pressed],
   );
 },
 _dispatchHotspotUpdate: function(destX, destY) {
   UIManager.dispatchViewManagerCommand(
     ReactNative.findNodeHandle(this),
     UIManager.getViewManagerConfig('RCTView').Commands.hotspotUpdate,
     [destX || 0, destY || 0],
   );
 },
Example #6
0
  _renderAndroid: function() {
    const props = Object.assign({}, this.props);
    props.style = [this.props.style];
    props.autoCapitalize = UIManager.getViewManagerConfig(
      'AndroidTextInput',
    ).Constants.AutoCapitalizationType[props.autoCapitalize || 'sentences'];
    /* $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. */
    let children = this.props.children;
    let childCount = 0;
    React.Children.forEach(children, () => ++childCount);
    invariant(
      !(this.props.value && childCount),
      'Cannot specify both value and children.',
    );
    if (childCount > 1) {
      children = <Text>{children}</Text>;
    }

    if (props.selection && props.selection.end == null) {
      props.selection = {
        start: props.selection.start,
        end: props.selection.start,
      };
    }

    const textContainer = (
      <AndroidTextInput
        ref={this._setNativeRef}
        {...props}
        mostRecentEventCount={0}
        onFocus={this._onFocus}
        onBlur={this._onBlur}
        onChange={this._onChange}
        onSelectionChange={this._onSelectionChange}
        onTextInput={this._onTextInput}
        text={this._getText()}
        children={children}
        disableFullscreenUI={this.props.disableFullscreenUI}
        textBreakStrategy={this.props.textBreakStrategy}
        onScroll={this._onScroll}
      />
    );

    return (
      <TouchableWithoutFeedback
        onLayout={props.onLayout}
        onPress={this._onPress}
        accessible={this.props.accessible}
        accessibilityLabel={this.props.accessibilityLabel}
        accessibilityRole={this.props.accessibilityRole}
        accessibilityStates={this.props.accessibilityStates}
        nativeID={this.props.nativeID}
        testID={this.props.testID}>
        {textContainer}
      </TouchableWithoutFeedback>
    );
  },
 scrollResponderFlashScrollIndicators: function() {
   UIManager.dispatchViewManagerCommand(
     this.scrollResponderGetScrollableNode(),
     UIManager.getViewManagerConfig('RCTScrollView').Commands
       .flashScrollIndicators,
     [],
   );
 },
 /**
  * Closes the drawer.
  */
 closeDrawer() {
   UIManager.dispatchViewManagerCommand(
     this._getDrawerLayoutHandle(),
     UIManager.getViewManagerConfig('AndroidDrawerLayout').Commands
       .closeDrawer,
     null,
   );
 }
  render() {
    const {
      onIconClicked,
      onActionSelected,
      forwardedRef,
      ...otherProps
    } = this.props;

    const nativeProps: {...typeof otherProps, nativeActions?: Array<Action>} = {
      ...otherProps,
    };

    if (this.props.logo) {
      nativeProps.logo = resolveAssetSource(this.props.logo);
    }

    if (this.props.navIcon) {
      nativeProps.navIcon = resolveAssetSource(this.props.navIcon);
    }

    if (this.props.overflowIcon) {
      nativeProps.overflowIcon = resolveAssetSource(this.props.overflowIcon);
    }

    if (this.props.actions) {
      const nativeActions = [];
      for (let i = 0; i < this.props.actions.length; i++) {
        const action = {
          icon: this.props.actions[i].icon,
          show: this.props.actions[i].show,
        };

        if (action.icon) {
          action.icon = resolveAssetSource(action.icon);
        }
        if (action.show) {
          action.show = UIManager.getViewManagerConfig(
            'ToolbarAndroid',
          ).Constants.ShowAsAction[action.show];
        }

        nativeActions.push({
          ...this.props.actions[i],
          ...action,
        });
      }

      nativeProps.nativeActions = nativeActions;
    }

    return (
      <ToolbarAndroidNativeComponent
        onSelect={this._onSelect}
        {...nativeProps}
        ref={forwardedRef}
      />
    );
  }
Example #10
0
 scrollResponderScrollToEnd: function(options?: {animated?: boolean}) {
   // Default to true
   const animated = (options && options.animated) !== false;
   UIManager.dispatchViewManagerCommand(
     this.scrollResponderGetScrollableNode(),
     UIManager.getViewManagerConfig('RCTScrollView').Commands.scrollToEnd,
     [animated],
   );
 },
Example #11
0
 render: function() {
   let textInput;
   if (Platform.OS === 'ios') {
     textInput = UIManager.getViewManagerConfig('RCTVirtualText')
       ? this._renderIOS()
       : this._renderIOSLegacy();
   } else if (Platform.OS === 'android') {
     textInput = this._renderAndroid();
   }
   return (
     <TextAncestor.Provider value={true}>{textInput}</TextAncestor.Provider>
   );
 },
Example #12
0
 scrollResponderScrollTo: function(
   x?: number | {x?: number, y?: number, animated?: boolean},
   y?: number,
   animated?: boolean,
 ) {
   if (typeof x === 'number') {
     console.warn(
       '`scrollResponderScrollTo(x, y, animated)` is deprecated. Use `scrollResponderScrollTo({x: 5, y: 5, animated: true})` instead.',
     );
   } else {
     ({x, y, animated} = x || {});
   }
   UIManager.dispatchViewManagerCommand(
     nullthrows(this.scrollResponderGetScrollableNode()),
     UIManager.getViewManagerConfig('RCTScrollView').Commands.scrollTo,
     [x || 0, y || 0, animated !== false],
   );
 },
'use strict';

const DeprecatedColorPropType = require('DeprecatedColorPropType');
const DeprecatedViewPropTypes = require('DeprecatedViewPropTypes');
const NativeMethodsMixin = require('NativeMethodsMixin');
const Platform = require('Platform');
const PropTypes = require('prop-types');
const React = require('React');
const ReactNative = require('ReactNative');
const StatusBar = require('StatusBar');
const StyleSheet = require('StyleSheet');
const UIManager = require('UIManager');
const View = require('View');

const DrawerConsts = UIManager.getViewManagerConfig('AndroidDrawerLayout')
  .Constants;

const createReactClass = require('create-react-class');
const dismissKeyboard = require('dismissKeyboard');
const requireNativeComponent = require('requireNativeComponent');

const RK_DRAWER_REF = 'drawerlayout';
const INNERVIEW_REF = 'innerView';

const DRAWER_STATES = ['Idle', 'Dragging', 'Settling'];

/**
 * React component that wraps the platform `DrawerLayout` (Android only). The
 * Drawer (typically used for navigation) is rendered with `renderNavigationView`
 * and direct children are the main view (where your content goes). The navigation
Example #14
0
        : this.props.pressRetentionOffset;
  }
}

const isTouchable = (props: Props): boolean =>
  props.onPress != null ||
  props.onLongPress != null ||
  props.onStartShouldSetResponder != null;

const RCTText = createReactNativeComponentClass(
  viewConfig.uiViewClassName,
  () => viewConfig,
);

const RCTVirtualText =
  UIManager.getViewManagerConfig('RCTVirtualText') == null
    ? RCTText
    : createReactNativeComponentClass('RCTVirtualText', () => ({
        validAttributes: {
          ...ReactNativeViewAttributes.UIView,
          isHighlighted: true,
          maxFontSizeMultiplier: true,
        },
        uiViewClassName: 'RCTVirtualText',
      }));

const Text = (
  props: TextProps,
  forwardedRef: ?React.Ref<'RCTText' | 'RCTVirtualText'>,
) => {
  return <TouchableText {...props} forwardedRef={forwardedRef} />;
function getNativeComponentAttributes(uiViewClassName: string) {
  const viewConfig = UIManager.getViewManagerConfig(uiViewClassName);

  invariant(
    viewConfig != null && viewConfig.NativeProps != null,
    'requireNativeComponent: "%s" was not found in the UIManager.',
    uiViewClassName,
  );

  // TODO: This seems like a whole lot of runtime initialization for every
  // native component that can be either avoided or simplified.
  let {baseModuleName, bubblingEventTypes, directEventTypes} = viewConfig;
  let nativeProps = viewConfig.NativeProps;
  while (baseModuleName) {
    const baseModule = UIManager.getViewManagerConfig(baseModuleName);
    if (!baseModule) {
      warning(false, 'Base module "%s" does not exist', baseModuleName);
      baseModuleName = null;
    } else {
      bubblingEventTypes = {
        ...baseModule.bubblingEventTypes,
        ...bubblingEventTypes,
      };
      directEventTypes = {
        ...baseModule.directEventTypes,
        ...directEventTypes,
      };
      nativeProps = {
        ...baseModule.NativeProps,
        ...nativeProps,
      };
      baseModuleName = baseModule.baseModuleName;
    }
  }

  const validAttributes = {};

  for (const key in nativeProps) {
    const typeName = nativeProps[key];
    const diff = getDifferForType(typeName);
    const process = getProcessorForType(typeName);

    validAttributes[key] =
      diff == null && process == null ? true : {diff, process};
  }

  // Unfortunately, the current setup declares style properties as top-level
  // props. This makes it so we allow style properties in the `style` prop.
  // TODO: Move style properties into a `style` prop and disallow them as
  // top-level props on the native side.
  validAttributes.style = ReactNativeStyleAttributes;

  Object.assign(viewConfig, {
    uiViewClassName,
    validAttributes,
    bubblingEventTypes,
    directEventTypes,
  });

  if (!hasAttachedDefaultEventTypes) {
    attachDefaultEventTypes(viewConfig);
    hasAttachedDefaultEventTypes = true;
  }

  return viewConfig;
}