2017-07-31 10:53:09 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2017-present, Facebook, Inc.
|
|
|
|
*
|
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.
|
2017-07-31 10:53:09 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2017-07-31 10:53:09 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2017-07-31 10:53:09 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
|
|
|
|
|
|
|
var {
|
|
|
|
Platform,
|
|
|
|
StyleSheet,
|
|
|
|
View,
|
|
|
|
Text,
|
|
|
|
TouchableOpacity,
|
|
|
|
TVEventHandler,
|
|
|
|
} = ReactNative;
|
|
|
|
|
|
|
|
exports.framework = 'React';
|
|
|
|
exports.title = 'TVEventHandler example';
|
|
|
|
exports.description = 'iOS alerts and action sheets';
|
2018-05-11 20:32:37 +00:00
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'TVEventHandler',
|
|
|
|
render() {
|
|
|
|
return <TVEventHandlerView />;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
2017-07-31 10:53:09 +00:00
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
class TVEventHandlerView extends React.Component<
|
|
|
|
$FlowFixMeProps,
|
|
|
|
{
|
|
|
|
lastEventType: string,
|
|
|
|
},
|
|
|
|
> {
|
2017-07-31 10:53:09 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-05-11 20:32:37 +00:00
|
|
|
lastEventType: '',
|
2017-07-31 10:53:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_tvEventHandler: any;
|
|
|
|
|
|
|
|
_enableTVEventHandler() {
|
|
|
|
this._tvEventHandler = new TVEventHandler();
|
|
|
|
this._tvEventHandler.enable(this, function(cmp, evt) {
|
|
|
|
cmp.setState({
|
2018-05-11 20:32:37 +00:00
|
|
|
lastEventType: evt.eventType,
|
2017-10-10 00:37:08 +00:00
|
|
|
});
|
2017-07-31 10:53:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_disableTVEventHandler() {
|
|
|
|
if (this._tvEventHandler) {
|
|
|
|
this._tvEventHandler.disable();
|
|
|
|
delete this._tvEventHandler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this._enableTVEventHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this._disableTVEventHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-06-10 20:37:53 +00:00
|
|
|
if (Platform.isTV) {
|
2017-07-31 10:53:09 +00:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TouchableOpacity onPress={() => {}}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>
|
|
|
|
This example enables an instance of TVEventHandler to show the
|
|
|
|
last event detected from the Apple TV Siri remote or from a
|
|
|
|
keyboard.
|
|
|
|
</Text>
|
2017-07-31 10:53:09 +00:00
|
|
|
</TouchableOpacity>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text style={{color: 'blue'}}>{this.state.lastEventType}</Text>
|
2017-07-31 10:53:09 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>This example is intended to be run on Apple TV.</Text>
|
2017-07-31 10:53:09 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|