2015-07-28 14:31:26 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2015-07-28 14:31:26 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2015-07-28 14:31:26 +00:00
|
|
|
var {
|
|
|
|
Modal,
|
2016-09-07 13:06:12 +00:00
|
|
|
Picker,
|
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 21:41:29 +00:00
|
|
|
Platform,
|
2015-07-28 14:31:26 +00:00
|
|
|
StyleSheet,
|
2016-03-18 11:20:36 +00:00
|
|
|
Switch,
|
2015-07-28 14:31:26 +00:00
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2016-09-14 09:55:24 +00:00
|
|
|
|
2016-09-07 13:06:12 +00:00
|
|
|
const Item = Picker.Item;
|
2015-07-28 14:31:26 +00:00
|
|
|
|
|
|
|
exports.displayName = (undefined: ?string);
|
|
|
|
exports.framework = 'React';
|
|
|
|
exports.title = '<Modal>';
|
|
|
|
exports.description = 'Component for presenting modal views.';
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class Button extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
active: false,
|
|
|
|
};
|
2015-08-13 16:09:10 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_onHighlight = () => {
|
2015-08-13 16:09:10 +00:00
|
|
|
this.setState({active: true});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-08-13 16:09:10 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_onUnhighlight = () => {
|
2015-08-13 16:09:10 +00:00
|
|
|
this.setState({active: false});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-08-13 16:09:10 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
var colorStyle = {
|
|
|
|
color: this.state.active ? '#fff' : '#000',
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<TouchableHighlight
|
|
|
|
onHideUnderlay={this._onUnhighlight}
|
|
|
|
onPress={this.props.onPress}
|
|
|
|
onShowUnderlay={this._onHighlight}
|
|
|
|
style={[styles.button, this.props.style]}
|
|
|
|
underlayColor="#a9d9d4">
|
|
|
|
<Text style={[styles.buttonText, colorStyle]}>{this.props.children}</Text>
|
|
|
|
</TouchableHighlight>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-08-13 16:09:10 +00:00
|
|
|
|
2016-09-07 13:06:12 +00:00
|
|
|
const supportedOrientationsPickerValues = [
|
|
|
|
['portrait'],
|
|
|
|
['landscape'],
|
|
|
|
['landscape-left'],
|
|
|
|
['portrait', 'landscape-right'],
|
|
|
|
['portrait', 'landscape'],
|
|
|
|
[],
|
|
|
|
];
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ModalExample extends React.Component<{}, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
animationType: 'none',
|
|
|
|
modalVisible: false,
|
|
|
|
transparent: false,
|
2017-06-21 02:02:27 +00:00
|
|
|
presentationStyle: 'fullScreen',
|
2016-09-07 13:06:12 +00:00
|
|
|
selectedSupportedOrientation: 0,
|
|
|
|
currentOrientation: 'unknown',
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-07-28 14:31:26 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_setModalVisible = (visible) => {
|
2015-08-13 16:09:10 +00:00
|
|
|
this.setState({modalVisible: visible});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-07-28 14:31:26 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_setAnimationType = (type) => {
|
2016-04-28 22:59:11 +00:00
|
|
|
this.setState({animationType: type});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-07-28 14:31:26 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_toggleTransparent = () => {
|
2015-08-13 16:09:10 +00:00
|
|
|
this.setState({transparent: !this.state.transparent});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-07-28 14:31:26 +00:00
|
|
|
|
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 21:41:29 +00:00
|
|
|
renderSwitch() {
|
|
|
|
if (Platform.isTVOS) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Switch value={this.state.transparent} onValueChange={this._toggleTransparent} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-13 16:09:10 +00:00
|
|
|
render() {
|
|
|
|
var modalBackgroundStyle = {
|
|
|
|
backgroundColor: this.state.transparent ? 'rgba(0, 0, 0, 0.5)' : '#f5fcff',
|
|
|
|
};
|
|
|
|
var innerContainerTransparentStyle = this.state.transparent
|
|
|
|
? {backgroundColor: '#fff', padding: 20}
|
|
|
|
: null;
|
2016-04-28 22:59:11 +00:00
|
|
|
var activeButtonStyle = {
|
|
|
|
backgroundColor: '#ddd'
|
|
|
|
};
|
2015-08-13 16:09:10 +00:00
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
return (
|
|
|
|
<View>
|
2015-08-13 16:09:10 +00:00
|
|
|
<Modal
|
2016-04-28 22:59:11 +00:00
|
|
|
animationType={this.state.animationType}
|
2017-06-21 02:02:27 +00:00
|
|
|
presentationStyle={this.state.presentationStyle}
|
2015-08-13 16:09:10 +00:00
|
|
|
transparent={this.state.transparent}
|
2016-03-18 11:20:36 +00:00
|
|
|
visible={this.state.modalVisible}
|
2016-09-07 13:06:12 +00:00
|
|
|
onRequestClose={() => this._setModalVisible(false)}
|
|
|
|
supportedOrientations={supportedOrientationsPickerValues[this.state.selectedSupportedOrientation]}
|
|
|
|
onOrientationChange={evt => this.setState({currentOrientation: evt.nativeEvent.orientation})}
|
2016-03-18 11:20:36 +00:00
|
|
|
>
|
2015-08-13 16:09:10 +00:00
|
|
|
<View style={[styles.container, modalBackgroundStyle]}>
|
|
|
|
<View style={[styles.innerContainer, innerContainerTransparentStyle]}>
|
2016-04-28 22:59:11 +00:00
|
|
|
<Text>This modal was presented {this.state.animationType === 'none' ? 'without' : 'with'} animation.</Text>
|
2016-09-07 13:06:12 +00:00
|
|
|
<Text>It is currently displayed in {this.state.currentOrientation} mode.</Text>
|
2015-08-13 16:09:10 +00:00
|
|
|
<Button
|
|
|
|
onPress={this._setModalVisible.bind(this, false)}
|
|
|
|
style={styles.modalButton}>
|
|
|
|
Close
|
|
|
|
</Button>
|
|
|
|
</View>
|
2015-07-28 14:31:26 +00:00
|
|
|
</View>
|
|
|
|
</Modal>
|
2015-08-13 16:09:10 +00:00
|
|
|
<View style={styles.row}>
|
2016-04-28 22:59:11 +00:00
|
|
|
<Text style={styles.rowTitle}>Animation Type</Text>
|
|
|
|
<Button onPress={this._setAnimationType.bind(this, 'none')} style={this.state.animationType === 'none' ? activeButtonStyle : {}}>
|
|
|
|
none
|
|
|
|
</Button>
|
|
|
|
<Button onPress={this._setAnimationType.bind(this, 'slide')} style={this.state.animationType === 'slide' ? activeButtonStyle : {}}>
|
|
|
|
slide
|
|
|
|
</Button>
|
|
|
|
<Button onPress={this._setAnimationType.bind(this, 'fade')} style={this.state.animationType === 'fade' ? activeButtonStyle : {}}>
|
|
|
|
fade
|
|
|
|
</Button>
|
2015-08-13 16:09:10 +00:00
|
|
|
</View>
|
2015-07-28 14:31:26 +00:00
|
|
|
|
2015-08-13 16:09:10 +00:00
|
|
|
<View style={styles.row}>
|
|
|
|
<Text style={styles.rowTitle}>Transparent</Text>
|
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 21:41:29 +00:00
|
|
|
{this.renderSwitch()}
|
2015-08-13 16:09:10 +00:00
|
|
|
</View>
|
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 21:41:29 +00:00
|
|
|
{this.renderPickers()}
|
|
|
|
<Button onPress={this._setModalVisible.bind(this, true)}>
|
|
|
|
Present
|
|
|
|
</Button>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
renderPickers() {
|
|
|
|
if (Platform.isTVOS) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View>
|
2017-06-21 02:02:27 +00:00
|
|
|
<View>
|
|
|
|
<Text style={styles.rowTitle}>Presentation style</Text>
|
|
|
|
<Picker
|
|
|
|
selectedValue={this.state.presentationStyle}
|
|
|
|
onValueChange={(presentationStyle) => this.setState({presentationStyle})}
|
|
|
|
itemStyle={styles.pickerItem}
|
|
|
|
>
|
|
|
|
<Item label="Full Screen" value="fullScreen" />
|
|
|
|
<Item label="Page Sheet" value="pageSheet" />
|
|
|
|
<Item label="Form Sheet" value="formSheet" />
|
|
|
|
<Item label="Over Full Screen" value="overFullScreen" />
|
|
|
|
<Item label="Default presentationStyle" value={null} />
|
|
|
|
</Picker>
|
|
|
|
</View>
|
|
|
|
|
2016-09-07 13:06:12 +00:00
|
|
|
<View>
|
|
|
|
<Text style={styles.rowTitle}>Supported orientations</Text>
|
|
|
|
<Picker
|
|
|
|
selectedValue={this.state.selectedSupportedOrientation}
|
|
|
|
onValueChange={(_, i) => this.setState({selectedSupportedOrientation: i})}
|
|
|
|
itemStyle={styles.pickerItem}
|
|
|
|
>
|
|
|
|
<Item label="Portrait" value={0} />
|
|
|
|
<Item label="Landscape" value={1} />
|
|
|
|
<Item label="Landscape left" value={2} />
|
|
|
|
<Item label="Portrait and landscape right" value={3} />
|
|
|
|
<Item label="Portrait and landscape" value={4} />
|
|
|
|
<Item label="Default supportedOrientations" value={5} />
|
|
|
|
</Picker>
|
|
|
|
</View>
|
2015-07-28 14:31:26 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-28 14:31:26 +00:00
|
|
|
|
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 21:41:29 +00:00
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Modal Presentation',
|
|
|
|
description: 'Modals can be presented with or without animation',
|
|
|
|
render: () => <ModalExample />,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
container: {
|
2015-08-13 16:09:10 +00:00
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
padding: 20,
|
|
|
|
},
|
|
|
|
innerContainer: {
|
|
|
|
borderRadius: 10,
|
2015-10-31 00:03:23 +00:00
|
|
|
alignItems: 'center',
|
2015-08-13 16:09:10 +00:00
|
|
|
},
|
|
|
|
row: {
|
2015-07-28 14:31:26 +00:00
|
|
|
alignItems: 'center',
|
|
|
|
flex: 1,
|
2015-08-13 16:09:10 +00:00
|
|
|
flexDirection: 'row',
|
|
|
|
marginBottom: 20,
|
|
|
|
},
|
|
|
|
rowTitle: {
|
|
|
|
flex: 1,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
borderRadius: 5,
|
2016-10-28 12:28:19 +00:00
|
|
|
flexGrow: 1,
|
2015-08-13 16:09:10 +00:00
|
|
|
height: 44,
|
2015-10-31 00:03:23 +00:00
|
|
|
alignSelf: 'stretch',
|
2015-07-28 14:31:26 +00:00
|
|
|
justifyContent: 'center',
|
2015-08-13 16:09:10 +00:00
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
buttonText: {
|
|
|
|
fontSize: 18,
|
|
|
|
margin: 5,
|
|
|
|
textAlign: 'center',
|
|
|
|
},
|
|
|
|
modalButton: {
|
|
|
|
marginTop: 10,
|
2015-07-28 14:31:26 +00:00
|
|
|
},
|
2016-09-07 13:06:12 +00:00
|
|
|
pickerItem: {
|
|
|
|
fontSize: 16,
|
|
|
|
},
|
2015-07-28 14:31:26 +00:00
|
|
|
});
|