react-native/Libraries/Text
Douglas 45185947ee Fix tvOS compile issues; enable TVEventHandler in Modal (fix #15389)
Summary:
**Motivation**

Fix an issue (#15389) where `TVEventHandler` would not work when a modal was visible.  The solution adds the gesture recognizers from the native `RCTTVRemoteHandler` to the native modal view (except for the menu button recognizer, which still needs special handling in modals).  This PR also fixes some breakages in compiling React Native for tvOS.

**Test plan**

Compilation fixes should enable tvOS compile test to pass in Travis CI.

The modal fix can be tested with the following component, modified from the original source in #15389 .

``` javascript
import React, { Component } from 'react';
import ReactNative from 'ReactNative';
import {
    Text,
    View,
    StyleSheet,
    TouchableHighlight,
    TVEventHandler,
    Modal,
} from 'react-native';

export default class Events extends Component {

    constructor(props) {
        super(props);

        this.state = {
            modalVisible: false,
        };
        this._tvEventHandler = new TVEventHandler();
    }

    _enableTVEventHandler() {
        this._tvEventHandler.enable(this, (cmp, evt) => {
            const myTag = ReactNative.findNodeHandle(cmp);
            console.log('Event.js TVEventHandler: ', evt.eventType);
            // if (evt.eventType !== 'blur' && evt.eventType !== 'focus') {
            //  console.log('Event.js TVEventHandler: ', evt.eventType);
            // }
        });
    }

    _disableTVEventHandler() {
        if (this._tvEventHandler) {
            this._tvEventHandler.disable();
            delete this._tvEventHandler;
        }
    }

    componentDidMount() {
        this._enableTVEventHandler();
    }

    componentWillUnmount() {
        this._disableTVEventHandler();
    }

    _renderRow() {
        return (
            <View style={styles.row}>
                {
                    Array.from({ length: 7 }).map((_, index) => {
                        return (
                            <TouchableHighlight
                                key={index}
                                onPress={() => { this.setState({ modalVisible: !this.state.modalVisible }); }}
                            >
                                <View style={styles.item}>
                                    <Text style={styles.itemText}>{ index }</Text>
                                </View>
                            </TouchableHighlight>
                        );
                    })
                }
            </View>
        );
    }

    onTVEvent(cmp, evt) {
      console.log('Modal.js TVEventHandler: ', evt.eventType);
    }

    hideModal() {
      this.setState({
        modalVisible: false
      });
    }

    render() {
        return (
            <View style={styles.container}>
                <Modal visible={this.state.modalVisible}
                       onRequestClose={() => this.hideModal()}>
                    <View style={styles.modal}>
                        { this._renderRow() }
                        { this._renderRow() }
                    </View>
                </Modal>
                { this._renderRow() }
                { this._renderRow() }
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'darkslategrey',
    },
    row: {
        flexDirection: 'row',
        padding: 30,
    },
    item: {
        width: 200,
        height: 100,
        borderColor: 'cyan',
        borderWidth: 2,
        margin: 30,
        alignItems: 'center',
        justifyContent: 'center',
    },
    itemText: {
        fontSize: 40,
        color: 'cyan',
    },
    modal: {
        flex: 1,
        backgroundColor: 'steelblue',
    },
});
```
**Release Notes**

After this change, the `onRequestClose` property will be required for a `Modal` in Apple TV.
Closes https://github.com/facebook/react-native/pull/16076

Differential Revision: D6288801

Pulled By: hramos

fbshipit-source-id: 446ae94a060387324aa9e528bd93cdabc9b5b37f
2017-11-09 13:54:54 -08:00
..
RCTText.xcodeproj Fix tvOS compile issues; enable TVEventHandler in Modal (fix #15389) 2017-11-09 13:54:54 -08:00
RCTBackedTextInputDelegate.h TextInput: Unified support of `blurOnSubmit` prop 2017-07-18 14:46:22 -07:00
RCTBackedTextInputDelegateAdapter.h TextInput: `selection` property was unified 2017-07-18 14:46:22 -07:00
RCTBackedTextInputDelegateAdapter.m TextInput: `selection` property was unified 2017-07-18 14:46:22 -07:00
RCTBackedTextInputViewProtocol.h TextInput: Refined contentSize calculation 2017-07-18 14:46:22 -07:00
RCTConvert+Text.h iOS: Introduce spellCheck prop to TextInput 2016-11-25 04:28:28 -08:00
RCTConvert+Text.m iOS: Introduce spellCheck prop to TextInput 2016-11-25 04:28:28 -08:00
RCTFontAttributes.h iOS: Support allowFontScaling on TextInput 2017-10-01 21:45:33 -07:00
RCTFontAttributes.m iOS: Support allowFontScaling on TextInput 2017-10-01 21:45:33 -07:00
RCTFontAttributesDelegate.h iOS: Support allowFontScaling on TextInput 2017-10-01 21:45:33 -07:00
RCTRawTextManager.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTRawTextManager.m Revert D4538026: Stop allocating an RCTView for everying RCTRawText 2017-02-13 15:00:18 -08:00
RCTShadowRawText.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTShadowRawText.m Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTShadowText.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTShadowText.m Re-render views when direction changes 2017-10-03 13:01:06 -07:00
RCTShadowTextField.h Better TextInput: RCTTextView and RCTTextField was marked as Yoga leaf nodes 2017-03-13 13:46:26 -07:00
RCTShadowTextField.m Better TextInput: RCTTextView and RCTTextField was marked as Yoga leaf nodes 2017-03-13 13:46:26 -07:00
RCTShadowTextView.h Better TextInput: RCTTextView and RCTTextField was marked as Yoga leaf nodes 2017-03-13 13:46:26 -07:00
RCTShadowTextView.m Better TextInput: RCTTextView and RCTTextField was marked as Yoga leaf nodes 2017-03-13 13:46:26 -07:00
RCTText.h Added support of `<Text>`'s `selectable` attribute on iOS 2016-11-17 16:13:28 -08:00
RCTText.m Proper support of the accessibilityLabel for <Text> components on iOS 2017-09-12 12:53:59 -07:00
RCTTextField.h TextInput: `selection` property was unified 2017-07-18 14:46:22 -07:00
RCTTextField.m iOS: Support allowFontScaling on TextInput 2017-10-01 21:45:33 -07:00
RCTTextFieldManager.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTTextFieldManager.m iOS: Support allowFontScaling on TextInput 2017-10-01 21:45:33 -07:00
RCTTextInput.h Remove retain cycle in RCTTextField/RCTTextInput 2017-11-02 08:51:34 -07:00
RCTTextInput.m RCTTextInput: Fixed problem with accessory view & 3rd party libs 2017-10-08 21:48:14 -07:00
RCTTextManager.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTTextManager.m Several layout related helper methods of RCTShadowView was moved to new (+Layout) category. 2017-05-08 11:31:20 -07:00
RCTTextSelection.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTTextSelection.m Add TextInput controlled selection prop on iOS 2016-08-25 17:28:37 -07:00
RCTTextView.h TextInput: `selection` property was unified 2017-07-18 14:46:22 -07:00
RCTTextView.m iOS: Support allowFontScaling on TextInput 2017-10-01 21:45:33 -07:00
RCTTextViewManager.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTTextViewManager.m iOS: Support allowFontScaling on TextInput 2017-10-01 21:45:33 -07:00
RCTUITextField.h Introducing `RCTBackedTextInputDelegate` 2017-07-18 14:46:22 -07:00
RCTUITextField.m TextInput: Refined contentSize calculation 2017-07-18 14:46:22 -07:00
RCTUITextView.h Introducing `RCTBackedTextInputDelegate` 2017-07-18 14:46:22 -07:00
RCTUITextView.m TextInput: Refined contentSize calculation 2017-07-18 14:46:22 -07:00
Text.js Fix missing return in example 2017-11-08 12:17:44 -08:00
TextStylePropTypes.js Update remaining PropTypes references 2017-06-12 16:03:09 -07:00
TextUpdateTest.js @allow-large-files Flow v0.54.0 2017-09-06 03:33:43 -07:00