2015-07-28 14:31:26 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTModalHostView.h"
|
|
|
|
|
2017-01-09 08:09:38 +00:00
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
#import "RCTAssert.h"
|
|
|
|
#import "RCTBridge.h"
|
|
|
|
#import "RCTModalHostViewController.h"
|
|
|
|
#import "RCTTouchHandler.h"
|
|
|
|
#import "RCTUIManager.h"
|
2017-04-01 10:16:52 +00:00
|
|
|
#import "RCTUtils.h"
|
2015-07-28 14:31:26 +00:00
|
|
|
#import "UIView+React.h"
|
2018-01-09 23:39:14 +00:00
|
|
|
#if TARGET_OS_TV
|
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
|
|
|
#import "RCTTVRemoteHandler.h"
|
2018-01-09 23:39:14 +00:00
|
|
|
#endif
|
2015-07-28 14:31:26 +00:00
|
|
|
|
|
|
|
@implementation RCTModalHostView
|
|
|
|
{
|
2015-11-17 14:35:46 +00:00
|
|
|
__weak RCTBridge *_bridge;
|
2015-10-06 17:09:47 +00:00
|
|
|
BOOL _isPresented;
|
2015-07-28 14:31:26 +00:00
|
|
|
RCTModalHostViewController *_modalViewController;
|
|
|
|
RCTTouchHandler *_touchHandler;
|
2016-04-20 18:19:37 +00:00
|
|
|
UIView *_reactSubview;
|
2017-08-17 22:05:26 +00:00
|
|
|
#if TARGET_OS_TV
|
|
|
|
UITapGestureRecognizer *_menuButtonGestureRecognizer;
|
|
|
|
#else
|
2016-09-07 13:06:12 +00:00
|
|
|
UIInterfaceOrientation _lastKnownOrientation;
|
2016-09-27 13:19:45 +00:00
|
|
|
#endif
|
2017-08-17 22:05:26 +00:00
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 10:14:33 +00:00
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder)
|
2015-07-28 14:31:26 +00:00
|
|
|
|
|
|
|
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
|
|
|
{
|
|
|
|
if ((self = [super initWithFrame:CGRectZero])) {
|
|
|
|
_bridge = bridge;
|
2015-08-17 14:35:34 +00:00
|
|
|
_modalViewController = [RCTModalHostViewController new];
|
2016-04-20 18:19:37 +00:00
|
|
|
UIView *containerView = [UIView new];
|
2016-09-26 22:49:10 +00:00
|
|
|
containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
|
2016-04-20 18:19:37 +00:00
|
|
|
_modalViewController.view = containerView;
|
2015-07-28 14:31:26 +00:00
|
|
|
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:bridge];
|
2017-08-17 22:05:26 +00:00
|
|
|
#if TARGET_OS_TV
|
|
|
|
_menuButtonGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuButtonPressed:)];
|
|
|
|
_menuButtonGestureRecognizer.allowedPressTypes = @[@(UIPressTypeMenu)];
|
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
|
|
|
self.tvRemoteHandler = [RCTTVRemoteHandler new];
|
2017-08-17 22:05:26 +00:00
|
|
|
#endif
|
2015-10-06 17:09:47 +00:00
|
|
|
_isPresented = NO;
|
2015-07-28 14:31:26 +00:00
|
|
|
|
2015-09-19 00:18:09 +00:00
|
|
|
__weak typeof(self) weakSelf = self;
|
2015-07-28 14:31:26 +00:00
|
|
|
_modalViewController.boundsDidChangeBlock = ^(CGRect newBounds) {
|
|
|
|
[weakSelf notifyForBoundsChange:newBounds];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-08-17 22:05:26 +00:00
|
|
|
#if TARGET_OS_TV
|
|
|
|
- (void)menuButtonPressed:(__unused UIGestureRecognizer *)gestureRecognizer
|
|
|
|
{
|
|
|
|
if (_onRequestClose) {
|
|
|
|
_onRequestClose(nil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setOnRequestClose:(RCTDirectEventBlock)onRequestClose
|
|
|
|
{
|
|
|
|
_onRequestClose = onRequestClose;
|
|
|
|
if (_reactSubview) {
|
|
|
|
if (_onRequestClose && _menuButtonGestureRecognizer) {
|
|
|
|
[_reactSubview addGestureRecognizer:_menuButtonGestureRecognizer];
|
|
|
|
} else {
|
|
|
|
[_reactSubview removeGestureRecognizer:_menuButtonGestureRecognizer];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
- (void)notifyForBoundsChange:(CGRect)newBounds
|
|
|
|
{
|
2016-04-20 18:19:37 +00:00
|
|
|
if (_reactSubview && _isPresented) {
|
2017-02-06 18:46:45 +00:00
|
|
|
[_bridge.uiManager setSize:newBounds.size forView:_reactSubview];
|
2016-09-07 13:06:12 +00:00
|
|
|
[self notifyForOrientationChange];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)notifyForOrientationChange
|
|
|
|
{
|
2016-09-27 13:19:45 +00:00
|
|
|
#if !TARGET_OS_TV
|
2016-09-07 13:06:12 +00:00
|
|
|
if (!_onOrientationChange) {
|
|
|
|
return;
|
2015-07-28 14:31:26 +00:00
|
|
|
}
|
2016-09-07 13:06:12 +00:00
|
|
|
|
2017-04-01 10:16:52 +00:00
|
|
|
UIInterfaceOrientation currentOrientation = [RCTSharedApplication() statusBarOrientation];
|
2016-09-07 13:06:12 +00:00
|
|
|
if (currentOrientation == _lastKnownOrientation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_lastKnownOrientation = currentOrientation;
|
|
|
|
|
|
|
|
BOOL isPortrait = currentOrientation == UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown;
|
|
|
|
NSDictionary *eventPayload =
|
|
|
|
@{
|
|
|
|
@"orientation": isPortrait ? @"portrait" : @"landscape",
|
|
|
|
};
|
|
|
|
_onOrientationChange(eventPayload);
|
2016-09-27 13:19:45 +00:00
|
|
|
#endif
|
2015-07-28 14:31:26 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 07:08:16 +00:00
|
|
|
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
|
2015-07-28 14:31:26 +00:00
|
|
|
{
|
2016-04-20 18:19:37 +00:00
|
|
|
RCTAssert(_reactSubview == nil, @"Modal view can only have one subview");
|
2016-06-07 07:08:16 +00:00
|
|
|
[super insertReactSubview:subview atIndex:atIndex];
|
2017-01-09 08:09:38 +00:00
|
|
|
[_touchHandler attachToView:subview];
|
2017-08-17 22:05:26 +00:00
|
|
|
#if TARGET_OS_TV
|
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
|
|
|
for (NSString *key in [self.tvRemoteHandler.tvRemoteGestureRecognizers allKeys]) {
|
|
|
|
if (![key isEqualToString:RCTTVRemoteEventMenu]) {
|
|
|
|
[subview addGestureRecognizer:self.tvRemoteHandler.tvRemoteGestureRecognizers[key]];
|
|
|
|
}
|
|
|
|
}
|
2017-08-17 22:05:26 +00:00
|
|
|
if (_onRequestClose) {
|
|
|
|
[subview addGestureRecognizer:_menuButtonGestureRecognizer];
|
|
|
|
}
|
|
|
|
#endif
|
2016-02-22 12:43:51 +00:00
|
|
|
subview.autoresizingMask = UIViewAutoresizingFlexibleHeight |
|
|
|
|
UIViewAutoresizingFlexibleWidth;
|
2016-04-20 18:19:37 +00:00
|
|
|
|
|
|
|
[_modalViewController.view insertSubview:subview atIndex:0];
|
|
|
|
_reactSubview = subview;
|
2015-07-28 14:31:26 +00:00
|
|
|
}
|
|
|
|
|
2015-11-14 18:25:00 +00:00
|
|
|
- (void)removeReactSubview:(UIView *)subview
|
2015-07-28 14:31:26 +00:00
|
|
|
{
|
2016-04-20 18:19:37 +00:00
|
|
|
RCTAssert(subview == _reactSubview, @"Cannot remove view other than modal view");
|
2017-08-17 22:05:26 +00:00
|
|
|
// Superclass (category) removes the `subview` from actual `superview`.
|
2016-06-07 07:08:16 +00:00
|
|
|
[super removeReactSubview:subview];
|
2017-01-09 08:09:38 +00:00
|
|
|
[_touchHandler detachFromView:subview];
|
2017-08-17 22:05:26 +00:00
|
|
|
#if TARGET_OS_TV
|
|
|
|
if (_menuButtonGestureRecognizer) {
|
|
|
|
[subview removeGestureRecognizer:_menuButtonGestureRecognizer];
|
|
|
|
}
|
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
|
|
|
for (UIGestureRecognizer *gr in self.tvRemoteHandler.tvRemoteGestureRecognizers) {
|
|
|
|
[subview removeGestureRecognizer:gr];
|
|
|
|
}
|
2017-08-17 22:05:26 +00:00
|
|
|
#endif
|
2016-04-20 18:19:37 +00:00
|
|
|
_reactSubview = nil;
|
2015-07-28 14:31:26 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 07:08:16 +00:00
|
|
|
- (void)didUpdateReactSubviews
|
|
|
|
{
|
|
|
|
// Do nothing, as subview (singular) is managed by `insertReactSubview:atIndex:`
|
|
|
|
}
|
|
|
|
|
2015-10-06 17:09:47 +00:00
|
|
|
- (void)dismissModalViewController
|
|
|
|
{
|
|
|
|
if (_isPresented) {
|
2016-08-23 23:50:23 +00:00
|
|
|
[_delegate dismissModalHostView:self withViewController:_modalViewController animated:[self hasAnimationType]];
|
2015-10-06 17:09:47 +00:00
|
|
|
_isPresented = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-31 00:03:23 +00:00
|
|
|
- (void)didMoveToWindow
|
2015-07-28 14:31:26 +00:00
|
|
|
{
|
2015-10-31 00:03:23 +00:00
|
|
|
[super didMoveToWindow];
|
2015-07-28 14:31:26 +00:00
|
|
|
|
2017-09-25 17:56:16 +00:00
|
|
|
// In the case where there is a LayoutAnimation, we will be reinserted into the view hierarchy but only for aesthetic purposes.
|
|
|
|
// In such a case, we should NOT represent the <Modal>.
|
|
|
|
if (!self.userInteractionEnabled && ![self.superview.reactSubviews containsObject:self]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-31 00:03:23 +00:00
|
|
|
if (!_isPresented && self.window) {
|
2015-08-13 15:27:16 +00:00
|
|
|
RCTAssert(self.reactViewController, @"Can't present modal view controller without a presenting view controller");
|
2016-04-28 22:59:11 +00:00
|
|
|
|
2016-09-27 13:19:45 +00:00
|
|
|
#if !TARGET_OS_TV
|
2016-09-07 13:06:12 +00:00
|
|
|
_modalViewController.supportedInterfaceOrientations = [self supportedOrientationsMask];
|
2016-09-27 13:19:45 +00:00
|
|
|
#endif
|
2016-04-28 22:59:11 +00:00
|
|
|
if ([self.animationType isEqualToString:@"fade"]) {
|
|
|
|
_modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
|
|
} else if ([self.animationType isEqualToString:@"slide"]) {
|
|
|
|
_modalViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
|
|
|
|
}
|
2017-06-21 02:02:27 +00:00
|
|
|
if (self.presentationStyle != UIModalPresentationNone) {
|
|
|
|
_modalViewController.modalPresentationStyle = self.presentationStyle;
|
|
|
|
}
|
2016-08-23 23:50:23 +00:00
|
|
|
[_delegate presentModalHostView:self withViewController:_modalViewController animated:[self hasAnimationType]];
|
2015-10-06 17:09:47 +00:00
|
|
|
_isPresented = YES;
|
2015-10-31 00:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didMoveToSuperview
|
|
|
|
{
|
|
|
|
[super didMoveToSuperview];
|
|
|
|
|
|
|
|
if (_isPresented && !self.superview) {
|
2015-10-06 17:09:47 +00:00
|
|
|
[self dismissModalViewController];
|
2015-07-28 14:31:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-13 16:09:10 +00:00
|
|
|
- (void)invalidate
|
|
|
|
{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2015-10-06 17:09:47 +00:00
|
|
|
[self dismissModalViewController];
|
2015-08-13 16:09:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isTransparent
|
|
|
|
{
|
2016-09-26 22:49:10 +00:00
|
|
|
return _modalViewController.modalPresentationStyle == UIModalPresentationOverFullScreen;
|
2015-08-13 16:09:10 +00:00
|
|
|
}
|
|
|
|
|
2016-04-28 22:59:11 +00:00
|
|
|
- (BOOL)hasAnimationType
|
|
|
|
{
|
|
|
|
return ![self.animationType isEqualToString:@"none"];
|
|
|
|
}
|
|
|
|
|
2015-08-13 16:09:10 +00:00
|
|
|
- (void)setTransparent:(BOOL)transparent
|
|
|
|
{
|
2017-06-21 02:02:27 +00:00
|
|
|
if (self.isTransparent != transparent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-26 22:49:10 +00:00
|
|
|
_modalViewController.modalPresentationStyle = transparent ? UIModalPresentationOverFullScreen : UIModalPresentationFullScreen;
|
2015-08-13 16:09:10 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 13:19:45 +00:00
|
|
|
#if !TARGET_OS_TV
|
2016-09-07 13:06:12 +00:00
|
|
|
- (UIInterfaceOrientationMask)supportedOrientationsMask
|
|
|
|
{
|
|
|
|
if (_supportedOrientations.count == 0) {
|
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
|
|
|
|
return UIInterfaceOrientationMaskAll;
|
|
|
|
} else {
|
|
|
|
return UIInterfaceOrientationMaskPortrait;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UIInterfaceOrientationMask supportedOrientations = 0;
|
|
|
|
for (NSString *orientation in _supportedOrientations) {
|
|
|
|
if ([orientation isEqualToString:@"portrait"]) {
|
|
|
|
supportedOrientations |= UIInterfaceOrientationMaskPortrait;
|
|
|
|
} else if ([orientation isEqualToString:@"portrait-upside-down"]) {
|
|
|
|
supportedOrientations |= UIInterfaceOrientationMaskPortraitUpsideDown;
|
|
|
|
} else if ([orientation isEqualToString:@"landscape"]) {
|
|
|
|
supportedOrientations |= UIInterfaceOrientationMaskLandscape;
|
|
|
|
} else if ([orientation isEqualToString:@"landscape-left"]) {
|
|
|
|
supportedOrientations |= UIInterfaceOrientationMaskLandscapeLeft;
|
|
|
|
} else if ([orientation isEqualToString:@"landscape-right"]) {
|
|
|
|
supportedOrientations |= UIInterfaceOrientationMaskLandscapeRight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return supportedOrientations;
|
|
|
|
}
|
2016-09-27 13:19:45 +00:00
|
|
|
#endif
|
2016-09-07 13:06:12 +00:00
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
@end
|