Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 662202896
  • Loading branch information
Nobody authored and material-automation committed Aug 12, 2024
1 parent 2b5aeb9 commit 142d22b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
5 changes: 3 additions & 2 deletions components/BottomSheet/src/private/MDCSheetContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#import "MDCDraggableViewDelegate.h"
#import "MDCSheetBehavior.h"
#import "MDCSheetContainerViewDelegate.h"
#import "MaterialKeyboardWatcher.h"
#import "MDCKeyboardWatcher.h"

/** KVO key for monitoring the content size for the content view if it is a scrollview. */
static NSString *kContentSizeKey = nil;
Expand Down Expand Up @@ -103,11 +103,12 @@ - (instancetype)initWithFrame:(CGRect)frame
forKeyPath:kContentInsetKey
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:kObservingContext];
#if !TARGET_OS_VISION
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(voiceOverStatusDidChange)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];

#endif
// Add the keyboard notifications.
NSArray *notificationNames = @[
MDCKeyboardWatcherKeyboardWillShowNotification,
Expand Down
15 changes: 12 additions & 3 deletions components/Snackbar/src/MDCSnackbarManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,11 @@ - (MDCSnackbarOverlayView *)overlayView {
if (!_overlayView) {
// Only initialize on the main thread.
NSAssert([NSThread isMainThread], @"Method is not called on main thread.");

#if !TARGET_OS_VISION
_overlayView = [[MDCSnackbarOverlayView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
#else
_overlayView = [[MDCSnackbarOverlayView alloc] initWithFrame:CGRectZero];
#endif // TODO: b/359236816 - fix visionOS-specific compatibility workarounds.
}
return _overlayView;
}
Expand Down Expand Up @@ -473,17 +476,23 @@ - (UIWindow *)bestGuessWindow {
return [_windowScene keyWindow];
}
}
#if !TARGET_OS_VISION
return [[UIApplication mdc_safeSharedApplication] keyWindow];
#else
return nil;
#endif // TODO: b/359236816 - fix visionOS-specific compatibility workarounds.
}

- (void)deactivateOverlay:(UIView *)overlay {
#if !TARGET_OS_VISION
UIWindow *window = [[UIApplication mdc_safeSharedApplication] keyWindow];
if ([window isKindOfClass:[MDCOverlayWindow class]]) {
MDCOverlayWindow *overlayWindow = (MDCOverlayWindow *)window;
[overlayWindow deactivateOverlay:overlay];
} else {
[overlay removeFromSuperview];
return;
}
#endif // TODO: b/359236816 - fix visionOS-specific compatibility workarounds.
[overlay removeFromSuperview];
}

#pragma mark - Public API
Expand Down
12 changes: 8 additions & 4 deletions components/Snackbar/src/MDCSnackbarMessageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,15 @@ + (BOOL)requiresConstraintBasedLayout {
}

- (CGFloat)minimumWidth {
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? kMinimumViewWidth_iPad
: kMinimumViewWidth_iPhone;
return UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
? kMinimumViewWidth_iPad
: kMinimumViewWidth_iPhone;
}

- (CGFloat)maximumWidth {
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? kMaximumViewWidth_iPad
: kMaximumViewWidth_iPhone;
return UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
? kMaximumViewWidth_iPad
: kMaximumViewWidth_iPhone;
}

#pragma mark - Styling the view
Expand Down Expand Up @@ -1090,6 +1092,7 @@ - (void)layoutSubviews {
[self updatePreferredMaxLayoutWidth];
[self updateButtonWidthConstraint];

#if !TARGET_OS_VISION
if (!self.dismissalAccessibilityAffordance.hidden) {
// Update frame of the dismissal touch affordance.
CGRect globalFrame = [self convertRect:self.bounds toView:nil];
Expand All @@ -1098,6 +1101,7 @@ - (void)layoutSubviews {
CGRect localDismissalAreaFrame = [self convertRect:globalDismissalAreaFrame fromView:nil];
self.dismissalAccessibilityAffordance.frame = localDismissalAreaFrame;
}
#endif // TODO: b/359236816 - fix visionOS-specific compatibility workarounds.

BOOL isMultilineText = [self numberOfLines] > 1;
if (_isMultilineText != isMultilineText) {
Expand Down
15 changes: 12 additions & 3 deletions components/Snackbar/src/private/MDCSnackbarOverlayView.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
name:MDCKeyboardWatcherKeyboardWillChangeFrameNotification
object:watcher];

#if !TARGET_OS_VISION
[nc addObserver:self
selector:@selector(willRotate:)
name:UIApplicationWillChangeStatusBarOrientationNotification
Expand All @@ -198,6 +199,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
selector:@selector(didRotate:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
#endif

[self setupContainerConstraints];
}
Expand Down Expand Up @@ -290,12 +292,13 @@ - (CGFloat)dynamicBottomMargin {
*/
- (CGFloat)staticBottomMargin {
if (MDCSnackbarMessage.usesLegacySnackbar) {
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
return UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
? MDCSnackbarLegacyBottomMargin_iPad
: MDCSnackbarLegacyBottomMargin_iPhone;
}
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? MDCSnackbarBottomMargin_iPad
: MDCSnackbarBottomMargin_iPhone;
return UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
? MDCSnackbarBottomMargin_iPad
: MDCSnackbarBottomMargin_iPhone;
}

- (void)setSnackbarView:(MDCSnackbarMessageView *)snackbarView {
Expand Down Expand Up @@ -490,6 +493,7 @@ - (void)triggerSnackbarLayoutChange {
}

- (CGRect)snackbarRectInScreenCoordinates {
#if !TARGET_OS_VISION
if (self.snackbarView == nil) {
return CGRectNull;
}
Expand All @@ -501,6 +505,9 @@ - (CGRect)snackbarRectInScreenCoordinates {

return [self.snackbarView convertRect:self.snackbarView.bounds
toCoordinateSpace:window.screen.coordinateSpace];
#else
return CGRectNull;
#endif // TODO: b/359236816 - fix visionOS-specific compatibility workarounds.
}

- (CGFloat)maximumHeight {
Expand Down Expand Up @@ -851,6 +858,7 @@ - (void)layoutSubviews {
}

- (void)willRotate:(NSNotification *)notification {
#if !TARGET_OS_VISION
UIApplication *application = [UIApplication mdc_safeSharedApplication];
UIInterfaceOrientation currentOrientation = application.statusBarOrientation;
UIInterfaceOrientation targetOrientation =
Expand All @@ -866,6 +874,7 @@ - (void)willRotate:(NSNotification *)notification {
}

self.rotationDuration = duration;
#endif // TODO: b/359220619 - fix this workaround for visionOS incompatibility.
}

- (void)didRotate:(__unused NSNotification *)notification {
Expand Down
2 changes: 1 addition & 1 deletion components/private/Overlay/src/MDCOverlayObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
If @c screen is nil, the main screen is used.
*/
+ (instancetype)observerForScreen:(UIScreen *)screen;
+ (instancetype)observerForScreen:(UIScreen *)screen API_UNAVAILABLE(visionos);

/**
Adds a target/action pair to listen for changes to overlays.
Expand Down
2 changes: 2 additions & 0 deletions components/private/Overlay/src/private/MDCOverlayUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#import "MDCOverlayUtilities.h"

CGRect MDCOverlayConvertRectToView(CGRect screenRect, UIView *target) {
#if !TARGET_OS_VISION
if (target != nil && !CGRectIsNull(screenRect)) {
UIScreen *screen = [UIScreen mainScreen];
return [target convertRect:screenRect fromCoordinateSpace:screen.coordinateSpace];
}
#endif // TODO: b/359236816 - fix visionOS-specific compatibility workarounds.
return CGRectNull;
}

0 comments on commit 142d22b

Please sign in to comment.