Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
{
UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, YES);

#if TARGET_OS_TV
rootView.backgroundColor = [UIColor clearColor];
#else
rootView.backgroundColor = [UIColor systemBackgroundColor];
#endif

return rootView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView =
[[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface];

#if TARGET_OS_TV
surfaceHostingProxyRootView.backgroundColor = [UIColor clearColor];
#else
surfaceHostingProxyRootView.backgroundColor = [UIColor systemBackgroundColor];
#endif
if (_configuration.customizeRootView != nil) {
_configuration.customizeRootView(surfaceHostingProxyRootView);
}
Expand All @@ -207,7 +211,11 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
initProps:(NSDictionary *)initProps
{
UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, YES);
#if !TARGET_OS_TV
rootView.backgroundColor = [UIColor systemBackgroundColor];
#else
rootView.backgroundColor = [UIColor blackColor];
#endif
return rootView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ @implementation RCTUITextView {
NSArray<UIBarButtonItemGroup *> *_initialValueLeadingBarButtonGroups;
NSArray<UIBarButtonItemGroup *> *_initialValueTrailingBarButtonGroups;
NSArray<NSString *> *_acceptDragAndDropTypes;
BOOL _disableKeyboardShortcuts;
}

static UIFont *defaultPlaceholderFont(void)
Expand Down Expand Up @@ -53,7 +54,9 @@ - (instancetype)initWithFrame:(CGRect)frame
self.textColor = [UIColor blackColor];
// This line actually removes 5pt (default value) left and right padding in UITextView.
self.textContainer.lineFragmentPadding = 0;
#if !TARGET_OS_TV
self.scrollsToTop = NO;
#endif
self.scrollEnabled = YES;
_initialValueLeadingBarButtonGroups = nil;
_initialValueTrailingBarButtonGroups = nil;
Expand Down Expand Up @@ -149,6 +152,7 @@ - (void)textDidChange

- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
{
_disableKeyboardShortcuts = disableKeyboardShortcuts;
#if TARGET_OS_IOS
// Initialize the initial values only once
if (_initialValueLeadingBarButtonGroups == nil) {
Expand All @@ -165,10 +169,14 @@ - (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
self.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups;
self.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups;
}
_disableKeyboardShortcuts = disableKeyboardShortcuts;
#endif
}

- (BOOL)disableKeyboardShortcuts
{
return _disableKeyboardShortcuts;
}

#pragma mark - Overrides

- (void)setFont:(UIFont *)font
Expand Down Expand Up @@ -306,7 +314,7 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender

- (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder
{
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 && !TARGET_OS_TV
if (@available(iOS 17.0, *)) {
if (_contextMenuHidden) {
[builder removeMenuForIdentifier:UIMenuAutoFill];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@

static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingContext;

@interface RCTBackedTextFieldDelegateAdapter () <UITextFieldDelegate, UITextDropDelegate>
@interface RCTBackedTextFieldDelegateAdapter () <
UITextFieldDelegate
#if !TARGET_OS_TV
,
UITextDropDelegate
#endif
>
@end

@implementation RCTBackedTextFieldDelegateAdapter {
Expand All @@ -25,7 +31,9 @@ - (instancetype)initWithTextField:(UITextField<RCTBackedTextInputViewProtocol> *
if (self = [super init]) {
_backedTextInputView = backedTextInputView;
backedTextInputView.delegate = self;
#if !TARGET_OS_TV
backedTextInputView.textDropDelegate = self;
#endif

[_backedTextInputView addTarget:self
action:@selector(textFieldDidChange)
Expand Down Expand Up @@ -160,6 +168,8 @@ - (void)textFieldProbablyDidChangeSelection
[_backedTextInputView.textInputDelegate textInputDidChangeSelection];
}

#if !TARGET_OS_TV

#pragma mark - UITextDropDelegate

- (UITextDropEditability)textDroppableView:(UIView<UITextDroppable> *)textDroppableView
Expand Down Expand Up @@ -196,11 +206,19 @@ - (bool)_shouldAcceptDrop:(id<UITextDropRequest>)drop
}
}

#endif

@end

#pragma mark - RCTBackedTextViewDelegateAdapter (for UITextView)

@interface RCTBackedTextViewDelegateAdapter () <UITextViewDelegate, UITextDropDelegate>
@interface RCTBackedTextViewDelegateAdapter () <
UITextViewDelegate
#if !TARGET_OS_TV
,
UITextDropDelegate
#endif
>
@end

@implementation RCTBackedTextViewDelegateAdapter {
Expand All @@ -216,7 +234,9 @@ - (instancetype)initWithTextView:(UITextView<RCTBackedTextInputViewProtocol> *)b
if (self = [super init]) {
_backedTextInputView = backedTextInputView;
backedTextInputView.delegate = self;
#if !TARGET_OS_TV
backedTextInputView.textDropDelegate = self;
#endif
}

return self;
Expand Down Expand Up @@ -342,6 +362,8 @@ - (void)textViewProbablyDidChangeSelection
[_backedTextInputView.textInputDelegate textInputDidChangeSelection];
}

#if !TARGET_OS_TV

#pragma mark - UITextDropDelegate

- (UITextDropEditability)textDroppableView:(UIView<UITextDroppable> *)textDroppableView
Expand Down Expand Up @@ -378,4 +400,6 @@ - (bool)_shouldAcceptDrop:(id<UITextDropRequest>)drop
}
}

#endif

@end
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ - (void)setSecureTextEntry:(BOOL)secureTextEntry

- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
{
_disableKeyboardShortcuts = disableKeyboardShortcuts;
#if TARGET_OS_IOS
// Initialize the initial values only once
if (_initialValueLeadingBarButtonGroups == nil) {
Expand All @@ -152,7 +153,6 @@ - (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
self.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups;
self.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups;
}
_disableKeyboardShortcuts = disableKeyboardShortcuts;
#endif
}

Expand Down Expand Up @@ -186,7 +186,7 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
- (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder
{
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000
if (@available(iOS 17.0, *)) {
if (@available(iOS 17.0, tvOS 17.0, *)) {
if (_contextMenuHidden) {
[builder removeMenuForIdentifier:UIMenuAutoFill];
}
Expand Down
6 changes: 6 additions & 0 deletions packages/react-native/React/Base/RCTConvert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC
return type;
}

#if !TARGET_OS_TV
RCT_MULTI_ENUM_CONVERTER(
UIDataDetectorTypes,
(@{
Expand All @@ -460,6 +461,7 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC
}),
UIDataDetectorTypePhoneNumber,
unsignedLongLongValue)
#endif

RCT_ENUM_CONVERTER(
UIKeyboardAppearance,
Expand Down Expand Up @@ -517,8 +519,12 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC
UIModalPresentationStyle,
(@{
@"fullScreen" : @(UIModalPresentationFullScreen),
#if !TARGET_OS_TV
@"pageSheet" : @(UIModalPresentationPageSheet),
#endif
#if !TARGET_OS_TV || __TV_OS_VERSION_MIN_REQUIRED >= 260000
@"formSheet" : @(UIModalPresentationFormSheet),
#endif
@"overFullScreen" : @(UIModalPresentationOverFullScreen),
}),
UIModalPresentationFullScreen,
Expand Down
9 changes: 9 additions & 0 deletions packages/react-native/React/Base/RCTUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
BOOL RCTIsHomeAssetURL(NSURL *__nullable imageURL);

// Returns the current device's orientation
#if !TARGET_OS_TV
UIDeviceOrientation RCTDeviceOrientation(void);
#endif

// Whether the New Architecture is enabled or not
BOOL RCTIsNewArchEnabled(void)
Expand Down Expand Up @@ -381,10 +383,12 @@ CGFloat RCTFontSizeMultiplier(void)
return mapping[RCTSharedApplication().preferredContentSizeCategory].floatValue;
}

#if !TARGET_OS_TV
UIDeviceOrientation RCTDeviceOrientation(void)
{
return [[UIDevice currentDevice] orientation];
}
#endif

CGSize RCTScreenSize(void)
{
Expand All @@ -397,11 +401,16 @@ CGSize RCTScreenSize(void)
});
});

#if !TARGET_OS_TV
if (UIDeviceOrientationIsLandscape(RCTDeviceOrientation())) {
return CGSizeMake(portraitSize.height, portraitSize.width);
} else {
return CGSizeMake(portraitSize.width, portraitSize.height);
}
#else
// tvOS doesn't have device orientation, always return landscape size
return CGSizeMake(portraitSize.height, portraitSize.width);
#endif
}

CGSize RCTViewportSize(void)
Expand Down
7 changes: 5 additions & 2 deletions packages/react-native/React/CoreModules/RCTDeviceInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ @interface RCTDeviceInfo () <NativeDeviceInfoSpec, RCTInitializing, RCTInvalidat
@end

@implementation RCTDeviceInfo {
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
UIInterfaceOrientation _currentInterfaceOrientation;
#endif
NSDictionary *_currentInterfaceDimensions;
BOOL _isFullscreen;
std::atomic<BOOL> _invalidated;
Expand Down Expand Up @@ -103,10 +105,11 @@ - (void)initialize
name:UIApplicationDidBecomeActiveNotification
object:nil];

#if TARGET_OS_IOS

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
_currentInterfaceOrientation = RCTKeyWindow().windowScene.interfaceOrientation;
#endif

#if TARGET_OS_IOS
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(interfaceFrameDidChange)
name:UIDeviceOrientationDidChangeNotification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using namespace facebook::react;

#if !TARGET_OS_TV
static UIInterfaceOrientationMask supportedOrientationsMask(ModalHostViewSupportedOrientationsMask mask)
{
UIInterfaceOrientationMask supportedOrientations = 0;
Expand Down Expand Up @@ -55,6 +56,7 @@ static UIInterfaceOrientationMask supportedOrientationsMask(ModalHostViewSupport

return supportedOrientations;
}
#endif

static std::tuple<BOOL, UIModalTransitionStyle> animationConfiguration(const ModalHostViewAnimationType animation)
{
Expand All @@ -77,9 +79,21 @@ static UIModalPresentationStyle presentationConfiguration(const ModalHostViewPro
case ModalHostViewPresentationStyle::FullScreen:
return UIModalPresentationFullScreen;
case ModalHostViewPresentationStyle::PageSheet:
#if !TARGET_OS_TV
return UIModalPresentationPageSheet;
#else
return UIModalPresentationFullScreen;
#endif
case ModalHostViewPresentationStyle::FormSheet:
#if TARGET_OS_TV
if (@available(tvOS 26.0, *)) {
return UIModalPresentationFormSheet;
} else {
return UIModalPresentationFullScreen;
}
#else
return UIModalPresentationFormSheet;
#endif
case ModalHostViewPresentationStyle::OverFullScreen:
return UIModalPresentationOverFullScreen;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@

@interface RCTTextInputComponentView () <
RCTBackedTextInputDelegate,
RCTTextInputViewProtocol,
UIDropInteractionDelegate>
RCTTextInputViewProtocol
#if !TARGET_OS_TV
,
UIDropInteractionDelegate
#endif
>
@end

static NSSet<NSNumber *> *returnKeyTypesSet;
Expand Down Expand Up @@ -211,11 +215,13 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
_backedTextInputView.editable = newTextInputProps.traits.editable;
}

#if !TARGET_OS_TV
if (newTextInputProps.multiline &&
newTextInputProps.traits.dataDetectorTypes != oldTextInputProps.traits.dataDetectorTypes) {
_backedTextInputView.dataDetectorTypes =
RCTUITextViewDataDetectorTypesFromStringVector(newTextInputProps.traits.dataDetectorTypes);
}
#endif

if (newTextInputProps.traits.enablesReturnKeyAutomatically !=
oldTextInputProps.traits.enablesReturnKeyAutomatically) {
Expand Down Expand Up @@ -665,6 +671,7 @@ - (void)setDefaultInputAccessoryView

_hasInputAccessoryView = shouldHaveInputAccessoryView;

#if !TARGET_OS_TV
if (shouldHaveInputAccessoryView) {
NSString *buttonLabel = inputAccessoryViewButtonLabel != nil ? inputAccessoryViewButtonLabel
: [self returnKeyTypeToString:returnKeyType];
Expand All @@ -682,6 +689,7 @@ - (void)setDefaultInputAccessoryView
} else {
_backedTextInputView.inputAccessoryView = nil;
}
#endif

if (_backedTextInputView.isFirstResponder) {
[_backedTextInputView reloadInputViews];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ UITextInputPasswordRules *RCTUITextInputPasswordRulesFromString(const std::strin

UITextSmartInsertDeleteType RCTUITextSmartInsertDeleteTypeFromOptionalBool(std::optional<bool> smartInsertDelete);

#if !TARGET_OS_TV
UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::vector<std::string> &dataDetectorTypes);
#endif

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ UITextContentType RCTUITextContentTypeFromString(const std::string &contentType)
}

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */
if (@available(iOS 17.0, *)) {
if (@available(iOS 17.0, tvOS 17.0, *)) {
[mutableContentTypeMap addEntriesFromDictionary:@{
@"creditCardExpiration" : UITextContentTypeCreditCardExpiration,
@"creditCardExpirationMonth" : UITextContentTypeCreditCardExpirationMonth,
Expand Down Expand Up @@ -271,6 +271,7 @@ UITextSmartInsertDeleteType RCTUITextSmartInsertDeleteTypeFromOptionalBool(std::
: UITextSmartInsertDeleteTypeDefault;
}

#if !TARGET_OS_TV
UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::vector<std::string> &dataDetectorTypes)
{
static dispatch_once_t onceToken;
Expand Down Expand Up @@ -298,3 +299,4 @@ UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::ve
}
return ret;
}
#endif
Loading
Loading