Skip to content

Commit 7319efd

Browse files
Nobodymaterial-automation
Nobody
authored andcommitted
Add option to activate an overlay underneath all other overlays with the same UIWindowLevel.
PiperOrigin-RevId: 723263384
1 parent 4d98ee5 commit 7319efd

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

components/OverlayWindow/src/MDCOverlayWindow.h

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
*/
3535
- (void)activateOverlay:(UIView *)overlay withLevel:(UIWindowLevel)level;
3636

37+
/**
38+
Notifies the window that the given overlay view should be shown at the bottom of the given level.
39+
This overlay will get added underneath all other overlays with the given UIWindowLevel.
40+
41+
Overlay owners must call this method to ensure that the overlay is actually displayed over the
42+
window's primary content.
43+
44+
@param overlay The overlay being displayed.
45+
@param level The UIWindowLevel to display the overlay on.
46+
*/
47+
- (void)activateOverlay:(UIView *)overlay atBottomOfLevel:(UIWindowLevel)level;
48+
3749
/**
3850
Notifies the window that the given overlay is no longer active.
3951

components/OverlayWindow/src/MDCOverlayWindow.m

+12-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,17 @@ - (void)noteOverlayRemoved:(UIView *)overlay {
148148
[self updateOverlayHiddenState];
149149
}
150150

151+
- (void)activateOverlay:(UIView *)overlay atBottomOfLevel:(UIWindowLevel)level {
152+
[self activateOverlay:overlay withLevel:level bottomOfLevel:YES];
153+
}
154+
151155
- (void)activateOverlay:(UIView *)overlay withLevel:(UIWindowLevel)level {
156+
[self activateOverlay:overlay withLevel:level bottomOfLevel:NO];
157+
}
158+
159+
- (void)activateOverlay:(UIView *)overlay
160+
withLevel:(UIWindowLevel)level
161+
bottomOfLevel:(BOOL)bottomOfLevel {
152162
if (!overlay) {
153163
return;
154164
}
@@ -163,10 +173,10 @@ - (void)activateOverlay:(UIView *)overlay withLevel:(UIWindowLevel)level {
163173
__block NSUInteger insertionIndex = self.overlays.count;
164174

165175
// Because @c self.overlays is already sorted by level, we can pick the first index which has a
166-
// level larger than @c level.
176+
// level larger than / equal to @c level.
167177
[self.overlays enumerateObjectsUsingBlock:^(UIView *existing, NSUInteger idx, BOOL *stop) {
168178
UIWindowLevel existingLevel = [self windowLevelForOverlay:existing];
169-
if (level < existingLevel) {
179+
if ((bottomOfLevel && level == existingLevel) || (level < existingLevel)) {
170180
insertionIndex = idx;
171181
*stop = YES;
172182
}

0 commit comments

Comments
 (0)