-
-
Notifications
You must be signed in to change notification settings - Fork 670
refactor(iOS, FormSheet v5): Move AppearanceCoordinator/Applicator to ContentController #4074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
8742fff
529e7b1
06be498
33ede2c
c6b9efe
414255e
9022290
1fb8840
e6c5928
abbef2d
c56b89c
fa5861a
579fffb
c18345f
c5473d9
dc3f9ac
a8a43b2
6fd75c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
| #import "RNSFormSheetProviders.h" | ||
|
|
||
| @class RNSFormSheetAppearanceCoordinator; | ||
| @class RNSFormSheetContentController; | ||
|
|
@@ -10,9 +11,10 @@ NS_ASSUME_NONNULL_BEGIN | |
|
|
||
| @interface RNSFormSheetAppearanceApplicator : NSObject | ||
|
|
||
| - (void)updateAppearanceIfNeededForHost:(RNSFormSheetHostComponentView *)host | ||
| controller:(RNSFormSheetContentController *)controller | ||
| coordinator:(RNSFormSheetAppearanceCoordinator *)coordinator; | ||
| - (void)updateAppearanceIfNeededForAppearanceProvider:(id<RNSFormSheetAppearanceProvider>)appearanceProvider | ||
| behaviorProvider:(id<RNSFormSheetBehaviorProvider>)behaviorProvider | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: behavior will have a dedicated path, but I'm extracting it to a separate PR in which I'm going to introduce a dedicated class for that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. associated followup PR: #4084 |
||
| controller:(RNSFormSheetContentController *)controller | ||
| coordinator:(RNSFormSheetAppearanceCoordinator *)coordinator; | ||
|
|
||
| - (void)resetInitialDetent; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| #import "RNSFormSheetContentController.h" | ||
| #import "RNSFormSheetAppearanceApplicator.h" | ||
| #import "RNSFormSheetAppearanceCoordinator.h" | ||
| #import "RNSFormSheetAppearanceUpdateFlags.h" | ||
| #import "RNSFormSheetContentView.h" | ||
| #import "RNSFormSheetHostComponentView.h" | ||
|
t0maboro marked this conversation as resolved.
Outdated
|
||
| #import "RNSPresentationSourceProvider.h" | ||
|
|
||
| #import <React/RCTAssert.h> | ||
|
|
@@ -13,12 +17,22 @@ @interface RNSFormSheetContentController () <UIAdaptivePresentationControllerDel | |
| > | ||
| @end | ||
|
|
||
| @implementation RNSFormSheetContentController | ||
| @implementation RNSFormSheetContentController { | ||
| RNSFormSheetAppearanceCoordinator *_Nonnull _appearanceCoordinator; | ||
| RNSFormSheetAppearanceApplicator *_Nonnull _appearanceApplicator; | ||
|
|
||
| BOOL _needsInitialDetentReset; | ||
| } | ||
|
|
||
| - (instancetype)init | ||
| { | ||
| if (self = [super init]) { | ||
| self.modalPresentationStyle = UIModalPresentationFormSheet; | ||
|
|
||
| _appearanceCoordinator = [RNSFormSheetAppearanceCoordinator new]; | ||
| _appearanceApplicator = [RNSFormSheetAppearanceApplicator new]; | ||
|
|
||
| _needsInitialDetentReset = NO; | ||
| } | ||
| return self; | ||
| } | ||
|
|
@@ -46,6 +60,27 @@ - (void)viewDidLayoutSubviews | |
|
|
||
| #pragma mark - Presentation | ||
|
|
||
| - (void)updatePresentationState | ||
| { | ||
| id<RNSFormSheetPresentationProvider> presentationProvider = self.presentationProvider; | ||
|
|
||
| RCTAssert(presentationProvider != nil, | ||
| @"[RNScreens] Presentation provider must be set before updating presentation state."); | ||
|
|
||
| if (presentationProvider == nil) { | ||
| return; | ||
| } | ||
|
|
||
| if (presentationProvider.isOpen) { | ||
| UIWindow *window = presentationProvider.hostWindow; | ||
| if (window != nil) { | ||
| [self presentFromWindowIfNeeded:window]; | ||
| } | ||
| } else { | ||
| [self dismissIfNeeded]; | ||
| } | ||
| } | ||
|
|
||
| - (void)prepareForPresentation | ||
| { | ||
| // The presentation controller is recreated by UIKit on every present/dismiss cycle. | ||
|
|
@@ -88,6 +123,62 @@ - (void)dismissIfNeeded | |
| [self dismissViewControllerAnimated:YES completion:nil]; | ||
| } | ||
|
|
||
| #pragma mark - Appearance | ||
|
|
||
| - (void)updateAppearanceIfNeeded | ||
| { | ||
| id<RNSFormSheetAppearanceProvider> appearanceProvider = self.appearanceProvider; | ||
| id<RNSFormSheetBehaviorProvider> behaviorProvider = self.behaviorProvider; | ||
|
|
||
| RCTAssert(appearanceProvider != nil, @"[RNScreens] Appearance provider must be set before updating appearance."); | ||
|
|
||
| RCTAssert(behaviorProvider != nil, @"[RNScreens] Behavior provider must be set before updating appearance."); | ||
|
|
||
| if (appearanceProvider == nil || behaviorProvider == nil) { | ||
| return; | ||
| } | ||
|
|
||
| if (_needsInitialDetentReset) { | ||
| _needsInitialDetentReset = NO; | ||
| [_appearanceApplicator resetInitialDetent]; | ||
| } | ||
|
Comment on lines
+140
to
+143
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do my first reading & don't understand the code fully yet, but detent update in appearance method doesn't fit for me. Aren't detents rather a behaviour? Thinking now. Maybe call it configuration or something and then have both detents and appearance here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right, there are a few things I don't like here:
my current plan is to:
let me know if you're okay with that |
||
|
|
||
| [_appearanceApplicator updateAppearanceIfNeededForAppearanceProvider:appearanceProvider | ||
| behaviorProvider:behaviorProvider | ||
| controller:self | ||
| coordinator:_appearanceCoordinator]; | ||
|
|
||
| // TODO: @t0maboro - decouple presentation logic from AppearanceCoordinator | ||
| [_appearanceCoordinator updateIfNeeds:RNSFormSheetAppearanceUpdateFlagsPresentation | ||
| performOperations:^{ | ||
| [self updatePresentationState]; | ||
| }]; | ||
| } | ||
|
|
||
| #pragma mark - Signals | ||
|
|
||
| - (void)setNeedsPresentationUpdate | ||
| { | ||
| [_appearanceCoordinator setNeeds:RNSFormSheetAppearanceUpdateFlagsPresentation]; | ||
| } | ||
|
|
||
| - (void)setNeedsAppearanceUpdate | ||
| { | ||
| [_appearanceCoordinator setNeeds:RNSFormSheetAppearanceUpdateFlagsConfiguration]; | ||
| } | ||
|
|
||
| - (void)setNeedsInitialDetentReset | ||
| { | ||
| _needsInitialDetentReset = YES; | ||
| } | ||
|
|
||
| #pragma mark - Updating | ||
|
|
||
| - (void)flushPendingUpdates | ||
| { | ||
| [self updateAppearanceIfNeeded]; | ||
| } | ||
|
|
||
| #pragma mark - UIAdaptivePresentationControllerDelegate | ||
|
|
||
| - (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one remark regarding naming.
The
Forpart does sound inappropriate and misleading in this context.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c5473d9