mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
2160377574
Summary: Refs: [0.62 release](https://reactnative.dev/blog/#moving-apple-tv-to-react-native-tvos), https://github.com/facebook/react-native/issues/28706, https://github.com/facebook/react-native/issues/28743, https://github.com/facebook/react-native/issues/29018 This PR removes most of the tvOS remnants in the code. Most of the changes are related to the tvOS platform removal from `.podspec` files, tvOS specific conditionals removal (Obj-C + JS) or tvOS CI/testing pipeline related code. In addition to the changes listed above I have removed the deprecated `Platform.isTVOS` method. I'm not sure how `Platform.isTV` method is correlated with Android TV devices support which is technically not deprecated in the core so I left this method untouched for now. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> * **[Internal] [Removed]** - remove most of tvOS remnants from the code: * `TVEventHandler`, `TVTouchable`, `RCTTVView`, `RCTTVRemoteHandler` and `RCTTVNavigationEventEmitter` * **[Internal] [Removed]** - remove `TARGET_TV_OS` flag and all the usages * **[iOS] [Removed]** - remove deprecated `Platform.isTVOS` method * **[iOS] [Removed]** - remove deprecated and TV related props from View: * `isTVSelectable`, `hasTVPreferredFocus` and `tvParallaxProperties` * **[iOS] [Removed]** - remove `BackHandler` utility implementation Pull Request resolved: https://github.com/facebook/react-native/pull/29407 Test Plan: Local tests (and iOS CI run) do not yield any errors, but I'm not sure how the CI pipeline would react to those changes. That is the reason why this PR is being posted as Draft. Some tweaks and code adjustment could be required. Reviewed By: PeteTheHeat Differential Revision: D22619441 Pulled By: shergin fbshipit-source-id: 9aaf3840c5e8bd469c2cfcfa7c5b441ef71b30b6
207 lines
6.3 KiB
Plaintext
207 lines
6.3 KiB
Plaintext
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTDeviceInfo.h"
|
|
|
|
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
|
#import <React/RCTAccessibilityManager.h>
|
|
#import <React/RCTAssert.h>
|
|
#import <React/RCTConstants.h>
|
|
#import <React/RCTEventDispatcher.h>
|
|
#import <React/RCTUIUtils.h>
|
|
#import <React/RCTUtils.h>
|
|
|
|
#import "CoreModulesPlugins.h"
|
|
|
|
using namespace facebook::react;
|
|
|
|
@interface RCTDeviceInfo () <NativeDeviceInfoSpec>
|
|
@end
|
|
|
|
@implementation RCTDeviceInfo {
|
|
UIInterfaceOrientation _currentInterfaceOrientation;
|
|
NSDictionary *_currentInterfaceDimensions;
|
|
}
|
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
{
|
|
return YES;
|
|
}
|
|
|
|
- (dispatch_queue_t)methodQueue
|
|
{
|
|
return dispatch_get_main_queue();
|
|
}
|
|
|
|
- (void)setBridge:(RCTBridge *)bridge
|
|
{
|
|
_bridge = bridge;
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(didReceiveNewContentSizeMultiplier)
|
|
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
|
|
object:_bridge.accessibilityManager];
|
|
|
|
_currentInterfaceOrientation = [RCTSharedApplication() statusBarOrientation];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(interfaceOrientationDidChange)
|
|
name:UIApplicationDidChangeStatusBarOrientationNotification
|
|
object:nil];
|
|
|
|
_currentInterfaceDimensions = RCTExportedDimensions(_bridge);
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(interfaceFrameDidChange)
|
|
name:UIApplicationDidBecomeActiveNotification
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(interfaceFrameDidChange)
|
|
name:RCTUserInterfaceStyleDidChangeNotification
|
|
object:nil];
|
|
}
|
|
|
|
static BOOL RCTIsIPhoneX()
|
|
{
|
|
static BOOL isIPhoneX = NO;
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
RCTAssertMainQueue();
|
|
|
|
CGSize screenSize = [UIScreen mainScreen].nativeBounds.size;
|
|
CGSize iPhoneXScreenSize = CGSizeMake(1125, 2436);
|
|
CGSize iPhoneXMaxScreenSize = CGSizeMake(1242, 2688);
|
|
CGSize iPhoneXRScreenSize = CGSizeMake(828, 1792);
|
|
|
|
isIPhoneX = CGSizeEqualToSize(screenSize, iPhoneXScreenSize) ||
|
|
CGSizeEqualToSize(screenSize, iPhoneXMaxScreenSize) || CGSizeEqualToSize(screenSize, iPhoneXRScreenSize);
|
|
});
|
|
|
|
return isIPhoneX;
|
|
}
|
|
|
|
static NSDictionary *RCTExportedDimensions(RCTBridge *bridge)
|
|
{
|
|
RCTAssertMainQueue();
|
|
RCTDimensions dimensions = RCTGetDimensions(bridge.accessibilityManager.multiplier);
|
|
__typeof(dimensions.window) window = dimensions.window;
|
|
NSDictionary<NSString *, NSNumber *> *dimsWindow = @{
|
|
@"width" : @(window.width),
|
|
@"height" : @(window.height),
|
|
@"scale" : @(window.scale),
|
|
@"fontScale" : @(window.fontScale)
|
|
};
|
|
__typeof(dimensions.screen) screen = dimensions.screen;
|
|
NSDictionary<NSString *, NSNumber *> *dimsScreen = @{
|
|
@"width" : @(screen.width),
|
|
@"height" : @(screen.height),
|
|
@"scale" : @(screen.scale),
|
|
@"fontScale" : @(screen.fontScale)
|
|
};
|
|
return @{@"window" : dimsWindow, @"screen" : dimsScreen};
|
|
}
|
|
|
|
- (NSDictionary<NSString *, id> *)constantsToExport
|
|
{
|
|
return [self getConstants];
|
|
}
|
|
|
|
- (NSDictionary<NSString *, id> *)getConstants
|
|
{
|
|
__block NSDictionary<NSString *, id> *constants;
|
|
RCTUnsafeExecuteOnMainQueueSync(^{
|
|
constants = @{
|
|
@"Dimensions" : RCTExportedDimensions(self->_bridge),
|
|
// Note:
|
|
// This prop is deprecated and will be removed in a future release.
|
|
// Please use this only for a quick and temporary solution.
|
|
// Use <SafeAreaView> instead.
|
|
@"isIPhoneX_deprecated" : @(RCTIsIPhoneX()),
|
|
};
|
|
});
|
|
|
|
return constants;
|
|
}
|
|
|
|
- (void)didReceiveNewContentSizeMultiplier
|
|
{
|
|
RCTBridge *bridge = _bridge;
|
|
RCTExecuteOnMainQueue(^{
|
|
// Report the event across the bridge.
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
[bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions" body:RCTExportedDimensions(bridge)];
|
|
#pragma clang diagnostic pop
|
|
});
|
|
}
|
|
|
|
- (void)interfaceOrientationDidChange
|
|
{
|
|
__weak __typeof(self) weakSelf = self;
|
|
RCTExecuteOnMainQueue(^{
|
|
[weakSelf _interfaceOrientationDidChange];
|
|
});
|
|
}
|
|
|
|
- (void)_interfaceOrientationDidChange
|
|
{
|
|
UIInterfaceOrientation nextOrientation = [RCTSharedApplication() statusBarOrientation];
|
|
|
|
// Update when we go from portrait to landscape, or landscape to portrait
|
|
if ((UIInterfaceOrientationIsPortrait(_currentInterfaceOrientation) &&
|
|
!UIInterfaceOrientationIsPortrait(nextOrientation)) ||
|
|
(UIInterfaceOrientationIsLandscape(_currentInterfaceOrientation) &&
|
|
!UIInterfaceOrientationIsLandscape(nextOrientation))) {
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions" body:RCTExportedDimensions(_bridge)];
|
|
#pragma clang diagnostic pop
|
|
}
|
|
|
|
_currentInterfaceOrientation = nextOrientation;
|
|
}
|
|
|
|
- (void)interfaceFrameDidChange
|
|
{
|
|
__weak __typeof(self) weakSelf = self;
|
|
RCTExecuteOnMainQueue(^{
|
|
[weakSelf _interfaceFrameDidChange];
|
|
});
|
|
}
|
|
|
|
- (void)_interfaceFrameDidChange
|
|
{
|
|
NSDictionary *nextInterfaceDimensions = RCTExportedDimensions(_bridge);
|
|
|
|
if (!([nextInterfaceDimensions isEqual:_currentInterfaceDimensions])) {
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions" body:nextInterfaceDimensions];
|
|
#pragma clang diagnostic pop
|
|
}
|
|
|
|
_currentInterfaceDimensions = nextInterfaceDimensions;
|
|
}
|
|
|
|
- (std::shared_ptr<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params
|
|
{
|
|
return std::make_shared<NativeDeviceInfoSpecJSI>(params);
|
|
}
|
|
|
|
@end
|
|
|
|
Class RCTDeviceInfoCls(void)
|
|
{
|
|
return RCTDeviceInfo.class;
|
|
}
|