Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
47b95af
chore(types): added modalDetent type
hurali97 Sep 30, 2022
7dd8ec7
feat(ios): support for modal detent in paper
hurali97 Oct 1, 2022
6c149e4
fix: match the java delegate generated by codegen
hurali97 Oct 1, 2022
c3b6f9b
feat(ios): support for modal detent in fabric
hurali97 Oct 1, 2022
a1d071b
refactor: remove console.log
hurali97 Oct 1, 2022
a4abe50
fix(prettier): fix formatting
hurali97 Oct 1, 2022
5a7a9e2
fix(prettier): fix Modal.d.ts formatting
hurali97 Oct 1, 2022
3bdd88b
refactor(JS): changed type for updated prop detent
hurali97 Oct 3, 2022
639065f
refactor(iOS): changed type for updated prop detent
hurali97 Oct 3, 2022
826d4c9
refactor(android): changed type for updated prop detent
hurali97 Oct 3, 2022
37cc67f
Merge branch 'facebook:main' into feat/ios/modal-detents
hurali97 Oct 5, 2022
aef05d2
refactor: fixed indentation and early exit if nil
hurali97 Oct 5, 2022
4ce436c
Merge branch 'facebook:main' into feat/ios/modal-detents
hurali97 Oct 25, 2022
da2ef72
refactor: changed detents to array type to support custom sized detents
hurali97 Nov 11, 2022
7cc448f
Merge branch 'facebook:main' into feat/ios/modal-detents
hurali97 Nov 11, 2022
5f8c366
Merge branch 'feat/ios/modal-detents' of https://github.com/hurali97/…
hurali97 Nov 11, 2022
1b45c43
Detents WIP
jacobp100 Nov 15, 2022
c615745
Merge branch 'facebook:main' into feat/ios/modal-detents
hurali97 Dec 1, 2022
38acf4a
Merge branch 'facebook:main' into feat/ios/modal-detents
hurali97 Dec 9, 2022
e70f593
Merge branch 'detents-converters' of https://github.com/hurali97/reac…
hurali97 Dec 9, 2022
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
9 changes: 9 additions & 0 deletions Libraries/Modal/Modal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export interface ModalPropsIOS {
| 'overFullScreen'
| undefined;

/**
* The `detents` determines the height for modal,
* based on the detents value.
* It can be a combination of `large`, `medium` or
* any number.
* for eg: ['140', 'medium', 'large']
*/
detents?: Array<string>;

/**
* The `supportedOrientations` prop allows the modal to be rotated to any of the specified orientations.
* On iOS, the modal is still restricted by what's specified in your app's Info.plist's UISupportedInterfaceOrientations field.
Expand Down
9 changes: 9 additions & 0 deletions Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ export type Props = $ReadOnly<{|
| 'overFullScreen'
),

/**
* The `detents` determines the height for modal,
* based on the detents value.
* It can be a combination of `large`, `medium` or
* any number.
* for eg: ['140', 'medium', 'large']
*/
detents?: ?$ReadOnlyArray<string>,
/**
* The `transparent` prop determines whether your modal will fill the
* entire view.
Expand Down Expand Up @@ -246,6 +254,7 @@ class Modal extends React.Component<Props> {

return (
<RCTModalHostView
detents={this.props.detents}
animationType={animationType}
presentationStyle={presentationStyle}
transparent={this.props.transparent}
Expand Down
8 changes: 8 additions & 0 deletions Libraries/Modal/RCTModalHostViewNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ type NativeProps = $ReadOnly<{|
'fullScreen',
>,

/**
* The `detents` determines the height for modal,
* based on the detents value.
* It can be a combination of `large`, `medium` or
* any number.
* for eg: ['140', 'medium', 'large']
*/
detents?: ?$ReadOnlyArray<string>,
/**
* The `transparent` prop determines whether your modal will fill the
* entire view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@property (nonatomic, weak) id<RCTFabricModalHostViewControllerDelegate> delegate;

@property (nonatomic, copy) NSArray *detents;
@property (nonatomic, assign) UIInterfaceOrientationMask supportedInterfaceOrientations;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* UIView class for root <ModalHostView> component.
*/
@interface RCTModalHostViewComponentView : RCTViewComponentView <RCTMountingTransactionObserving>
@interface RCTModalHostViewComponentView : RCTViewComponentView <RCTMountingTransactionObserving, UIAdaptivePresentationControllerDelegate>

/**
* Subclasses may override this method and present the modal on different view controller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ - (void)ensurePresentedOnlyIfNeeded
BOOL shouldBePresented = !_isPresented && _shouldPresent && self.window;
if (shouldBePresented) {
_isPresented = YES;
if (@available(iOS 13.0, *)) {
_viewController.presentationController.delegate = self;
}
// if (@available(iOS 15.0, *)) {
// UISheetPresentationController *sheetPresentationController =
// _viewController.sheetPresentationController;
//
// if (sheetPresentationController && self.detents != nil) {
// NSArray<UISheetPresentationControllerDetent *> *detents = self.detents != nil
// ? [RCTConvert UISheetPresentationControllerDetentArray:self.detents]
// // The default value is an array that contains the value largeDetent
// : @[[UISheetPresentationControllerDetent largeDetent]];
// sheetPresentationController.detents = detents;
// sheetPresentationController.prefersGrabberVisible = detents.count > 1;
// }
// }
[self presentViewController:self.viewController
animated:_shouldAnimatePresentation
completion:^{
Expand Down Expand Up @@ -227,6 +243,14 @@ - (void)boundsDidChange:(CGRect)newBounds
}
}

- (void)presentationControllerDidAttemptToDismiss:(UIPresentationController *)controller
{
auto eventEmitter = [self modalEventEmitter];
if (eventEmitter) {
eventEmitter->onRequestClose(ModalHostViewEventEmitter::OnRequestClose{});
}
}

#pragma mark - RCTComponentViewProtocol

+ (ComponentDescriptorProvider)componentDescriptorProvider
Expand Down Expand Up @@ -257,6 +281,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &

self.viewController.modalPresentationStyle = presentationConfiguration(newProps);

self.viewController.detents = @[];

_shouldPresent = newProps.visible;
[self ensurePresentedOnlyIfNeeded];

Expand Down
17 changes: 17 additions & 0 deletions React/Views/RCTConvert+Modal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* 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/RCTConvert.h>

@interface RCTConvert (Modal)

+ (UISheetPresentationControllerDetent *)UISheetPresentationControllerDetent:(id)json API_AVAILABLE(ios(15.0));
+ (NSArray<UISheetPresentationControllerDetent *> *)UISheetPresentationControllerDetentArray:(id)json API_AVAILABLE(ios(15.0));

@end
33 changes: 33 additions & 0 deletions React/Views/RCTConvert+Modal.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import "RCTConvert+Modal.h"

@implementation RCTConvert (Modal)

+ (UISheetPresentationControllerDetent *)UISheetPresentationControllerDetent:(id)json {
if (@available(iOS 16.0, *)) {
if ([json isKindOfClass:[NSNumber class]]) {
float value = [json floatValue];
return [UISheetPresentationControllerDetent
customDetentWithIdentifier:nil
resolver:^CGFloat(id context) {
return value;
}];
}
}

if ([json isEqualToString:@"medium"]) {
return [UISheetPresentationControllerDetent mediumDetent];
}

return [UISheetPresentationControllerDetent largeDetent];
}

RCT_ARRAY_CONVERTER(UISheetPresentationControllerDetent)

@end
1 change: 1 addition & 0 deletions React/Views/RCTModalHostView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@property (nonatomic, copy) NSString *animationType;
@property (nonatomic, assign) UIModalPresentationStyle presentationStyle;
@property (nonatomic, assign) id detents;
@property (nonatomic, assign, getter=isTransparent) BOOL transparent;

@property (nonatomic, copy) RCTDirectEventBlock onShow;
Expand Down
14 changes: 14 additions & 0 deletions React/Views/RCTModalHostView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "RCTUIManager.h"
#import "RCTUtils.h"
#import "UIView+React.h"
#import "RCTConvert+Modal.h"

@implementation RCTModalHostView {
__weak RCTBridge *_bridge;
Expand Down Expand Up @@ -185,6 +186,19 @@ - (void)ensurePresentedOnlyIfNeeded
if (@available(iOS 13.0, *)) {
_modalViewController.presentationController.delegate = self;
}
if (@available(iOS 15.0, *)) {
UISheetPresentationController *sheetPresentationController =
_modalViewController.sheetPresentationController;

if (sheetPresentationController && self.detents != nil) {
NSArray<UISheetPresentationControllerDetent *> *detents = self.detents != nil
? [RCTConvert UISheetPresentationControllerDetentArray:self.detents]
// The default value is an array that contains the value largeDetent
: @[[UISheetPresentationControllerDetent largeDetent]];
sheetPresentationController.detents = detents;
sheetPresentationController.prefersGrabberVisible = detents.count > 1;
}
}
[_delegate presentModalHostView:self withViewController:_modalViewController animated:[self hasAnimationType]];
_isPresented = YES;
}
Expand Down
1 change: 1 addition & 0 deletions React/Views/RCTModalHostViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ - (void)invalidate
RCT_EXPORT_VIEW_PROPERTY(onOrientationChange, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(visible, BOOL)
RCT_EXPORT_VIEW_PROPERTY(onRequestClose, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(detents, NSArray)

// Fabric only
RCT_EXPORT_VIEW_PROPERTY(onDismiss, RCTDirectEventBlock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public void setVisible(ReactModalHostView view, boolean visible) {
@ReactProp(name = "presentationStyle")
public void setPresentationStyle(ReactModalHostView view, @Nullable String value) {}

@Override
@ReactProp(name = "detent")
public void setDetent(ReactModalHostView view, @Nullable String value) {
// iOS only
}

@Override
@ReactProp(name = "animated")
public void setAnimated(ReactModalHostView view, boolean value) {}
Expand Down