0xLet / SwiftUIKit

📱 UIKit code that is fun to write
https://0xlet.github.io/SwiftUIKit/
MIT License
74 stars 6 forks source link

Add particular layer modifiers as separated methods. #108

Closed Oschly closed 4 years ago

Oschly commented 4 years ago

Instead of using single layer modifier to edit view's layer:

View()
   .layer { 
      $0.borderWidth = 10
   }

We can use that syntax:

View()
   .border(width: 10)

There's method named layer() left to give programmer more possibilities to work on layer than new methods allow to, but it's a rare case and shouldn't be used until needed.

0xLeif commented 4 years ago

@Oschly Looking through this I was thinking it might be better to have all the layer modifier functions named layer and their parameters different.

for example instead of

View()
   .border(width: 10)

it could be

View()
   .layer(borderWidth: 10)

Mainly thought this when I saw layer.backgroundColor.

https://github.com/Oschly/SwiftUIKit/blob/0ad1cac10119e8861eb3d336602f7404c7842f10/Sources/SwiftUIKit/Extensions/UIView%2BSwiftUIKit.swift#L347-L354

and we already have

https://github.com/0xLeif/SwiftUIKit/blob/faba15f99f3726954f3330939868880b164a52d7/Sources/SwiftUIKit/Extensions/UIView%2BSwiftUIKit.swift#L238-L243

Also I'd feel better if these moved into their own extension file... CALayer+SwiftUIKit.swift

0xLeif commented 4 years ago

Also let's switch this to the develop branch too.

0xLeif commented 4 years ago

@Oschly Looks great! Could you merge in the latest of develop. After that I can merge it in.

Only question is why did you remove layer(backgroundColor:)

When I was referring View().background(color: .blue) https://github.com/0xLeif/SwiftUIKit/blob/faba15f99f3726954f3330939868880b164a52d7/Sources/SwiftUIKit/Extensions/UIView%2BSwiftUIKit.swift#L238-L243

I still think we should have a layer modifier.

View().layer(backgroundColor: .red)

Oschly commented 4 years ago

Thanks! I will move that method back within develop branch wtih rest of the modifiers. I somehow understood that we don't need .layer(backgroundColor:) as we have just .background(color:).

Oschly commented 4 years ago

Moved to #110