Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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 @@ -681,11 +681,6 @@ - (void)updateViewportMetrics {
[_engine.get() updateViewportMetrics:_viewportMetrics];
}

- (void)updateViewConstraints {
[super updateViewConstraints];
[self onUserSettingsChanged:nil];
}

- (CGFloat)statusBarPadding {
UIScreen* screen = self.view.window.screen;
CGRect statusFrame = [UIApplication sharedApplication].statusBarFrame;
Expand All @@ -695,11 +690,6 @@ - (CGFloat)statusBarPadding {
return CGRectIsNull(intersection) ? 0.0 : intersection.size.height;
}

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
[self onUserSettingsChanged:nil];
}

- (void)viewDidLayoutSubviews {
CGSize viewSize = self.view.bounds.size;
CGFloat scale = [UIScreen mainScreen].scale;
Expand All @@ -712,7 +702,6 @@ - (void)viewDidLayoutSubviews {

[self updateViewportPadding];
[self updateViewportMetrics];
[self onUserSettingsChanged:nil];

// This must run after updateViewportMetrics so that the surface creation tasks are queued after
// the viewport metrics update tasks.
Expand Down Expand Up @@ -874,16 +863,10 @@ - (void)onLocaleUpdated:(NSNotification*)notification {

#pragma mark - Set user settings

- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self onUserSettingsChanged:nil];
}

- (void)onUserSettingsChanged:(NSNotification*)notification {
[[_engine.get() settingsChannel] sendMessage:@{
@"textScaleFactor" : @([self textScaleFactor]),
@"alwaysUse24HourFormat" : @([self isAlwaysUse24HourFormat]),
@"platformBrightness" : [self brightnessMode]
}];
}

Expand Down Expand Up @@ -957,20 +940,6 @@ - (BOOL)isAlwaysUse24HourFormat {
return [dateFormat rangeOfString:@"a"].location == NSNotFound;
}

- (NSString*)brightnessMode {
if (@available(iOS 13, *)) {
UIUserInterfaceStyle style = UITraitCollection.currentTraitCollection.userInterfaceStyle;

if (style == UIUserInterfaceStyleDark) {
return @"dark";
} else {
return @"light";
}
} else {
return @"light";
}
}

#pragma mark - Status Bar touch event handling

// Standard iOS status bar height in pixels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#import <XCTest/XCTest.h>
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"

#include "FlutterBinaryMessenger.h"

@interface FlutterViewControllerTest : XCTestCase
@end

Expand All @@ -25,85 +23,4 @@ - (void)testBinaryMessenger {
OCMVerify([engine binaryMessenger]);
}

- (void)testItReportsLightPlatformBrightnessByDefault {
// Setup test.
id engine = OCMClassMock([FlutterEngine class]);

id settingsChannel = OCMClassMock([FlutterBasicMessageChannel class]);
OCMStub([engine settingsChannel]).andReturn(settingsChannel);

FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];

// Exercise behavior under test.
[vc traitCollectionDidChange:nil];

// Verify behavior.
OCMVerify([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(id message) {
return [message[@"platformBrightness"] isEqualToString:@"light"];
}]]);
}

- (void)testItReportsDarkPlatformBrightnessWhenTraitCollectionRequestsIt {
// Setup test.
id engine = OCMClassMock([FlutterEngine class]);

id settingsChannel = OCMClassMock([FlutterBasicMessageChannel class]);
OCMStub([engine settingsChannel]).andReturn(settingsChannel);

FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
id mockTraitCollection = [self setupFakeUserInterfaceStyle:UIUserInterfaceStyleDark];

// Exercise behavior under test.
[vc traitCollectionDidChange:nil];

// Verify behavior.
OCMVerify([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(id message) {
return [message[@"platformBrightness"] isEqualToString:@"light"];
}]]);

// Restore UIUserInterfaceStyle
[mockTraitCollection stopMocking];
}

- (void)testItReportsPlatformBrightnessWhenExpected {
// Setup test.
id engine = OCMClassMock([FlutterEngine class]);

id settingsChannel = OCMClassMock([FlutterBasicMessageChannel class]);
OCMStub([engine settingsChannel]).andReturn(settingsChannel);

FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
id mockTraitCollection = [self setupFakeUserInterfaceStyle:UIUserInterfaceStyleDark];

__block int messageCount = 0;
OCMStub([settingsChannel sendMessage:[OCMArg any]]).andDo(^(NSInvocation* invocation) {
messageCount = messageCount + 1;
});

// Exercise behavior under test.
[vc updateViewConstraints];
[vc viewWillLayoutSubviews];
[vc traitCollectionDidChange:nil];
[vc onUserSettingsChanged:nil];

// Verify behavior.
XCTAssertEqual(messageCount, 4);

// Restore UIUserInterfaceStyle
[mockTraitCollection stopMocking];
}

- (UITraitCollection*)setupFakeUserInterfaceStyle:(UIUserInterfaceStyle)style {
id mockTraitCollection = OCMClassMock([UITraitCollection class]);
OCMStub([mockTraitCollection userInterfaceStyle]).andReturn(UIUserInterfaceStyleDark);
OCMStub([mockTraitCollection currentTraitCollection]).andReturn(mockTraitCollection);
return mockTraitCollection;
}

@end
2 changes: 1 addition & 1 deletion testing/ios/IosUnitTests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fi

set -o pipefail && xcodebuild -sdk iphonesimulator \
-scheme IosUnitTests \
-destination 'platform=iOS Simulator,name=iPhone 8,OS=13.0' \
-destination 'platform=iOS Simulator,name=iPhone SE,OS=12.2' \
test \
FLUTTER_ENGINE=$FLUTTER_ENGINE | $PRETTY