Skip to content

Commit

Permalink
Correctly handle bar tint color
Browse files Browse the repository at this point in the history
Add translucent property to popup bar
Add hairline separator to prominent bar as well (iOS 11.2 adds it to Music app)
Closes #210
Closes #208
Closes #207
  • Loading branch information
LeoNatan committed Jan 15, 2018
1 parent be68328 commit 815d236
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 34 deletions.
8 changes: 8 additions & 0 deletions LNPopupController/LNPopupController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
397AFC061F1A229400E7D95C /* LNPopupInteractionPanGestureRecognizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 397AFC041F1A229400E7D95C /* LNPopupInteractionPanGestureRecognizer.m */; };
39A9249A1B58530A003C1C19 /* LNPopupController.h in Headers */ = {isa = PBXBuildFile; fileRef = 39A924991B5852ED003C1C19 /* LNPopupController.h */; settings = {ATTRIBUTES = (Public, ); }; };
39C81A321B642DDD00D3B645 /* LNPopupItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 394A85B71B6304F5004FFC61 /* LNPopupItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
39E7A604200B5157007AF3AD /* _LNPopupBase64Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 39E7A602200B5157007AF3AD /* _LNPopupBase64Utils.h */; };
39E7A605200B5157007AF3AD /* _LNPopupBase64Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 39E7A603200B5157007AF3AD /* _LNPopupBase64Utils.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -81,6 +83,8 @@
397AFC041F1A229400E7D95C /* LNPopupInteractionPanGestureRecognizer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LNPopupInteractionPanGestureRecognizer.m; sourceTree = "<group>"; };
39A924991B5852ED003C1C19 /* LNPopupController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LNPopupController.h; sourceTree = "<group>"; };
39DB52E51B5823330061C589 /* LNPopupController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LNPopupController.framework; sourceTree = BUILT_PRODUCTS_DIR; };
39E7A602200B5157007AF3AD /* _LNPopupBase64Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _LNPopupBase64Utils.h; sourceTree = "<group>"; };
39E7A603200B5157007AF3AD /* _LNPopupBase64Utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = _LNPopupBase64Utils.m; sourceTree = "<group>"; };
46ECC2AE1BF31025005CE96C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

Expand All @@ -100,6 +104,8 @@
children = (
397AFBFE1F1A216400E7D95C /* GestureRecognizers */,
3934A9F41DD4C935004B073A /* LNPopupController.pch */,
39E7A602200B5157007AF3AD /* _LNPopupBase64Utils.h */,
39E7A603200B5157007AF3AD /* _LNPopupBase64Utils.m */,
391481B91DCFA514002416D1 /* LNChevronView.h */,
391481B81DCFA514002416D1 /* LNChevronView.m */,
39314A501B6AE7A400574D3C /* MarqueeLabel.h */,
Expand Down Expand Up @@ -189,6 +195,7 @@
3947E1B21B61CE4A0001178B /* LNPopupController.h in Headers */,
3947E1BA1B6300370001178B /* LNPopupBar+Private.h in Headers */,
397AFC051F1A229400E7D95C /* LNPopupInteractionPanGestureRecognizer.h in Headers */,
39E7A604200B5157007AF3AD /* _LNPopupBase64Utils.h in Headers */,
39314A521B6AE7A400574D3C /* MarqueeLabel.h in Headers */,
391481BB1DCFA514002416D1 /* LNChevronView.h in Headers */,
39599BAD1E02CDF4008EE386 /* LNPopupCustomBarViewController+Private.h in Headers */,
Expand Down Expand Up @@ -270,6 +277,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
39E7A605200B5157007AF3AD /* _LNPopupBase64Utils.m in Sources */,
397AFC021F1A21DD00E7D95C /* LNPopupLongPressGesutreRecognizer.m in Sources */,
39222ADC1F1A1C5800388E06 /* LNPopupOpenTapGesutreRecognizer.m in Sources */,
3947E1AA1B61CDA40001178B /* LNPopupCloseButton.m in Sources */,
Expand Down
12 changes: 11 additions & 1 deletion LNPopupController/LNPopupController/LNPopupBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ typedef NS_ENUM(NSUInteger, LNPopupBarProgressViewStyle) {
*/
@interface LNPopupBar : UIView <UIAppearanceContainer>

/**
* If @c YES, the popup bar will automatically inherit its style from the bottom docking view.
*/
@property (nonatomic, assign) BOOL inheritsVisualStyleFromDockingView UI_APPEARANCE_SELECTOR;

/**
* The currently displayed popup item. (read-only)
*/
@property(nullable, nonatomic, weak, readonly) LNPopupItem* popupItem;
@property (nullable, nonatomic, weak, readonly) LNPopupItem* popupItem;

/**
* An array of custom bar button items to display on the left side. (read-only)
Expand Down Expand Up @@ -130,6 +135,11 @@ typedef NS_ENUM(NSUInteger, LNPopupBarProgressViewStyle) {
*/
@property (nullable, nonatomic, strong) UIColor* barTintColor UI_APPEARANCE_SELECTOR;

/**
* A Boolean value that indicates whether the popup bar is translucent (@c YES) or not (@c NO).
*/
@property(nonatomic, assign, getter=isTranslucent) BOOL translucent UI_APPEARANCE_SELECTOR;

/**
* Display attributes for the popup bar’s title text.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern LNPopupBarStyle _LNPopupResolveBarStyleFromBarStyle(LNPopupBarStyle style

@property (nonatomic, assign) UIBarStyle barStyle;
@property (nonatomic, retain) UIColor* barTintColor;
@property(nonatomic, assign, getter=isTranslucent) BOOL translucent;

@end

Expand Down
55 changes: 45 additions & 10 deletions LNPopupController/LNPopupController/Private/LNPopupBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "LNPopupBar+Private.h"
#import "LNPopupCustomBarViewController+Private.h"
#import "MarqueeLabel.h"
#import "_LNPopupBase64Utils.h"

@interface _LNPopupToolbar : UIToolbar @end
@implementation _LNPopupToolbar
Expand Down Expand Up @@ -81,6 +82,7 @@ @implementation LNPopupBar
UIColor* _userBackgroundColor;

UIBlurEffectStyle _actualBackgroundStyle;
UIBlurEffect* _customBlurEffect;

UIView* _shadowView;

Expand Down Expand Up @@ -169,13 +171,19 @@ - (nonnull instancetype)initWithFrame:(CGRect)frame
{
self.preservesSuperviewLayoutMargins = YES;

_inheritsVisualStyleFromDockingView = YES;

_userBackgroundStyle = LNBackgroundStyleInherit;

_translucent = YES;

_backgroundView = [[UIVisualEffectView alloc] initWithEffect:nil];
_backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_backgroundView.userInteractionEnabled = NO;
[self addSubview:_backgroundView];

_resolvedStyle = _LNPopupResolveBarStyleFromBarStyle(_barStyle);

[self _innerSetBackgroundStyle:LNBackgroundStyleInherit];

_toolbar = [[_LNPopupToolbar alloc] initWithFrame:self.bounds];
Expand Down Expand Up @@ -230,8 +238,6 @@ - (nonnull instancetype)initWithFrame:(CGRect)frame
_highlightView.alpha = 0.0;
[self addSubview:_highlightView];

_resolvedStyle = _LNPopupResolveBarStyleFromBarStyle(_barStyle);

_marqueeScrollEnabled = [NSProcessInfo processInfo].operatingSystemVersion.majorVersion < 10;
_coordinateMarqueeScroll = YES;

Expand Down Expand Up @@ -275,8 +281,7 @@ - (void)layoutSubviews
[self bringSubviewToFront:_titlesView];
[self bringSubviewToFront:_shadowView];

_shadowView.frame = CGRectMake(0, 0, self.toolbar.bounds.size.width, 1 / self.window.screen.scale);
_shadowView.hidden = _resolvedStyle == LNPopupBarStyleProminent;
_shadowView.frame = CGRectMake(0, 0, self.toolbar.bounds.size.width, 1 / self.window.screen.nativeScale);

[self _layoutImageView];
[self _layoutTitles];
Expand All @@ -292,7 +297,14 @@ - (void)_innerSetBackgroundStyle:(UIBlurEffectStyle)backgroundStyle
_userBackgroundStyle = backgroundStyle;

_actualBackgroundStyle = _userBackgroundStyle == LNBackgroundStyleInherit ? _LNBlurEffectStyleForSystemBarStyle(_systemBarStyle, _resolvedStyle) : _userBackgroundStyle;
[_backgroundView setValue:[UIBlurEffect effectWithStyle:_actualBackgroundStyle] forKey:@"effect"];
#ifndef LNPopupControllerEnforceStrictClean
//_UICustomBlurEffect
_customBlurEffect = [NSClassFromString(_LNPopupDecodeBase64String(@"X1VJQ3VzdG9tQmx1ckVmZmVjdA==")) effectWithStyle:_actualBackgroundStyle];
#else
_customBlurEffect = [UIBlurEffect effectWithStyle:_actualBackgroundStyle];
#endif

[_backgroundView setValue:_customBlurEffect forKey:@"effect"];

if(_userBackgroundStyle == LNBackgroundStyleInherit)
{
Expand All @@ -306,6 +318,10 @@ - (void)_innerSetBackgroundStyle:(UIBlurEffectStyle)backgroundStyle
}
}

//Recalculate bar tint color
[self _internalSetBarTintColor:_userBarTintColor];

//Recalculate labels
[self _setTitleLableFontsAccordingToBarStyleAndTint];
}

Expand Down Expand Up @@ -335,12 +351,22 @@ - (void)_internalSetBarTintColor:(UIColor*)barTintColor
{
_userBarTintColor = barTintColor;

UIColor* colorToUse = _userBarTintColor ?: _systemBarTintColor;

self.backgroundColor = [colorToUse colorWithAlphaComponent:1.0];
[_backgroundView setHidden:self.backgroundColor != nil];
UIColor* colorToUse = [_userBarTintColor ?: _systemBarTintColor colorWithAlphaComponent:0.67];

[self _setTitleLableFontsAccordingToBarStyleAndTint];
if(_translucent == NO)
{
colorToUse = colorToUse ? [colorToUse colorWithAlphaComponent:1.0] : (_actualBackgroundStyle == UIBlurEffectStyleLight || _actualBackgroundStyle == UIBlurEffectStyleExtraLight) ? [UIColor whiteColor] : [UIColor blackColor];
}
//#ifndef LNPopupControllerEnforceStrictClean
// [_customBlurEffect setValue:[colorToUse colorWithAlphaComponent:1.0] forKey:@"colorTint"];
// //colorTintAlpha
// [_customBlurEffect setValue:@0.67 forKey:_LNPopupDecodeBase64String(@"Y29sb3JUaW50QWxwaGE=")];
//
// _backgroundView.effect = _customBlurEffect;
//#else
self.backgroundColor = colorToUse;
// [_backgroundView setHidden:self.backgroundColor != nil];
//#endif
}

- (void)setBarTintColor:(UIColor *)barTintColor
Expand Down Expand Up @@ -421,6 +447,15 @@ - (void)setSystemShadowColor:(UIColor *)systemShadowColor
_shadowView.backgroundColor = systemShadowColor;
}

- (void)setTranslucent:(BOOL)translucent
{
_translucent = translucent;

_backgroundView.hidden = _translucent == NO;

[self _internalSetBarTintColor:_userBarTintColor];
}

- (void)setTitle:(NSString *)title
{
_title = [title copy];
Expand Down
16 changes: 13 additions & 3 deletions LNPopupController/LNPopupController/Private/LNPopupController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "LNPopupOpenTapGesutreRecognizer.h"
#import "LNPopupLongPressGesutreRecognizer.h"
#import "LNPopupInteractionPanGestureRecognizer.h"
#import "_LNPopupBase64Utils.h"
@import ObjectiveC;

void __LNPopupControllerOutOfWindowHierarchy()
Expand Down Expand Up @@ -862,6 +863,11 @@ - (void)_reconfigureContent

- (void)_configurePopupBarFromBottomBar
{
if(self.popupBar.inheritsVisualStyleFromDockingView == NO)
{
return;
}

if([_bottomBar respondsToSelector:@selector(barStyle)])
{
[self.popupBar setSystemBarStyle:[(id<_LNPopupBarSupport>)_bottomBar barStyle]];
Expand All @@ -873,18 +879,22 @@ - (void)_configurePopupBarFromBottomBar
}
self.popupBar.systemBackgroundColor = _bottomBar.backgroundColor;

if([_bottomBar respondsToSelector:@selector(isTranslucent)])
{
self.popupBar.translucent = [(id<_LNPopupBarSupport>)_bottomBar isTranslucent];
}

#ifndef LNPopupControllerEnforceStrictClean
//backgroundView
static NSString* const bV = @"X2JhY2tncm91bmRWaWV3";
//backgroundView.shadowView.backgroundColor
static NSString* const bVsVbC = @"YmFja2dyb3VuZFZpZXcuc2hhZG93Vmlldy5iYWNrZ3JvdW5kQ29sb3I=";

NSString* str1 = [[NSString alloc] initWithData:[[NSData alloc] initWithBase64EncodedString:bV options:0] encoding:NSUTF8StringEncoding];
NSString* str1 = _LNPopupDecodeBase64String(bV);

if([_bottomBar respondsToSelector:NSSelectorFromString(str1)])
{
NSString* str2 = [[NSString alloc] initWithData:[[NSData alloc] initWithBase64EncodedString:bVsVbC options:0] encoding:NSUTF8StringEncoding];

NSString* str2 = _LNPopupDecodeBase64String(bVsVbC);

if([[NSProcessInfo processInfo] operatingSystemVersion].majorVersion >= 10)
{
Expand Down
Loading

0 comments on commit 815d236

Please sign in to comment.