Skip to content

Commit 3487778

Browse files
shwetsolankiwojteg1337
authored andcommitted
feat(slider): adds support for touch to seek to iOS slider (#117)
* feat(slider): adds support for touch to seek to iOS slider * refactor(slider): adds tap to seek for ios
1 parent 198a6ac commit 3487778

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/ios/RNCSlider.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
@implementation RNCSlider
1111
{
1212
float _unclippedValue;
13+
UITapGestureRecognizer * tapGesturer;
14+
}
15+
16+
- (instancetype)initWithFrame:(CGRect)frame
17+
{
18+
self = [super initWithFrame:frame];
19+
if (self) {
20+
tapGesturer = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(tapHandler:)];
21+
[tapGesturer setNumberOfTapsRequired: 1];
22+
[self addGestureRecognizer:tapGesturer];
23+
}
24+
return self;
25+
}
26+
- (void)tapHandler:(UITapGestureRecognizer *)gesture {
27+
CGPoint touchPoint = [gesture locationInView:self];
28+
[self setValue:touchPoint.x / self.bounds.size.width animated: YES];
1329
}
1430

1531
- (void)setValue:(float)value
@@ -99,4 +115,8 @@ - (void)setInverted:(BOOL)inverted
99115
}
100116
}
101117

118+
- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
119+
return YES;
120+
}
121+
102122
@end

0 commit comments

Comments
 (0)