Skip to content

Commit

Permalink
fix: iOS inverted tap-to-seek in RTL (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
AymanHossam authored Jan 17, 2025
1 parent 2f07d2d commit a0bb8b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion package/ios/RNCSliderComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ - (void)tapHandler:(UITapGestureRecognizer *)gesture {

CGPoint touchPoint = [gesture locationInView:slider];
float rangeWidth = slider.maximumValue - slider.minimumValue;
float sliderPercent = touchPoint.x / slider.bounds.size.width;

float sliderPercent;
if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:slider.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft) {
sliderPercent = 1.0 - (touchPoint.x / slider.bounds.size.width);
} else {
sliderPercent = touchPoint.x / slider.bounds.size.width;
}

slider.lastValue = slider.value;
float value = slider.minimumValue + (rangeWidth * sliderPercent);

Expand Down
9 changes: 8 additions & 1 deletion package/ios/RNCSliderManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ - (void)tapHandler:(UITapGestureRecognizer *)gesture {

CGPoint touchPoint = [gesture locationInView:slider];
float rangeWidth = slider.maximumValue - slider.minimumValue;
float sliderPercent = touchPoint.x / slider.bounds.size.width;

float sliderPercent;
if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:slider.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft) {
sliderPercent = 1.0 - (touchPoint.x / slider.bounds.size.width);
} else {
sliderPercent = touchPoint.x / slider.bounds.size.width;
}

slider.lastValue = slider.value;
float value = slider.minimumValue + (rangeWidth * sliderPercent);

Expand Down

0 comments on commit a0bb8b5

Please sign in to comment.