react-native-macos/React/Views/RCTModalHostView.h

50 строки
1.6 KiB
C
Исходник Обычный вид История

/**
Squashed commit of the following: commit 4c43e301d97042e9eec4401dd81b8ebce053f691 Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:49:02 2019 -0700 Squashed commit of the following: commit 862f3fb5d9e3161feab6e5e0e61c7b28e8ac1ef9 Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:46:37 2019 -0700 Revert "Merge 1b12e2caaadf094ce9327deb7e5fe49297e8a115 into 9f1e90947421ad0ea2de1b534117c500dc8c9744" This reverts commit d036bc4c5768d6a3327c5766e1791719cb11693f, reversing changes made to 9f1e90947421ad0ea2de1b534117c500dc8c9744. commit 41477c33c1bcc78f40da00ac7e86ab4dd3f7d062 Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:46:23 2019 -0700 Revert "Applying package update to 0.58.6-microsoft.1" This reverts commit 852df1af0e489063db15d74f0d241ea930778b9c. commit 4993963205e737849e4880309ef86aeac9f2a765 Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:46:16 2019 -0700 Revert "Applying package update to 0.58.6-microsoft.2" This reverts commit 774513fec948ee5595543e23ab4e7b9cccbdcbf1. commit 41f8beadb2030593208ffc6ff29339991dde3798 Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:46:07 2019 -0700 Revert "Merge 4f3c37886c3f8d0af9571dbed0ec1361d51219a6 into 774513fec948ee5595543e23ab4e7b9cccbdcbf1" This reverts commit a84049078437ce6e0852a30367b4c2d56be7b884, reversing changes made to 774513fec948ee5595543e23ab4e7b9cccbdcbf1. commit 143e70ec6228e110cd94a5ae9c56309040c1f1eb Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:45:57 2019 -0700 Revert "Applying package update to 0.58.6-microsoft.3" This reverts commit 54dfee820d107cb897c5aca14131cf7fbde616d7. commit 138191b0d6bf9e4370fb5126dc2095a3fb122a57 Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:45:16 2019 -0700 Revert "Merge d8be239facee73f3ba7b664154766dbfb8049050 into 54dfee820d107cb897c5aca14131cf7fbde616d7" This reverts commit faae1e56f805e2fd953218be92b2c0d1753a7c3c, reversing changes made to 54dfee820d107cb897c5aca14131cf7fbde616d7. commit 40a77c8365c5273df0bba4fc2b0439db17d247d0 Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:34:44 2019 -0700 Revert "Applying package update to 0.58.6-microsoft.4" This reverts commit 043f6330e7a7fe7a73ac4e406c157f61cf1e7f1c. commit adf5c26c8f7132a6643ecfea116226632173447b Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:34:42 2019 -0700 Revert "Applying package update to 0.58.6-microsoft.5" This reverts commit 4004f889c28f42535b9cc08d439311b2f5802359. commit e68d497a58e32d26f0d04130895954d7b654c2bf Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:34:39 2019 -0700 Revert "Fix the builds... (#20)" This reverts commit 745eeda26fafa79fd9110e20647ace54c80d3dab. commit 4cdef1eef22edbcdc9ca86e31846a175b944999e Author: REDMOND\acoates <acoates@microsoft.com> Date: Tue Mar 26 10:34:31 2019 -0700 Revert "Applying package update to 0.58.6-microsoft.6" This reverts commit 34a307738806da39704d7f45428920144e0bed53.
2019-03-26 20:54:53 +03:00
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <React/RCTInvalidating.h>
#import <React/RCTModalHostViewManager.h>
#import <React/RCTView.h>
@class RCTBridge;
@class RCTModalHostViewController;
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-10 00:41:29 +03:00
@class RCTTVRemoteHandler;
@protocol RCTModalHostViewInteractor;
@interface RCTModalHostView : UIView <RCTInvalidating>
@property (nonatomic, copy) NSString *animationType;
@property (nonatomic, assign) UIModalPresentationStyle presentationStyle;
@property (nonatomic, assign, getter=isTransparent) BOOL transparent;
@property (nonatomic, copy) RCTDirectEventBlock onShow;
@property (nonatomic, copy) NSNumber *identifier;
@property (nonatomic, weak) id<RCTModalHostViewInteractor> delegate;
@property (nonatomic, copy) NSArray<NSString *> *supportedOrientations;
@property (nonatomic, copy) RCTDirectEventBlock onOrientationChange;
#if TARGET_OS_TV
@property (nonatomic, copy) RCTDirectEventBlock onRequestClose;
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-10 00:41:29 +03:00
@property (nonatomic, strong) RCTTVRemoteHandler *tvRemoteHandler;
#endif
- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
@end
@protocol RCTModalHostViewInteractor <NSObject>
- (void)presentModalHostView:(RCTModalHostView *)modalHostView withViewController:(RCTModalHostViewController *)viewController animated:(BOOL)animated;
- (void)dismissModalHostView:(RCTModalHostView *)modalHostView withViewController:(RCTModalHostViewController *)viewController animated:(BOOL)animated;
@end