Skip to content

Commit

Permalink
fix for swift project, can not use `func contentShadow() -> HWPanModa…
Browse files Browse the repository at this point in the history
…lShadow`
  • Loading branch information
HeathWang committed Aug 4, 2023
1 parent 6fe96f0 commit c907c65
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Demo/PanControllerExample/Base/HWBaseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ - (BOOL)anchorModalToLongForm {
return NO;
}

- (HWPanModalShadow)contentShadow {
return PanModalShadowMake([UIColor yellowColor], 10, CGSizeMake(0, 2), 1);
- (HWPanModalShadow *)contentShadow {
return [[HWPanModalShadow alloc] initWithColor:[UIColor yellowColor] shadowRadius:10 shadowOffset:CGSizeMake(0, 2) shadowOpacity:1];
}

//- (UIViewAnimationOptions)transitionAnimationOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ @interface HWDynamicHeightViewController () <HWPanModalPresentable>
@property (nonatomic, strong) UIButton *changeShadowButton;
@property (nonatomic, strong) UIButton *clearShadowButton;

@property (nonatomic, assign) HWPanModalShadow shadowConfig;
@property (nonatomic, strong) HWPanModalShadow *shadowConfig;

// corner
@property (nonatomic, strong) UIButton *changeRoundCornerButton;
Expand Down Expand Up @@ -132,12 +132,12 @@ - (void)onTapChangeLong {
}

- (void)onTapDefaultShadow {
self.shadowConfig = PanModalShadowMake([UIColor blueColor], 8, CGSizeMake(0, 2), 1);
self.shadowConfig = [[HWPanModalShadow alloc] initWithColor:[UIColor blueColor] shadowRadius:8 shadowOffset:CGSizeMake(0, 2) shadowOpacity:1];
[self hw_panModalSetNeedsLayoutUpdate];
}

- (void)onTapClearShadow {
self.shadowConfig = PanModalShadowNil();
self.shadowConfig = [HWPanModalShadow panModalShadowNil];
[self hw_panModalSetNeedsLayoutUpdate];
}

Expand Down Expand Up @@ -188,7 +188,7 @@ - (PanModalHeight)longFormHeight {
return self.longHeight;
}

- (HWPanModalShadow)contentShadow {
- (HWPanModalShadow *)contentShadow {
return self.shadowConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ - (UIScrollView *)panScrollable {
return self.tableView;
}

- (HWPanModalShadow)contentShadow {
return PanModalShadowMake([UIColor systemPinkColor], 10, CGSizeMake(1, 1), 1);
- (HWPanModalShadow *)contentShadow {
return [[HWPanModalShadow alloc] initWithColor:[UIColor systemPinkColor] shadowRadius:10 shadowOffset:CGSizeMake(1, 1) shadowOpacity:1];
}

//- (BOOL)allowsTouchEventsPassingThroughTransitionView {
Expand Down
2 changes: 1 addition & 1 deletion HWPanModal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'HWPanModal'
s.version = '0.9.7'
s.version = '0.9.8'
s.summary = 'HWPanModal is used to present controller and drag to dismiss.'

# This description is used to generate tags and improve search results.
Expand Down
2 changes: 0 additions & 2 deletions HWPanModal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@
7EA0F56B230D5B7300ED20D2 /* HWPanModalPresentationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HWPanModalPresentationDelegate.m; sourceTree = "<group>"; };
7EA0F56C230D5B7300ED20D2 /* HWPanModalPresentationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HWPanModalPresentationDelegate.h; sourceTree = "<group>"; };
7EA0F56E230D5B7400ED20D2 /* UIViewController+Presentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Presentation.h"; sourceTree = "<group>"; };
7EA0F56F230D5B7400ED20D2 /* UIViewController+LayoutHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+LayoutHelper.m"; sourceTree = "<group>"; };
7EA0F570230D5B7400ED20D2 /* UIViewController+PanModalDefault.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+PanModalDefault.m"; sourceTree = "<group>"; };
7EA0F571230D5B7400ED20D2 /* HWPanModalPresentable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HWPanModalPresentable.h; sourceTree = "<group>"; };
7EA0F572230D5B7400ED20D2 /* UIViewController+Presentation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Presentation.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -501,7 +500,6 @@
7EA0F56E230D5B7400ED20D2 /* UIViewController+Presentation.h */,
7EA0F572230D5B7400ED20D2 /* UIViewController+Presentation.m */,
7EA0F574230D5B7400ED20D2 /* UIViewController+LayoutHelper.h */,
7EA0F56F230D5B7400ED20D2 /* UIViewController+LayoutHelper.m */,
);
path = Presentable;
sourceTree = "<group>";
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- HWPanModal (0.9.5)
- HWPanModal (0.9.7)
- Masonry (1.1.0)
- MJRefresh (3.5.0)
- SnapKit (5.0.1)
Expand All @@ -21,7 +21,7 @@ EXTERNAL SOURCES:
:path: "./"

SPEC CHECKSUMS:
HWPanModal: b6c51a2fd3ab5cfde868eec840c9e2d7465d745e
HWPanModal: 2340d953661dbeadd1f041cde9e059c0704c873a
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
MJRefresh: 6afc955813966afb08305477dd7a0d9ad5e79a16
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb
Expand Down
2 changes: 1 addition & 1 deletion Sources/Animator/HWPanModalPresentationAnimator.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ - (void)animateDismissal:(id<UIViewControllerContextTransitioning>)context {

- (void)springDismiss:(id <UIViewControllerContextTransitioning>)context fromVC:(UIViewController *)fromVC toVC:(UIViewController *)toVC presentable:(UIViewController <HWPanModalPresentable> *)presentable panView:(UIView *)panView {
CGFloat offsetY = 0;
HWPanModalShadow shadowConfig = [presentable contentShadow];
HWPanModalShadow *shadowConfig = [presentable contentShadow];
if (shadowConfig.shadowColor) {
// we should make the panView move further to hide the shadow effect.
offsetY = offsetY + shadowConfig.shadowRadius + shadowConfig.shadowOffset.height;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Controller/HWPanModalPresentationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ - (void)resetRoundedCornersToView:(UIView *)view {
}

- (void)updateContainerViewShadow {
HWPanModalShadow shadow = [[self presentable] contentShadow];
HWPanModalShadow *shadow = [[self presentable] contentShadow];
if (shadow.shadowColor) {
[self.panContainerView updateShadow:shadow.shadowColor shadowRadius:shadow.shadowRadius shadowOffset:shadow.shadowOffset shadowOpacity:shadow.shadowOpacity];
} else {
Expand Down
22 changes: 0 additions & 22 deletions Sources/Presentable/HWPanModalHeight.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@ CG_INLINE PanModalHeight PanModalHeightMake(PanModalHeightType heightType, CGFlo
return modalHeight;
}

struct HWPanModalShadow {
UIColor *shadowColor;
CGFloat shadowRadius;
CGSize shadowOffset;
float shadowOpacity;
};

typedef struct HWPanModalShadow HWPanModalShadow;

CG_INLINE HWPanModalShadow PanModalShadowMake(UIColor *shadowColor, CGFloat shadowRadius, CGSize shadowOffset, float shadowOpacity) {
HWPanModalShadow shadowConfig;
shadowConfig.shadowColor = shadowColor;
shadowConfig.shadowRadius = shadowRadius;
shadowConfig.shadowOffset = shadowOffset;
shadowConfig.shadowOpacity = shadowOpacity;
return shadowConfig;
}

CG_INLINE HWPanModalShadow PanModalShadowNil() {
return PanModalShadowMake([UIColor clearColor], 0, CGSizeZero, 0);
}

static inline BOOL HW_FLOAT_IS_ZERO(CGFloat value) {
return (value > -FLT_EPSILON) && (value < FLT_EPSILON);
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Presentable/HWPanModalPresentable.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import <HWPanModal/HWPresentingVCAnimatedTransitioning.h>
#import <HWPanModal/HWPanModalIndicatorProtocol.h>
#import <HWPanModal/HWBackgroundConfig.h>
#import <HWPanModal/HWPanModalShadow.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -271,7 +272,7 @@ typedef NS_ENUM(NSInteger, PresentingViewControllerAnimationStyle) {
* presented content shadow
* Default is None config
*/
- (HWPanModalShadow)contentShadow;
- (HWPanModalShadow *)contentShadow;

#pragma mark - Indicator config

Expand Down
4 changes: 2 additions & 2 deletions Sources/Presentable/UIViewController+PanModalDefault.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ - (CGFloat)cornerRadius {
return 8;
}

- (HWPanModalShadow)contentShadow {
return PanModalShadowMake(nil, 0, CGSizeZero, 0);
- (HWPanModalShadow *)contentShadow {
return [HWPanModalShadow panModalShadowNil];
}

- (BOOL)showDragIndicator {
Expand Down
26 changes: 26 additions & 0 deletions Sources/View/HWPanModalShadow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// HWPanModalShadow.h
// Pods
//
// Created by hb on 2023/8/3.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface HWPanModalShadow : NSObject

@property (nonatomic, strong) UIColor *shadowColor;
@property (nonatomic, assign) CGFloat shadowRadius;
@property (nonatomic, assign) CGSize shadowOffset;
@property (nonatomic, assign) CGFloat shadowOpacity;

- (instancetype)initWithColor:(UIColor *)shadowColor shadowRadius:(CGFloat)shadowRadius shadowOffset:(CGSize)shadowOffset shadowOpacity:(CGFloat)shadowOpacity;

+ (instancetype)panModalShadowNil;


@end

NS_ASSUME_NONNULL_END
28 changes: 28 additions & 0 deletions Sources/View/HWPanModalShadow.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// HWPanModalShadow.m
// Pods
//
// Created by hb on 2023/8/3.
//

#import "HWPanModalShadow.h"

@implementation HWPanModalShadow

- (instancetype)initWithColor:(UIColor *)shadowColor shadowRadius:(CGFloat)shadowRadius shadowOffset:(CGSize)shadowOffset shadowOpacity:(CGFloat)shadowOpacity {
self = [super init];
if (self) {
_shadowColor = shadowColor;
_shadowRadius = shadowRadius;
_shadowOffset = shadowOffset;
_shadowOpacity = shadowOpacity;
}

return self;
}

+ (instancetype)panModalShadowNil {
return [[HWPanModalShadow alloc] initWithColor:[UIColor clearColor] shadowRadius:0 shadowOffset:CGSizeZero shadowOpacity:0];
}

@end
2 changes: 1 addition & 1 deletion Sources/View/PanModal/HWPanModalContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ - (void)addDragIndicatorViewToView:(UIView *)view {
}

- (void)updateContainerViewShadow {
HWPanModalShadow shadow = [[self presentable] contentShadow];
HWPanModalShadow *shadow = [[self presentable] contentShadow];
if (shadow.shadowColor) {
[self.panContainerView updateShadow:shadow.shadowColor shadowRadius:shadow.shadowRadius shadowOffset:shadow.shadowOffset shadowOpacity:shadow.shadowOpacity];
} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/View/PanModal/HWPanModalContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ - (CGFloat)cornerRadius {
return 8;
}

- (HWPanModalShadow)contentShadow {
return PanModalShadowMake(nil, 0, CGSizeZero, 0);
- (HWPanModalShadow *)contentShadow {
return [HWPanModalShadow panModalShadowNil];
}

- (BOOL)showDragIndicator {
Expand Down
5 changes: 4 additions & 1 deletion SwiftDemo/ControllerExample/Basic/BasicViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ extension BasicViewController {
override func transitionAnimationOptions() -> UIView.AnimationOptions {
return [.curveLinear]
}


override func contentShadow() -> HWPanModalShadow {
return HWPanModalShadow(color: UIColor.red, shadowRadius: 10, shadowOffset: CGSizeMake(0, 2), shadowOpacity: 1)
}
}

0 comments on commit c907c65

Please sign in to comment.