[ios] fix UI bugs when appearance is changing

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2024-02-01 11:45:12 +04:00 committed by Alexander Borsuk
parent 6da9ee7e91
commit 8842618c29
9 changed files with 55 additions and 5 deletions

View file

@ -266,4 +266,19 @@
[super layoutSubviews];
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
if (self.traitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle) {
[self updateViewStyle:self];
}
}
- (void)updateViewStyle:(UIView *)view {
if (!view)
return;
for (UIView *subview in view.subviews)
[self updateViewStyle:subview];
[view applyTheme];
}
@end

View file

@ -26,6 +26,7 @@ class UITextFieldRenderer {
control.layer.cornerCurve = .continuous
}
}
control.borderStyle = .none
var placeholderAttributes = [NSAttributedString.Key : Any]()
if let backgroundColor = style.backgroundColor {
control.backgroundColor = backgroundColor

View file

@ -14,8 +14,11 @@ class PlacePageHeaderViewController: UIViewController {
@IBOutlet private var expandView: UIView!
@IBOutlet private var shadowView: UIView!
@IBOutlet private var grabberView: UIView!
override func viewDidLoad() {
private var titleText: String?
private var secondaryText: String?
override func viewDidLoad() {
super.viewDidLoad()
presenter?.configure()
let tap = UITapGestureRecognizer(target: self, action: #selector(onExpandPressed(sender:)))
@ -33,6 +36,12 @@ class PlacePageHeaderViewController: UIViewController {
@IBAction private func onCloseButtonPressed(_ sender: Any) {
presenter?.onClosePress()
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
guard traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle else { return }
setTitle(titleText, secondaryTitle: secondaryText)
}
}
extension PlacePageHeaderViewController: PlacePageHeaderViewProtocol {
@ -55,6 +64,8 @@ extension PlacePageHeaderViewController: PlacePageHeaderViewProtocol {
}
func setTitle(_ title: String?, secondaryTitle: String?) {
titleText = title
secondaryText = secondaryTitle
// XCode 13 is not smart enough to detect that title is used below, and requires explicit unwrapped variable.
guard let unwrappedTitle = title else {
titleLabel?.attributedText = nil

View file

@ -24,6 +24,7 @@ class InfoItemViewController: UIViewController {
imageView?.styleName = "MWMBlue"
infoLabel?.styleName = "linkBlueText"
}
accessoryImage.styleName = "MWMBlack"
}
}
@ -361,6 +362,7 @@ private extension UIView {
color: UIColor?,
insets: UIEdgeInsets) {
let lineView = UIView()
lineView.styleName = "Divider"
lineView.backgroundColor = color ?? .black
lineView.isUserInteractionEnabled = false
lineView.translatesAutoresizingMaskIntoConstraints = false

View file

@ -61,6 +61,12 @@ final class PlacePagePreviewViewController: UIViewController {
}
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
guard traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle else { return }
updateViews()
}
private func updateViews() {
if placePagePreviewData.isMyPosition {
if let speedAndAltitude = speedAndAltitude {
@ -91,7 +97,7 @@ final class PlacePagePreviewViewController: UIViewController {
} else {
addressContainerView.isHidden = true
}
placePageDirectionView?.imageView.changeColoringToOpposite()
configSchedule()
}

View file

@ -20,6 +20,12 @@ class WikiDescriptionViewController: UIViewController {
updateDescription()
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
guard traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle else { return }
updateDescription()
}
private func updateDescription() {
guard let descriptionHtml = descriptionHtml else { return }

View file

@ -173,6 +173,9 @@
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular14:blackSecondaryText"/>
</userDefinedRuntimeAttributes>
</label>
<view hidden="YES" contentMode="scaleToFill" horizontalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="jaa-Yj-XQR" customClass="PlacePageDirectionView" customModule="Organic_Maps" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="69.5" height="50"/>
@ -741,7 +744,7 @@
<constraint firstAttribute="height" constant="44" id="UK1-MJ-aDf"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="coloring" value="MWMBlack"/>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="MWMBlack"/>
</userDefinedRuntimeAttributes>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="6l3-ag-Ii0">

View file

@ -199,6 +199,11 @@ NSString *titleForButton(MWMActionBarButtonType type, BOOL isSelected) {
[NSUserDefaults.standardUserDefaults setBool:true forKey:kUDDidHighlightRouteToButton];
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self.button setSelected:false];
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
return [self pointInside:point withEvent:event] ? self.button : nil;
}

View file

@ -103,7 +103,8 @@ final class PlacePageScrollView: UIScrollView {
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if self.previousTraitCollection != nil {
// Update layout when the device was rotated but skip when the appearance was changed.
if self.previousTraitCollection != nil, previousTraitCollection?.userInterfaceStyle == traitCollection.userInterfaceStyle {
DispatchQueue.main.async {
self.updateSteps()
self.showLastStop()