protected _buildInternalProps()

in src/windows/View.tsx [191:339]


    protected _buildInternalProps(props: Types.ViewProps) {
        // Base class does the bulk of _internalprops creation
        super._buildInternalProps(props);

        // On Windows a view with importantForAccessibility='Yes' or
        // non-empty accessibilityLabel and importantForAccessibility='Auto' (or unspecified) will hide its children.
        // However, a view that is also a group or a dialog should keep children visible to UI Automation.
        // The following condition checks and sets RN importantForAccessibility property
        // to 'yes-dont-hide-descendants' to keep view children visible.
        const hasGroup = this._hasTrait(Types.AccessibilityTrait.Group, props.accessibilityTraits);
        const hasDialog = this._hasTrait(Types.AccessibilityTrait.Dialog, props.accessibilityTraits);
        const i4aYes = props.importantForAccessibility === Types.ImportantForAccessibility.Yes;
        const i4aAuto = (props.importantForAccessibility === Types.ImportantForAccessibility.Auto
            || props.importantForAccessibility === undefined);
        const hasLabel = props.accessibilityLabel && props.accessibilityLabel.length > 0;
        if ((hasGroup || hasDialog) && (i4aYes || (i4aAuto && hasLabel))) {
            this._internalProps.importantForAccessibility = 'yes-dont-hide-descendants';
        }

        if (props.onKeyPress) {

            // Define the handler for "onKeyDown" on first use, it's the safest way when functions
            // called from super constructors are involved. Ensuring nothing happens here if a
            // tabIndex is specified else KeyDown is handled twice, in _onFocusableKeyDown as well.
            if (this.props.tabIndex === undefined) {
                if (!this._onKeyDown) {
                    this._onKeyDown =  (e: Types.SyntheticEvent) => {
                        const keyEvent = EventHelpers.toKeyboardEvent(e);
                        if (this.props.onKeyPress) {
                            // A conversion to a KeyboardEvent looking event is needed
                            this.props.onKeyPress(keyEvent);
                        }

                        // This needs to be handled when there is no
                        // tabIndex so we do not lose the bubbled events
                        if (this.props.onContextMenu) {
                            const key = keyEvent.keyCode;
                            if ((key === KEY_CODE_APP) || (key === KEY_CODE_F10 && keyEvent.shiftKey)) {
                                this._showContextMenu(keyEvent);
                            }
                        }
                    };
                }
                // "onKeyDown" is fired by native buttons and bubbles up to views
                this._internalProps.onKeyDown = this._onKeyDown;
            }
        }

        // Drag and drop related properties
        for (const name of ['onDragEnter', 'onDragOver', 'onDrop', 'onDragLeave']) {
            const handler = this._internalProps[name];

            if (handler) {
                this._internalProps.allowDrop = true;

                this._internalProps[name] = (e: React.SyntheticEvent<View>) => {
                    handler({
                        dataTransfer: (e.nativeEvent as any).dataTransfer,

                        stopPropagation() {
                            if (e.stopPropagation) {
                                e.stopPropagation();
                            }
                        },

                        preventDefault() {
                            if (e.preventDefault) {
                                e.preventDefault();
                            }
                        },
                    });
                };
            }
        }

        // Drag and drop related properties
        for (const name of ['onDragStart', 'onDrag', 'onDragEnd']) {
            const handler = this._internalProps[name];

            if (handler) {
                if (name === 'onDragStart') {
                    this._internalProps.allowDrag = true;
                }

                this._internalProps[name] = (e: React.SyntheticEvent<View>) => {
                    handler({
                        dataTransfer: (e.nativeEvent as any).dataTransfer,

                        stopPropagation() {
                            if (e.stopPropagation) {
                                e.stopPropagation();
                            }
                        },

                        preventDefault() {
                            if (e.preventDefault) {
                                e.preventDefault();
                            }
                        },
                    });
                };
            }
        }

        // Mouse events (using same lazy initialization as for onKeyDown)
        if (props.onMouseEnter) {
            if (!this._onMouseEnter) {
                this._onMouseEnter =  (e: React.SyntheticEvent<any>) => {
                    if (this.props.onMouseEnter) {
                        this.props.onMouseEnter(EventHelpers.toMouseEvent(e));
                    }
                };
            }
            this._internalProps.onMouseEnter = this._onMouseEnter;
        }

        if (props.onMouseLeave) {
            if (!this._onMouseLeave) {
                this._onMouseLeave =  (e: React.SyntheticEvent<any>) => {
                    if (this.props.onMouseLeave) {
                        this.props.onMouseLeave(EventHelpers.toMouseEvent(e));
                    }
                };
            }
            this._internalProps.onMouseLeave = this._onMouseLeave;
        }

        if (props.onMouseOver) {
            if (!this._onMouseOver) {
                this._onMouseOver =  (e: React.SyntheticEvent<any>) => {
                    if (this.props.onMouseOver) {
                        this.props.onMouseOver(EventHelpers.toMouseEvent(e));
                    }
                };
            }
            this._internalProps.onMouseOver = this._onMouseOver;
        }

        if (props.onMouseMove) {
            if (!this._onMouseMove) {
                this._onMouseMove =  (e: React.SyntheticEvent<any>) => {
                    if (this.props.onMouseMove) {
                        this.props.onMouseMove(EventHelpers.toMouseEvent(e));
                    }
                };
            }
            this._internalProps.onMouseMove = this._onMouseMove;
        }
    }