Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 30ebbeb

Browse files
committed
refactor: combile local and remote orientation
Signed-off-by: Lessica <wuzheng28@huawei.com>
1 parent 1e87627 commit 30ebbeb

File tree

1 file changed

+17
-37
lines changed

1 file changed

+17
-37
lines changed

sources/HUDRootViewController.mm

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,9 @@ @implementation HUDRootViewController {
328328
NSLayoutConstraint *_centerXConstraint;
329329
NSLayoutConstraint *_leadingConstraint;
330330
NSLayoutConstraint *_trailingConstraint;
331+
UIInterfaceOrientation _orientation;
331332
#if !NO_TROLL
332-
FBSOrientationObserver *_remoteOrientationObserver;
333-
UIInterfaceOrientation _remoteOrientation;
334-
#else
335-
UIInterfaceOrientation _localOrientation;
333+
FBSOrientationObserver *_orientationObserver;
336334
#endif
337335
}
338336

@@ -441,17 +439,11 @@ + (BOOL)passthroughMode
441439

442440
- (BOOL)isLandscapeOrientation
443441
{
444-
UIInterfaceOrientation orientation;
445-
#if !NO_TROLL
446-
orientation = _remoteOrientation;
447-
#else
448-
orientation = _localOrientation;
449-
#endif
450442
BOOL isLandscape;
451-
if (orientation == UIInterfaceOrientationUnknown) {
443+
if (_orientation == UIInterfaceOrientationUnknown) {
452444
isLandscape = CGRectGetWidth(self.view.bounds) > CGRectGetHeight(self.view.bounds);
453445
} else {
454-
isLandscape = UIInterfaceOrientationIsLandscape(orientation);
446+
isLandscape = UIInterfaceOrientationIsLandscape(_orientation);
455447
}
456448
return isLandscape;
457449
}
@@ -559,9 +551,9 @@ - (instancetype)init
559551
_constraints = [NSMutableArray array];
560552
[self registerNotifications];
561553
#if !NO_TROLL
562-
_remoteOrientationObserver = [[objc_getClass("FBSOrientationObserver") alloc] init];
554+
_orientationObserver = [[objc_getClass("FBSOrientationObserver") alloc] init];
563555
__weak HUDRootViewController *weakSelf = self;
564-
[_remoteOrientationObserver setHandler:^(FBSOrientationUpdate *orientationUpdate) {
556+
[_orientationObserver setHandler:^(FBSOrientationUpdate *orientationUpdate) {
565557
HUDRootViewController *strongSelf = weakSelf;
566558
dispatch_async(dispatch_get_main_queue(), ^{
567559
[strongSelf updateOrientation:(UIInterfaceOrientation)orientationUpdate.orientation animateWithDuration:orientationUpdate.duration];
@@ -575,16 +567,17 @@ - (instancetype)init
575567
- (void)dealloc
576568
{
577569
#if !NO_TROLL
578-
[_remoteOrientationObserver invalidate];
570+
[_orientationObserver invalidate];
579571
#endif
580572
}
581573

582574
- (void)updateSpeedLabel
583575
{
584576
log_debug(OS_LOG_DEFAULT, "updateSpeedLabel");
585577
NSAttributedString *attributedText = formattedAttributedString(_isFocused);
586-
if (attributedText)
578+
if (attributedText) {
587579
[_speedLabel setAttributedText:attributedText];
580+
}
588581
[_speedLabel sizeToFit];
589582
}
590583

@@ -672,21 +665,14 @@ - (void)updateViewConstraints
672665
[_constraints removeAllObjects];
673666

674667
#if NO_TROLL
675-
_localOrientation = [self.view.window.windowScene interfaceOrientation];
676-
#endif
677-
678-
UIInterfaceOrientation orientation;
679-
#if !NO_TROLL
680-
orientation = _remoteOrientation;
681-
#else
682-
orientation = _localOrientation;
668+
_orientation = [self.view.window.windowScene interfaceOrientation];
683669
#endif
684670

685671
BOOL isLandscape;
686-
if (orientation == UIInterfaceOrientationUnknown) {
672+
if (_orientation == UIInterfaceOrientationUnknown) {
687673
isLandscape = CGRectGetWidth(self.view.bounds) > CGRectGetHeight(self.view.bounds);
688674
} else {
689-
isLandscape = UIInterfaceOrientationIsLandscape(orientation);
675+
isLandscape = UIInterfaceOrientationIsLandscape(_orientation);
690676
}
691677

692678
HUDPresetPosition selectedMode = [self selectedModeForCurrentOrientation];
@@ -718,8 +704,8 @@ - (void)updateViewConstraints
718704
#endif
719705

720706
[_constraints addObjectsFromArray:@[
721-
[_contentView.leadingAnchor constraintEqualToAnchor:layoutGuide.leadingAnchor constant:(orientation == UIInterfaceOrientationLandscapeLeft ? -paddingFarFromNotch : paddingNearNotch)],
722-
[_contentView.trailingAnchor constraintEqualToAnchor:layoutGuide.trailingAnchor constant:(orientation == UIInterfaceOrientationLandscapeLeft ? -paddingNearNotch : paddingFarFromNotch)],
707+
[_contentView.leadingAnchor constraintEqualToAnchor:layoutGuide.leadingAnchor constant:(_orientation == UIInterfaceOrientationLandscapeLeft ? -paddingFarFromNotch : paddingNearNotch)],
708+
[_contentView.trailingAnchor constraintEqualToAnchor:layoutGuide.trailingAnchor constant:(_orientation == UIInterfaceOrientationLandscapeLeft ? -paddingNearNotch : paddingFarFromNotch)],
723709
]];
724710

725711
CGFloat minimumLandscapeTopConstant = 0;
@@ -1000,13 +986,7 @@ - (void)panGestureRecognized:(UIPanGestureRecognizer *)sender
1000986

1001987
if (sender.state == UIGestureRecognizerStateEnded)
1002988
{
1003-
UIInterfaceOrientation orientation;
1004-
#if !NO_TROLL
1005-
orientation = _remoteOrientation;
1006-
#else
1007-
orientation = _localOrientation;
1008-
#endif
1009-
if (UIInterfaceOrientationIsLandscape(orientation))
989+
if (UIInterfaceOrientationIsLandscape(_orientation))
1010990
[self setCurrentLandscapePositionY:_topConstraint.constant];
1011991
else
1012992
[self setCurrentPositionY:_topConstraint.constant];
@@ -1089,11 +1069,11 @@ - (void)updateOrientation:(UIInterfaceOrientation)orientation animateWithDuratio
10891069
return;
10901070
}
10911071

1092-
if (orientation == _remoteOrientation) {
1072+
if (orientation == _orientation) {
10931073
return;
10941074
}
10951075

1096-
_remoteOrientation = orientation;
1076+
_orientation = orientation;
10971077
[self cancelPreviousPerformRequestsWithTarget:_contentView];
10981078

10991079
CGRect bounds = orientationBounds(orientation, [UIScreen mainScreen].bounds);

0 commit comments

Comments
 (0)