Skip to content

Commit

Permalink
Release 3.3.1
Browse files Browse the repository at this point in the history
- 为 SJEdgeControlButtonItem 添加 Actions.
  • Loading branch information
changsanjiang committed Mar 25, 2021
1 parent af017ec commit 453abf1
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Example/SJVideoPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@
ORGANIZATIONNAME = changsanjiang;
TargetAttributes = {
6003F589195388D20070C39A = {
DevelopmentTeam = Q6TTFXGP8Q;
DevelopmentTeam = DVCY355DY9;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.BackgroundModes = {
Expand Down Expand Up @@ -1329,7 +1329,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = Q6TTFXGP8Q;
DEVELOPMENT_TEAM = DVCY355DY9;
ENABLE_BITCODE = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SJVideoPlayer/SJVideoPlayer-Prefix.pch";
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ - (void)_test {
_player.defaultFloatSmallViewControlLayer.bottomHeight = 35;

SJEdgeControlButtonItem *playItem = [SJEdgeControlButtonItem.alloc initWithTag:101];
[playItem addTarget:self action:@selector(playOrPause)];
[playItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(playOrPause)]];
[_player.defaultFloatSmallViewControlLayer.bottomAdapter addItem:playItem];
__weak typeof(self) _self = self;
_player.playbackObserver.playbackStatusDidChangeExeBlock = ^(__kindof SJBaseVideoPlayer * _Nonnull player) {
Expand Down
2 changes: 1 addition & 1 deletion SJVideoPlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'SJVideoPlayer'
s.version = '3.3.0'
s.version = '3.3.1'
s.summary = 'video player.'
s.description = 'https://github.com/changsanjiang/SJVideoPlayer/blob/master/README.md'
s.homepage = 'https://github.com/changsanjiang/SJVideoPlayer'
Expand Down
31 changes: 26 additions & 5 deletions SJVideoPlayer/Common/Utils/Adapters/Core/SJEdgeControlButtonItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
#import <SJBaseVideoPlayer/SJPlayerGestureControlDefines.h>
typedef NSInteger SJEdgeControlButtonItemTag;
@class SJBaseVideoPlayer;
@class SJBaseVideoPlayer, SJEdgeControlButtonItemAction;

typedef struct SJEdgeInsets {
// 前后间距
Expand Down Expand Up @@ -50,14 +50,15 @@ UIKIT_EXTERN NSNotificationName const SJEdgeControlButtonItemPerformedActionNoti
@property (nonatomic, strong, nullable) UIImage *image;
@property (nonatomic, getter=isHidden) BOOL hidden;
@property (nonatomic) CGFloat alpha;
@property (nonatomic, weak, nullable) id target;
@property (nonatomic, nullable) SEL action;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
@property (nonatomic) BOOL fill; // 当想要填充剩余空间时, 可以设置为`Yes`.

- (void)addTarget:(id)target action:(nonnull SEL)action;
- (void)performAction;
@property (nonatomic, readonly, nullable) NSArray<SJEdgeControlButtonItemAction *> *actions;
- (void)addAction:(SJEdgeControlButtonItemAction *)action;
- (void)removeAction:(SJEdgeControlButtonItemAction *)action;
- (void)removeAllActions;
- (void)performActions;
@end

typedef enum : NSUInteger {
Expand All @@ -84,4 +85,24 @@ typedef enum : NSUInteger {
+ (instancetype)frameLayoutWithCustomView:(__kindof UIView *)customView tag:(SJEdgeControlButtonItemTag)tag;
@property (nonatomic, readonly) BOOL isFrameLayout;
@end


@interface SJEdgeControlButtonItem (SJDeprecated)
- (void)addTarget:(id)target action:(nonnull SEL)action __deprecated_msg("use `addAction:`;");
- (void)performAction __deprecated_msg("use `performActions`;");
@end

#pragma mark - action

@interface SJEdgeControlButtonItemAction : NSObject
+ (instancetype)actionWithTarget:(id)target action:(SEL)action;
- (instancetype)initWithTarget:(id)target action:(SEL)action;

+ (instancetype)actionWithHandler:(void(^)(SJEdgeControlButtonItemAction *action))handler;
- (instancetype)initWithHandler:(void(^)(SJEdgeControlButtonItemAction *action))handler;

@property (nonatomic, weak, readonly, nullable) id target;
@property (nonatomic, readonly, nullable) SEL action;
@property (nonatomic, copy, readonly, nullable) void(^handler)(SJEdgeControlButtonItemAction *action);
@end
NS_ASSUME_NONNULL_END
90 changes: 77 additions & 13 deletions SJVideoPlayer/Common/Utils/Adapters/Core/SJEdgeControlButtonItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @implementation SJEdgeControlButtonItem {
SJButtonItemPlaceholderType _placeholderType;
CGFloat _size;
BOOL _isFrameLayout;
NSMutableArray<SJEdgeControlButtonItemAction *> *_Nullable _actions;
}
- (instancetype)initWithTitle:(nullable NSAttributedString *)title
target:(nullable id)target
Expand All @@ -24,8 +25,9 @@ - (instancetype)initWithTitle:(nullable NSAttributedString *)title
self = [self initWithTag:tag];
if ( !self ) return nil;
_title = title;
_target = target;
_action = action;
if ( target != nil && action != NULL ) {
[self addAction:[SJEdgeControlButtonItemAction actionWithTarget:target action:action]];
}
return self;
}
- (instancetype)initWithImage:(nullable UIImage *)image
Expand All @@ -35,8 +37,9 @@ - (instancetype)initWithImage:(nullable UIImage *)image
self = [self initWithTag:tag];
if ( !self ) return nil;
_image = image;
_target = target;
_action = action;
if ( target != nil && action != NULL ) {
[self addAction:[SJEdgeControlButtonItemAction actionWithTarget:target action:action]];
}
return self;
}
- (instancetype)initWithCustomView:(nullable __kindof UIView *)customView
Expand All @@ -55,20 +58,41 @@ - (instancetype)initWithTag:(NSInteger)tag {
return self;
}

- (void)addTarget:(id)target action:(nonnull SEL)action {
_target = target;
_action = action;
- (nullable NSArray<SJEdgeControlButtonItemAction *> *)actions {
return _actions.count != 0 ? _actions : nil;
}

- (void)performAction {
if ( !_action ) return;
- (void)addAction:(SJEdgeControlButtonItemAction *)action {
if ( action != nil ) {
if ( _actions == nil ) {
_actions = NSMutableArray.array;
}
[_actions addObject:action];
}
}

- (void)removeAction:(SJEdgeControlButtonItemAction *)action {
if ( action != nil )
[_actions removeObject:action];
}

- (void)removeAllActions {
[_actions removeAllObjects];
}

- (void)performActions {
for ( SJEdgeControlButtonItemAction *action in _actions ) {
if ( action.handler != nil ) {
action.handler(action);
}
else if ( [action.target respondsToSelector:action.action] ) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if ( [_target respondsToSelector:_action] ) {
[_target performSelector:_action withObject:self];
[NSNotificationCenter.defaultCenter postNotificationName:SJEdgeControlButtonItemPerformedActionNotification object:self];
}
[action.target performSelector:action.action withObject:self];
#pragma clang diagnostic pop
}
}
[NSNotificationCenter.defaultCenter postNotificationName:SJEdgeControlButtonItemPerformedActionNotification object:self];
}
@end

Expand Down Expand Up @@ -98,6 +122,20 @@ - (CGFloat)size {
@end


#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@implementation SJEdgeControlButtonItem(SJDeprecated)
- (void)addTarget:(id)target action:(nonnull SEL)action {
[self removeAllActions];
[self addAction:[SJEdgeControlButtonItemAction actionWithTarget:target action:action]];
}

- (void)performAction {
[self performActions];
}
@end
#pragma clang diagnostic pop

@implementation SJEdgeControlButtonItem(FrameLayout)
+ (instancetype)frameLayoutWithCustomView:(__kindof UIView *)customView tag:(SJEdgeControlButtonItemTag)tag {
SJEdgeControlButtonItem *item = [[SJEdgeControlButtonItem alloc] initWithCustomView:customView tag:tag];
Expand All @@ -108,4 +146,30 @@ - (BOOL)isFrameLayout {
return _isFrameLayout;
}
@end

@implementation SJEdgeControlButtonItemAction
+ (instancetype)actionWithTarget:(id)target action:(SEL)action {
return [[self alloc] initWithTarget:target action:action];
}

+ (instancetype)actionWithHandler:(void(^)(SJEdgeControlButtonItemAction *action))handler {
return [[self alloc] initWithHandler:handler];
}

- (instancetype)initWithTarget:(id)target action:(SEL)action {
self = [super init];
if ( self ) {
_target = target;
_action = action;
}
return self;
}
- (instancetype)initWithHandler:(void(^)(SJEdgeControlButtonItemAction *action))handler {
self = [super init];
if ( self ) {
_handler = handler;
}
return self;
}
@end
NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event {
if ( item.isHidden == YES || item.alpha < 0.01 )
return NO;

if ( item.customView == nil && item.target == nil )
if ( item.customView == nil && item.actions == nil )
return NO;

return [super pointInside:point withEvent:event];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
}

- (void)performAction {
[_item performAction];
[_item performActions];
}

- (void)reloadItemIfNeeded {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ - (void)_addItemToTopAdapter {

- (void)_addItemToRightAdapter {
SJEdgeControlButtonItem *doneItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJRightItem_Done];
[doneItem addTarget:self action:@selector(clickedDoneItem:)];
[doneItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(clickedDoneItem:)]];
[self.rightAdapter addItem:doneItem];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ - (void)_addItemToTopAdapter {

- (void)_addItemToRightAdapter {
SJEdgeControlButtonItem *doneItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJRightItem_Done];
[doneItem addTarget:self action:@selector(clickedDoneItem:)];
[doneItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(clickedDoneItem:)]];
[self.rightAdapter addItem:doneItem];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ - (void)_setupViews {

- (void)_addItemToRightAdapter {
SJEdgeControlButtonItem *screenshotItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJClipsControlLayerRightItem_Screenshot];
[screenshotItem addTarget:self action:@selector(screenshotItemWasTapped)];
[screenshotItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(screenshotItemWasTapped)]];
[self.rightAdapter addItem:screenshotItem];

SJEdgeControlButtonItem *exportVideoItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJClipsControlLayerRightItem_ExportVideo];
[exportVideoItem addTarget:self action:@selector(exportVideoItemWasTapped)];
[exportVideoItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(exportVideoItemWasTapped)]];
[self.rightAdapter addItem:exportVideoItem];

SJEdgeControlButtonItem *exportGIFItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJClipsControlLayerRightItem_ExportGIF];
[exportGIFItem addTarget:self action:@selector(exportGIFItemWasTapped)];
[exportGIFItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(exportGIFItemWasTapped)]];
[self.rightAdapter addItem:exportGIFItem];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ - (void)exitControlLayer {
#pragma mark - item actions

- (void)_fixedBackButtonWasTapped {
[self.backItem performAction];
[self.backItem performActions];
}

- (void)_backItemWasTapped {
Expand Down Expand Up @@ -360,7 +360,7 @@ - (BOOL)videoPlayer:(__kindof SJBaseVideoPlayer *)videoPlayer gestureRecognizerS
if ( !CGRectContainsPoint(adapter.view.frame, point) ) return YES;

SJEdgeControlButtonItem *_Nullable item = [adapter itemAtPoint:point];
return item != nil ? ![item.target respondsToSelector:item.action] : YES;
return item != nil ? (item.actions.count == 0) : YES;
}

- (void)videoPlayer:(__kindof SJBaseVideoPlayer *)videoPlayer panGestureTriggeredInTheHorizontalDirection:(SJPanGestureRecognizerState)state progressTime:(NSTimeInterval)progressTime {
Expand Down Expand Up @@ -667,7 +667,7 @@ - (SJTimerControl *)lockStateTappedTimerControl {
- (SJEdgeControlButtonItem *)pictureInPictureItem API_AVAILABLE(ios(14.0)) {
if ( _pictureInPictureItem == nil ) {
_pictureInPictureItem = [SJEdgeControlButtonItem.alloc initWithTag:SJEdgeControlLayerTopItem_PictureInPicture];
[_pictureInPictureItem addTarget:self action:@selector(pictureInPictureItemWasTapped)];
[_pictureInPictureItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(pictureInPictureItemWasTapped)]];
}
return _pictureInPictureItem;
}
Expand Down Expand Up @@ -733,7 +733,7 @@ - (SJTimerControl *)dateTimerControl {
- (void)_addItemsToTopAdapter {
SJEdgeControlButtonItem *backItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJEdgeControlLayerTopItem_Back];
backItem.resetsAppearIntervalWhenPerformingItemAction = NO;
[backItem addTarget:self action:@selector(_backItemWasTapped)];
[backItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(_backItemWasTapped)]];
[self.topAdapter addItem:backItem];
_backItem = backItem;

Expand All @@ -745,7 +745,7 @@ - (void)_addItemsToTopAdapter {

- (void)_addItemsToLeftAdapter {
SJEdgeControlButtonItem *lockItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJEdgeControlLayerLeftItem_Lock];
[lockItem addTarget:self action:@selector(_lockItemWasTapped)];
[lockItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(_lockItemWasTapped)]];
[self.leftAdapter addItem:lockItem];

[self.leftAdapter reload];
Expand All @@ -754,7 +754,7 @@ - (void)_addItemsToLeftAdapter {
- (void)_addItemsToBottomAdapter {
// 播放按钮
SJEdgeControlButtonItem *playItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJEdgeControlLayerBottomItem_Play];
[playItem addTarget:self action:@selector(_playItemWasTapped)];
[playItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(_playItemWasTapped)]];
[self.bottomAdapter addItem:playItem];

SJEdgeControlButtonItem *liveItem = [[SJEdgeControlButtonItem alloc] initWithTag:SJEdgeControlLayerBottomItem_LIVEText];
Expand Down Expand Up @@ -803,7 +803,7 @@ - (void)_addItemsToBottomAdapter {
// 全屏按钮
SJEdgeControlButtonItem *fullItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJEdgeControlLayerBottomItem_Full];
fullItem.resetsAppearIntervalWhenPerformingItemAction = NO;
[fullItem addTarget:self action:@selector(_fullItemWasTapped)];
[fullItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(_fullItemWasTapped)]];
[self.bottomAdapter addItem:fullItem];

[self.bottomAdapter reload];
Expand All @@ -817,7 +817,7 @@ - (void)_addItemsToCenterAdapter {
UILabel *replayLabel = [UILabel new];
replayLabel.numberOfLines = 0;
SJEdgeControlButtonItem *replayItem = [SJEdgeControlButtonItem frameLayoutWithCustomView:replayLabel tag:SJEdgeControlLayerCenterItem_Replay];
[replayItem addTarget:self action:@selector(_replayItemWasTapped)];
[replayItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(_replayItemWasTapped)]];
[self.centerAdapter addItem:replayItem];
[self.centerAdapter reload];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event
item = [self->_centerAdapter itemAtPoint:[self convertPoint:point toView:self->_centerAdapter.view]];
}

if ( item.action != NULL || item.customView != nil ) {
if ( item.actions != nil || item.customView != nil ) {
gesture.enabled = NO;
dispatch_async(dispatch_get_main_queue(), ^{
gesture.enabled = YES;
Expand Down Expand Up @@ -94,7 +94,7 @@ - (void)_setupView {
[self.topAdapter addItem:fillItem];

SJEdgeControlButtonItem *closeItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJFloatSmallViewControlLayerTopItem_Close];
[closeItem addTarget:self action:@selector(tappedCloseItem:)];
[closeItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(tappedCloseItem:)]];
closeItem.image = SJVideoPlayerConfigurations.shared.resources.floatSmallViewCloseImage;
[self.topAdapter addItem:closeItem];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ - (void)_setupView {
id<SJVideoPlayerLocalizedStrings> strings = SJVideoPlayerConfigurations.shared.localizedStrings;

SJEdgeControlButtonItem *backItem = [SJEdgeControlButtonItem placeholderWithType:SJButtonItemPlaceholderType_49x49 tag:SJNotReachableControlLayerTopItem_Back];
[backItem addTarget:self action:@selector(backItemWasTapped:)];
[backItem addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(backItemWasTapped:)]];
backItem.image = sources.backImage;
[self.topAdapter addItem:backItem];
[self.topAdapter reload];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ - (void)setAssets:(nullable NSArray<SJVideoPlayerURLAsset *> *)assets {
NSMutableArray<SJEdgeControlButtonItem *> *m = [NSMutableArray new];
[_assets enumerateObjectsUsingBlock:^(SJVideoPlayerURLAsset * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
SJEdgeControlButtonItem *item = [SJEdgeControlButtonItem placeholderWithSize:38 tag:idx];
[item addTarget:self action:@selector(_clickedItem:)];
[item addAction:[SJEdgeControlButtonItemAction actionWithTarget:self action:@selector(_clickedItem:)]];
[m addObject:item];
}];
self.items = m;
Expand Down
Loading

0 comments on commit 453abf1

Please sign in to comment.