Comments (9)
Hi @omegaes, sorry but currently PinLayout doesn't support RTL. But this would be easy to implement by adding more methods (ex: pin.start(), pin.end(), pin.before(of: UIView), pin.after(of: UIView), ...) and add an extra method pin.direction(LTR/RTL). I would be more than happy to review a PR. Anyway I'll add this to my TODO list.
from pinlayout.
I did it, I will open a PR for it, I did it in this way, adding more start and end edges, start and end anchors, etc ..
from pinlayout.
I'll check your PR, but I think that maybe another possibility would be to create another interface for RTL support, I'm little affraid/concerned that adding RTL to the existing API may impact its clearlyness. Another solution also would be to have a separate branch from it. But thanks for your future PR. Ah also, please note that this API would need to match my other project FlexLayout. This project purpose is to wrap Yoga's flexbox implementation, you can see this project still in development here https://github.com/lucdion/FlexLayout/tree/dev
from pinlayout.
Hi @omegaes I though about it again a little bit, and finally I would finally add RTL support directly in the current API, not another protocol nor another branch. If you want to share your branch, I could also helps you to complete it.
My idea was to add a global method that would set the layout direction for all views, ex: PinLayoutDirection(.rtl)
.
It could be also possible to overwrite this default layout direction when layouting a view: ex: view.layoutDirection(.ltr).start(10).end(10)
. Do you think this method would be useful?
For method implementation, something like that should be nice, for example the `start(_ value: CGFloat):
func start(_ value: CGFloat) -> PinLayout {
func context() -> String { return "start(\(value))" }
switch layoutDirection {
case .ltr: setLeft(value, context)
case .rtl: setRight(value, context)
}
return self
}
What do you think about all this?
from pinlayout.
I did an extension for PinLayout contains functions like:
`@discardableResult func marginStart(_ value: CGFloat) -> PinLayout {
if isLtr() {
marginLeft(value)
} else {
marginRight(value)
}
return self
}
@discardableResult func marginEnd(_ value: CGFloat) -> PinLayout {
if isLtr() {
marginRight(value)
} else {
marginLeft(value)
}
return self
}
so I implement isLtr in my way, reading language settings from defaults also I created extensions for AnchorList and EdgeList
var start : HorizontalEdge {
if (isLtr()) {
return left
} else {
return right
}
}
var end : HorizontalEdge {
if (isLtr()) {
return right
} else {
return left
}
}`
`
var topStart : Anchor {
if (isLtr()) {
return topLeft
} else {
return topRight
}
}
var topEnd : Anchor {
if (isLtr()) {
return topRight
} else {
return topLeft
}
}
var bottomStart : Anchor {
if (isLtr()) {
return bottomLeft
} else {
return bottomRight
}
}
var bottomEnd : Anchor {
if (isLtr()) {
return bottomRight
} else {
return bottomLeft
}
}
var startCenter : Anchor {
if (isLtr()) {
return leftCenter
} else {
return rightCenter
}
}
var endCenter : Anchor {
if (isLtr()) {
return rightCenter
} else {
return leftCenter
}
}
`
from pinlayout.
@omegaes would you like to share with me your extension code, including your isltr method. I could integrate it.
Thanks
from pinlayout.
sorry for delay, I hadn't no time to fork and open new PR, here is my code:
`
extension EdgeList {
func isLtr () -> Bool {
if DataManager.shared.getUserLang()! == "ar" {
return false
}
return true
}
var start : HorizontalEdge {
if (isLtr()) {
return left
} else {
return right
}
}
var end : HorizontalEdge {
if (isLtr()) {
return right
} else {
return left
}
}
}
extension AnchorList {
func isLtr () -> Bool {
if DataManager.shared.getUserLang()! == "ar" {
return false
}
return true
}
var topStart : Anchor {
if (isLtr()) {
return topLeft
} else {
return topRight
}
}
var topEnd : Anchor {
if (isLtr()) {
return topRight
} else {
return topLeft
}
}
var bottomStart : Anchor {
if (isLtr()) {
return bottomLeft
} else {
return bottomRight
}
}
var bottomEnd : Anchor {
if (isLtr()) {
return bottomRight
} else {
return bottomLeft
}
}
var startCenter : Anchor {
if (isLtr()) {
return leftCenter
} else {
return rightCenter
}
}
var endCenter : Anchor {
if (isLtr()) {
return rightCenter
} else {
return leftCenter
}
}
}
extension PinLayout {
func isLtr () -> Bool {
if DataManager.shared.getUserLang()! == "ar" {
return false
}
return true
}
@discardableResult func start() -> PinLayout {
if isLtr() {
left()
} else {
right()
}
return self
}
@discardableResult func end() -> PinLayout {
if isLtr() {
right()
} else {
left()
}
return self
}
@discardableResult func start(_ value: CGFloat) -> PinLayout {
if isLtr() {
left(value)
} else {
right(value)
}
return self
}
@discardableResult func end(_ value: CGFloat) -> PinLayout {
if isLtr() {
right(value)
} else {
left(value)
}
return self
}
@discardableResult func start(_ percent: Percent) -> PinLayout {
if isLtr() {
left(percent)
} else {
right(percent)
}
return self
}
@discardableResult func end(_ percent: Percent) -> PinLayout {
if isLtr() {
right(percent)
} else {
left(percent)
}
return self
}
@discardableResult func start(to edge: HorizontalEdge) -> PinLayout {
if isLtr() {
left(to : edge)
} else {
right(to : edge)
}
return self
}
@discardableResult func end(to edge: HorizontalEdge) -> PinLayout {
if isLtr() {
right(to : edge)
} else {
left(to : edge)
}
return self
}
@discardableResult func topStart(to anchor: Anchor) -> PinLayout {
if isLtr() {
topLeft(to : anchor)
} else {
topRight(to : anchor)
}
return self
}
@discardableResult func topEnd(to anchor: Anchor) -> PinLayout {
if isLtr() {
topRight(to : anchor)
} else {
topLeft(to : anchor)
}
return self
}
@discardableResult func topStart() -> PinLayout {
if isLtr() {
topLeft()
} else {
topRight()
}
return self
}
@discardableResult func topEnd() -> PinLayout {
if isLtr() {
topRight()
} else {
topLeft()
}
return self
}
@discardableResult func startCenter(to anchor: Anchor) -> PinLayout {
if isLtr() {
leftCenter(to : anchor)
} else {
rightCenter(to : anchor)
}
return self
}
@discardableResult func endCenter(to anchor: Anchor) -> PinLayout {
if isLtr() {
rightCenter(to : anchor)
} else {
leftCenter(to : anchor)
}
return self
}
@discardableResult func startCenter() -> PinLayout {
if isLtr() {
leftCenter()
} else {
rightCenter()
}
return self
}
@discardableResult func endCenter() -> PinLayout {
if isLtr() {
rightCenter()
} else {
leftCenter()
}
return self
}
@discardableResult func bottomStart(to anchor: Anchor) -> PinLayout {
if isLtr() {
bottomLeft(to : anchor)
} else {
bottomRight(to : anchor)
}
return self
}
@discardableResult func bottomEnd(to anchor: Anchor) -> PinLayout {
if isLtr() {
bottomRight(to : anchor)
} else {
bottomLeft(to : anchor)
}
return self
}
@discardableResult func bottomStart() -> PinLayout {
if isLtr() {
bottomLeft()
} else {
bottomRight()
}
return self
}
@discardableResult func bottomEnd() -> PinLayout {
if isLtr() {
bottomRight()
} else {
bottomLeft()
}
return self
}
@discardableResult func marginStart(_ value: CGFloat) -> PinLayout {
if isLtr() {
marginLeft(value)
} else {
marginRight(value)
}
return self
}
@discardableResult func marginEnd(_ value: CGFloat) -> PinLayout {
if isLtr() {
marginRight(value)
} else {
marginLeft(value)
}
return self
}
}
`
from pinlayout.
@omegaes I've implemented RTL support, but not everything has been tested yet. Everything is in the branch https://github.com/mirego/PinLayout/tree/add_rtl_support
from pinlayout.
@omegaes RTL support has been integrated in the master branch https://github.com/mirego/PinLayout/releases/tag/1.2.0
from pinlayout.
Related Issues (20)
- "view.keyboardLayoutGuide.layoutFrame" is (0,0,0,0) before using "view.pin.keyboardMargins".
- How do I auto-size the container of image view and label? HOT 5
- invalid parameter not satisfying: !cgsizeequaltosize(size, cgsizezero) HOT 7
- Can I use autoSizeThatFits on collection view cell ? HOT 5
- Can I let View A cover B half? HOT 2
- Crash: PinLayout.swift - Line 1236 HOT 7
- How to align base line of two UILabels?
- Interview partners for research about communication in GitHub projects wanted
- H
- Unable to build with Carthage HOT 2
- Crash: PinLayout.swift - Line 1236
- How to use with NSSplitViewController? HOT 3
- How to add separator line below row/cell?
- UIButton with image .aspectRation() not work HOT 1
- Attach view to different edges or use priorities
- Document missing link HOT 1
- ABI stability for swift evolution support for different swift versions
- Problem with sizeToFit - autoSizing HOT 1
- Edge offsets (.top(x), .bottom(x), .start(x), .end(x)) aren't used in autoSizeThatFits HOT 1
- Work on watchOS? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pinlayout.