text: /**
   * Copyright (c) 2015-present, Viro Media, Inc.
   * All rights reserved.
   *
   * This source code is licensed under the BSD-style license found in the
   * LICENSE file in the root directory of this source tree. An additional grant
   * of patent rights can be found in the PATENTS file in the same directory.
   */
  
  import { requireNativeComponent, View, findNodeHandle } from 'react-native';
  import React, { Component } from 'react';
  import PropTypes from 'prop-types';
  var NativeModules = require('react-native').NativeModules;
  var createReactClass = require('create-react-class');
  import { checkMisnamedProps } from './Utilities/ViroProps';
  
  var ViroBox = createReactClass({
    propTypes: {
      ...View.propTypes,
      position: PropTypes.arrayOf(PropTypes.number),
      scale: PropTypes.arrayOf(PropTypes.number),
      rotation: PropTypes.arrayOf(PropTypes.number),
      scalePivot: PropTypes.arrayOf(PropTypes.number),
      rotationPivot: PropTypes.arrayOf(PropTypes.number),
      renderingOrder: PropTypes.number,
      visible: PropTypes.bool,
      opacity: PropTypes.number,
      width: PropTypes.number,
      height: PropTypes.number,
      length: PropTypes.number,
      materials: PropTypes.oneOfType([
        PropTypes.arrayOf(PropTypes.string),
        PropTypes.string
      ]),
      animation: PropTypes.shape({
        name: PropTypes.string,
        delay: PropTypes.number,
        loop: PropTypes.bool,
        onStart: PropTypes.func,
        onFinish: PropTypes.func,
        run: PropTypes.bool,
        interruptible: PropTypes.bool,
      }),
      transformBehaviors: PropTypes.oneOfType([
        PropTypes.arrayOf(PropTypes.string),
        PropTypes.string
      ]),
      lightReceivingBitMask : PropTypes.number,
      shadowCastingBitMask : PropTypes.number,
      ignoreEventHandling: PropTypes.bool,
      dragType: PropTypes.oneOf(["FixedDistance", "FixedDistanceOrigin", "FixedToWorld", "FixedToPlane"]),
      dragPlane: PropTypes.shape({
        planePoint : PropTypes.arrayOf(PropTypes.number),
        planeNormal : PropTypes.arrayOf(PropTypes.number),
        maxDistance : PropTypes.number
      }),
  
      onTransformUpdate: PropTypes.func,
      onHover: PropTypes.func,
      onClick: PropTypes.func,
      onClickState: PropTypes.func,
      onTouch: PropTypes.func,
      onScroll: PropTypes.func,
      onSwipe: PropTypes.func,
      onDrag: PropTypes.func,
      onPinch: PropTypes.func,
      onRotate: PropTypes.func,
      onFuse: PropTypes.oneOfType([
        PropTypes.shape({
          callback: PropTypes.func.isRequired,
          timeToFuse: PropTypes.number
        }),
        PropTypes.func,
      ]),
      /**
       * Enables high accuracy event collision checks for this object.
       * This can be useful for complex 3D objects where the default
       * checking method of bounding boxes do not provide adequate
       * collision detection coverage.
       *
       * NOTE: Enabling high accuracy event collision checks has a high
       * performance cost and should be used sparingly / only when
       * necessary.
       *
       * Flag is set to false by default.
       */
      highAccuracyEvents:PropTypes.bool,
      /* DEPRECATION WARNING - highAccuracyGaze has been deprecated, please use highAccuracyEvents instead */
      highAccuracyGaze:PropTypes.bool,
      physicsBody: PropTypes.shape({
        type: PropTypes.oneOf(['Dynamic','Kinematic','Static']).isRequired,
        mass: PropTypes.number,
        restitution: PropTypes.number,
        shape: PropTypes.shape({
          type: PropTypes.oneOf(["Box", "Sphere", "Compound"]).isRequired,
          params: PropTypes.arrayOf(PropTypes.number)
        }),
        friction: PropTypes.number,
        useGravity: PropTypes.bool,
        enabled: PropTypes.bool,
        velocity: PropTypes.arrayOf(PropTypes.number),
        force:  PropTypes.oneOfType([
          PropTypes.arrayOf(PropTypes.shape({
            value: PropTypes.arrayOf(PropTypes.number),
            position: PropTypes.arrayOf(PropTypes.number)
          })),
          PropTypes.shape({
            value: PropTypes.arrayOf(PropTypes.number),
            position: PropTypes.arrayOf(PropTypes.number)
          }),
        ]),
        torque: PropTypes.arrayOf(PropTypes.number)
      }),
  
      viroTag: PropTypes.string,
      onCollision: PropTypes.func,
    },
  
    _onHover: function(event: Event) {
      this.props.onHover && this.props.onHover(event.nativeEvent.isHovering, event.nativeEvent.position, event.nativeEvent.source);
    },
  
    _onClick: function(event: Event) {
      this.props.onClick && this.props.onClick(event.nativeEvent.position, event.nativeEvent.source);
    },
  
    _onClickState: function(event: Event) {
      this.props.onClickState && this.props.onClickState(event.nativeEvent.clickState, event.nativeEvent.position, event.nativeEvent.source);
      let CLICKED = 3; // Value representation of Clicked ClickState within EventDelegateJni.
      if (event.nativeEvent.clickState == CLICKED){
        this._onClick(event)
      }
    },
  
    _onTouch: function(event: Event) {
      this.props.onTouch && this.props.onTouch(event.nativeEvent.touchState, event.nativeEvent.touchPos, event.nativeEvent.source);
    },
  
    _onScroll: function(event: Event) {
      this.props.onScroll && this.props.onScroll(event.nativeEvent.scrollPos, event.nativeEvent.source);
    },
  
    _onSwipe: function(event: Event) {
      this.props.onSwipe && this.props.onSwipe(event.nativeEvent.swipeState, event.nativeEvent.source);
    },
  
    _onPinch: function(event: Event) {
      this.props.onPinch && this.props.onPinch(event.nativeEvent.pinchState, event.nativeEvent.scaleFactor, event.nativeEvent.source);
    },
  
    _onRotate: function(event: Event) {
      this.props.onRotate && this.props.onRotate(event.nativeEvent.rotateState, event.nativeEvent.rotationFactor, event.nativeEvent.source);
    },
  
    _onDrag: function(event: Event) {
      this.props.onDrag
        && this.props.onDrag(event.nativeEvent.dragToPos, event.nativeEvent.source);
    },
  
    _onFuse: function(event: Event){
      if (this.props.onFuse){
        if (typeof this.props.onFuse === 'function'){
          this.props.onFuse(event.nativeEvent.source);
        } else if (this.props.onFuse != undefined && this.props.onFuse.callback != undefined){
          this.props.onFuse.callback(event.nativeEvent.source);
        }
      }
    },
  
    _onAnimationStart: function(event: Event) {
      this.props.animation && this.props.animation.onStart && this.props.animation.onStart();
    },
  
    _onAnimationFinish: function(event: Event) {
      this.props.animation && this.props.animation.onFinish && this.props.animation.onFinish();
    },
  
    async getTransformAsync() {
      return await NativeModules.VRTNodeModule.getNodeTransform(findNodeHandle(this));
    },
  
    async getBoundingBoxAsync() {
      return await NativeModules.VRTNodeModule.getBoundingBox(findNodeHandle(this));
    },
  
    applyImpulse: function(force, position) {
      NativeModules.VRTNodeModule.applyImpulse(findNodeHandle(this), force, position);
    },
  
    applyTorqueImpulse: function(torque) {
      NativeModules.VRTNodeModule.applyTorqueImpulse(findNodeHandle(this), torque);
    },
  
    setVelocity: function(velocity) {
      NativeModules.VRTNodeModule.setVelocity(findNodeHandle(this), velocity);
    },
  
    _onCollision: function(event: Event){
      if (this.props.onCollision){
        this.props.onCollision(event.nativeEvent.viroTag,
          event.nativeEvent.collidedPoint, event.nativeEvent.collidedNormal);
      }
    },
  
    // Called from native on the event a positional change has occured
    // for the underlying control within the renderer.
    _onNativeTransformUpdate: function(event: Event){
      var position =  event.nativeEvent.position;
      if (this.props.onTransformUpdate){
        this.props.onTransformUpdate(position);
      }
    },
  
    setNativeProps: function(nativeProps) {
      this._component.setNativeProps(nativeProps);
    },
  
    render: function() {
  
      checkMisnamedProps("ViroBox", this.props);
  
      // Since materials and transformBehaviors can be either a string or an array, convert the string to a 1-element array.
      let materials = typeof this.props.materials === 'string' ? new Array(this.props.materials) : this.props.materials;
      let transformBehaviors = typeof this.props.transformBehaviors === 'string' ?
          new Array(this.props.transformBehaviors) : this.props.transformBehaviors;
  
      if(materials) {
        if(materials.length!=1 && materials.length!=6) {
          console.error("<ViroBox> can only take 1 material for all sides or 6, one for each side.");
        }
      }
  
      let timeToFuse = undefined;
      if (this.props.onFuse != undefined && typeof this.props.onFuse === 'object'){
        timeToFuse = this.props.onFuse.timeToFuse;
      }
  
      let transformDelegate = this.props.onTransformUpdate != undefined ? this._onNativeTransformUpdate : undefined;
  
      let highAccuracyEvents = this.props.highAccuracyEvents;
      if (this.props.highAccuracyEvents == undefined && this.props.highAccuracyGaze != undefined) {
        console.warn("**DEPRECATION WARNING** highAccuracyGaze has been deprecated/renamed to highAccuracyEvents");
        highAccuracyEvents = this.props.highAccuracyGaze;
      }
  
      return (
        <VRTBox
          {...this.props}
          ref={ component => {this._component = component; }}
          highAccuracyEvents={highAccuracyEvents}
          transformBehaviors={transformBehaviors}
          onNativeTransformDelegateViro={transformDelegate}
          hasTransformDelegate={this.props.onTransformUpdate != undefined}
          materials={materials}
          canHover={this.props.onHover != undefined}
          canClick={this.props.onClick != undefined || this.props.onClickState != undefined}
          canTouch={this.props.onTouch != undefined}
          canScroll={this.props.onScroll != undefined}
          canSwipe={this.props.onSwipe != undefined}
          canDrag={this.props.onDrag != undefined}
          canPinch={this.props.onPinch != undefined}
          canRotate={this.props.onRotate != undefined}
          canFuse={this.props.onFuse != undefined}
          onHoverViro={this._onHover}
          onClickViro={this._onClickState}
          onTouchViro={this._onTouch}
          onScrollViro={this._onScroll}
          onSwipeViro={this._onSwipe}
          onDragViro={this._onDrag}
          onPinchViro={this._onPinch}
          onRotateViro={this._onRotate}
          onFuseViro={this._onFuse}
          onAnimationStartViro={this._onAnimationStart}
          onAnimationFinishViro={this._onAnimationFinish}
          canCollide={this.props.onCollision != undefined}
          onCollisionViro={this._onCollision}
          timeToFuse={timeToFuse}/>
      );
    }
  });
  
  var VRTBox = requireNativeComponent(
    'VRTBox', ViroBox, {
      nativeOnly: {
        canHover: true,
        canClick: true,
        canTouch: true,
        canScroll: true,
        canSwipe: true,
        canDrag: true,
        canPinch: true,
        canRotate: true,
        canFuse: true,
        onHoverViro:true,
        onClickViro:true,
        onTouchViro:true,
        onScrollViro:true,
        onSwipeViro:true,
        onDragViro:true,
        onPinchViro:true,
        onRotateViro:true,
        onFuseViro:true,
        timeToFuse:true,
        canCollide:true,
        onCollisionViro:true,
        onNativeTransformDelegateViro:true,
        hasTransformDelegate:true,
        onAnimationStartViro:true,
        onAnimationFinishViro:true
      }
    }
  );
  
  module.exports = ViroBox;
  