Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions HCSStarRatingView/HCSStarRatingView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

typedef BOOL(^HCSStarRatingViewShouldBeginGestureRecognizerBlock)(UIGestureRecognizer *gestureRecognizer);

@protocol HCSStarRatingViewDelegate;

IB_DESIGNABLE
@interface HCSStarRatingView : UIControl
@property (nonatomic) IBInspectable NSUInteger maximumValue;
Expand All @@ -42,5 +44,13 @@ IB_DESIGNABLE
@property (nonatomic, strong) IBInspectable UIImage *emptyStarImage;
@property (nonatomic, strong) IBInspectable UIImage *halfStarImage;
@property (nonatomic, strong) IBInspectable UIImage *filledStarImage;

@property (nonatomic, weak) IBOutlet id<HCSStarRatingViewDelegate> delegate;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that you made this an outlet! ❤️

@end

@protocol HCSStarRatingViewDelegate <NSObject>

@optional
- (void)userFinishedRatingOnView:(HCSStarRatingView*)ratingView withRating:(CGFloat)value;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to something like - (void)ratingView:(HCSStarRatingView *)ratingView userFinishedRatingWithValue:(CGFloat)value;

Makes more sense to me as a delegate API.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I also think it's kinda clunky at the moment.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, in that case I'll merge the PR and update the pod once this is changed. Thanks! 😄

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this could just be - (void)ratingViewFinishedRating:(HCSStarRatingView *)ratingView, since whoever's implementing can get the value from ratingView.


@end
6 changes: 6 additions & 0 deletions HCSStarRatingView/HCSStarRatingView.m
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ - (void)_handleTouch:(UITouch *)touch {
[self setValue:value sendValueChangedAction:_continuous];
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
if ([self.delegate respondsToSelector:@selector(userFinishedRatingOnView:withRating:)]) {
[self.delegate userFinishedRatingOnView:self withRating:self.value];
}
}

#pragma mark - First responder

- (BOOL)canBecomeFirstResponder {
Expand Down