no-comment / SlideButton

SwiftUI package that provides a customizable slide button that can be swiped to unlock or perform an action
MIT License
24 stars 6 forks source link

SlideButton does not work with RTL languages #4

Closed dabear closed 8 months ago

dabear commented 8 months ago

SlideButton does not appear to be working with apps that use right to left wording. The Indicator appears right aligned instead of left aligned in its default state, making it impossible to slide the button correctly.

First reported it here: https://github.com/LoopKit/Loop/issues/2105

image

We've found a workaround, but it might not be the best solution, by adding this to a view containing a slidebutton:

.environment(\.layoutDirection, .leftToRight)
dabear commented 8 months ago

applying .flipsForRightToLeftLayoutDirection(true) on the slidebutton seems to fix the logic of the slidebutton for RTL languages, but it also flips the text in the slidebutton (which is probably unwanted behavior). @mikakruschel @cameronshemilt any thoughts?

mikakruschel commented 8 months ago

I think there would be two options:

  1. Fix the layout and have it always be a swipe left-to-right (by overwriting layoutDirection, as you suggested).
  2. Read the layoutDirection from the SwiftUI environment, and based on that, change the code in the gesture.

I think the first option would be better, but I'm not sure how the 'swipe-to-unlock' gesture should work in RTL languages.

dabear commented 8 months ago

the system level slider (used by iOS for confirming to a user to turn off the phone) swipes right to left for RTL languages. We should probably mimic that b havior. Btw I've also posted reproduction instructions in the linked Loop issue.

dabear commented 8 months ago

Trying to fix the math as indicated in 2). Will publish a PR once I'v cleaned it up and tested it a bit more: https://github.com/no-comment/SlideButton/compare/main...dabear:SlideButton:fixes?expand=1