Skip to content

Commit b6907dc

Browse files
committed
Added RTL to view extension. Fixed protect level in view extension.
1 parent 9c2852b commit b6907dc

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

Sources/SparrowKit/UIKit/Extensions/UIViewExtension.swift

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
#if canImport(UIKit) && (os(iOS) || os(tvOS))
2323
import UIKit
2424

25-
public extension UIView {
25+
extension UIView {
2626

2727
/**
2828
SparrowKit: Init `UIView` object with background color.
2929

3030
- parameter backgroundColor: Color which using for background.
3131
*/
32-
convenience init(backgroundColor color: UIColor) {
32+
public convenience init(backgroundColor color: UIColor) {
3333
self.init()
3434
backgroundColor = color
3535
}
@@ -42,7 +42,7 @@ public extension UIView {
4242
- warning:
4343
If view not added to any controller, return nil.
4444
*/
45-
var viewController: UIViewController? {
45+
open var viewController: UIViewController? {
4646
weak var parentResponder: UIResponder? = self
4747
while parentResponder != nil {
4848
parentResponder = parentResponder!.next
@@ -58,21 +58,21 @@ public extension UIView {
5858

5959
- parameter subviews: Array of `UIView` objects.
6060
*/
61-
func addSubviews(_ subviews: [UIView]) {
61+
open func addSubviews(_ subviews: [UIView]) {
6262
subviews.forEach { addSubview($0) }
6363
}
6464

6565
/**
6666
SparrowKit: Remove all subviews.
6767
*/
68-
func removeSubviews() {
68+
open func removeSubviews() {
6969
subviews.forEach { $0.removeFromSuperview() }
7070
}
7171

7272
/**
7373
SparrowKit: Take screenshoot of view as `UIImage`.
7474
*/
75-
var screenshot: UIImage? {
75+
open var screenshot: UIImage? {
7676
UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, 0)
7777
defer {
7878
UIGraphicsEndImageContext()
@@ -82,6 +82,16 @@ public extension UIView {
8282
return UIGraphicsGetImageFromCurrentImageContext()
8383
}
8484

85+
/**
86+
SparrowKit: If view has LTR interface.
87+
*/
88+
open var ltr: Bool { effectiveUserInterfaceLayoutDirection == .leftToRight }
89+
90+
/**
91+
SparrowKit: If view has TRL interface.
92+
*/
93+
open var rtl: Bool { effectiveUserInterfaceLayoutDirection == .rightToLeft }
94+
8595
// MARK: - Layout
8696

8797
/**
@@ -90,7 +100,7 @@ public extension UIView {
90100
- warning:
91101
Fit view can be return zero height. View shoud support it.
92102
*/
93-
func setWidthAndFit(width: CGFloat) {
103+
open func setWidthAndFit(width: CGFloat) {
94104
frame.setWidth(width)
95105
sizeToFit()
96106
}
@@ -101,7 +111,7 @@ public extension UIView {
101111
- warning:
102112
If current view have not superview, center X is set to zero.
103113
*/
104-
func setXCenter() {
114+
open func setXCenter() {
105115
center.x = (superview?.frame.width ?? 0) / 2
106116
}
107117

@@ -111,7 +121,7 @@ public extension UIView {
111121
- warning:
112122
If current view have not superview, center Y is set to zero.
113123
*/
114-
func setYCenter() {
124+
open func setYCenter() {
115125
center.y = (superview?.frame.height ?? 0) / 2
116126
}
117127

@@ -121,7 +131,7 @@ public extension UIView {
121131
- warning:
122132
If current view have not superview, center is set to zero.
123133
*/
124-
func setToCenter() {
134+
open func setToCenter() {
125135
setXCenter()
126136
setYCenter()
127137
}
@@ -131,7 +141,7 @@ public extension UIView {
131141
/**
132142
SparrowKit: Margins of readable frame.
133143
*/
134-
var readableMargins: UIEdgeInsets {
144+
open var readableMargins: UIEdgeInsets {
135145
let layoutFrame = readableContentGuide.layoutFrame
136146
return UIEdgeInsets(
137147
top: layoutFrame.origin.y,
@@ -144,21 +154,21 @@ public extension UIView {
144154
/**
145155
SparrowKit: Readable width of current view without horizontal readable margins.
146156
*/
147-
var readableWidth: CGFloat {
157+
open var readableWidth: CGFloat {
148158
return readableContentGuide.layoutFrame.width
149159
}
150160

151161
/**
152162
SparrowKit: Readable height of current view without vertical readable margins.
153163
*/
154-
var readableHeight: CGFloat {
164+
open var readableHeight: CGFloat {
155165
return readableContentGuide.layoutFrame.height
156166
}
157167

158168
/**
159169
SparrowKit: Readable frame of current view without vertical and horizontal readable margins.
160170
*/
161-
var readableFrame: CGRect {
171+
open var readableFrame: CGRect {
162172
let margins = readableMargins
163173
return CGRect.init(x: margins.left, y: margins.top, width: readableWidth, height: readableHeight)
164174
}
@@ -168,7 +178,7 @@ public extension UIView {
168178
/**
169179
SparrowKit: Width of current view without horizontal layout margins.
170180
*/
171-
var layoutWidth: CGFloat {
181+
open var layoutWidth: CGFloat {
172182
// ver 1
173183
// Depricated becouse sometimes return invalid size
174184
//return layoutMarginsGuide.layoutFrame.width
@@ -180,7 +190,7 @@ public extension UIView {
180190
/**
181191
SparrowKit: Height of current view without vertical layout margins.
182192
*/
183-
var layoutHeight: CGFloat {
193+
open var layoutHeight: CGFloat {
184194
// ver 1
185195
// Depricated becouse sometimes return invalid size
186196
//return layoutMarginsGuide.layoutFrame.height
@@ -192,7 +202,7 @@ public extension UIView {
192202
/**
193203
SparrowKit: Frame of current view without horizontal and vertical layout margins.
194204
*/
195-
var layoutFrame: CGRect {
205+
open var layoutFrame: CGRect {
196206
return CGRect.init(x: layoutMargins.left, y: layoutMargins.top, width: layoutWidth, height: layoutHeight)
197207
}
198208

@@ -202,15 +212,15 @@ public extension UIView {
202212
- warning:
203213
If view not have superview, nothing happen.
204214
*/
205-
func setEqualSuperviewBounds() {
215+
open func setEqualSuperviewBounds() {
206216
guard let superview = self.superview else { return }
207217
frame = superview.bounds
208218
}
209219

210220
/**
211221
SparrowKit: Set view equal frame to superview frame via `autoresizingMask`.
212222
*/
213-
func setEqualSuperviewBoundsWithAutoresizingMask() {
223+
open func setEqualSuperviewBoundsWithAutoresizingMask() {
214224
autoresizingMask = [.flexibleWidth, .flexibleHeight]
215225
}
216226

@@ -220,7 +230,7 @@ public extension UIView {
220230
- warning:
221231
If view not have superview, constraints will not be added.
222232
*/
223-
func setEqualSuperviewBoundsWithAutoLayout() {
233+
open func setEqualSuperviewBoundsWithAutoLayout() {
224234
guard let superview = self.superview else { return }
225235
translatesAutoresizingMaskIntoConstraints = false
226236
NSLayoutConstraint.activate([
@@ -237,7 +247,7 @@ public extension UIView {
237247
- warning:
238248
If view not have superview, constraints will not be added.
239249
*/
240-
func setEqualSuperviewMarginsWithAutoLayout() {
250+
open func setEqualSuperviewMarginsWithAutoLayout() {
241251
guard let superview = self.superview else { return }
242252
translatesAutoresizingMaskIntoConstraints = false
243253
NSLayoutConstraint.activate([
@@ -253,7 +263,7 @@ public extension UIView {
253263
/**
254264
SparrowKit: Wrapper for layer property `masksToBounds`.
255265
*/
256-
var masksToBounds: Bool {
266+
open var masksToBounds: Bool {
257267
get {
258268
return layer.masksToBounds
259269
}
@@ -271,7 +281,7 @@ public extension UIView {
271281
- parameter corners: Case of `UIRectCorner`
272282
- parameter radius: Amount of radius.
273283
*/
274-
func roundCorners(_ corners: UIRectCorner = .allCorners, radius: CGFloat) {
284+
open func roundCorners(_ corners: UIRectCorner = .allCorners, radius: CGFloat) {
275285
let maskPath = UIBezierPath(
276286
roundedRect: bounds,
277287
byRoundingCorners: corners,
@@ -288,14 +298,14 @@ public extension UIView {
288298
- important:
289299
Need call after changed frame. Better leave it in `layoutSubviews` method.
290300
*/
291-
func roundCorners() {
301+
open func roundCorners() {
292302
layer.cornerRadius = min(frame.width, frame.height) / 2
293303
}
294304

295305
/**
296306
SparrowKit: Wrapper for layer property `borderColor`.
297307
*/
298-
var borderColor: UIColor? {
308+
open var borderColor: UIColor? {
299309
get {
300310
guard let color = layer.borderColor else { return nil }
301311
return UIColor(cgColor: color)
@@ -314,7 +324,7 @@ public extension UIView {
314324
/**
315325
SparrowKit: Wrapper for layer property `borderWidth`.
316326
*/
317-
var borderWidth: CGFloat {
327+
open var borderWidth: CGFloat {
318328
get {
319329
return layer.borderWidth
320330
}
@@ -331,7 +341,7 @@ public extension UIView {
331341
- parameter offset: Vertical and horizontal offset from center fro shadow.
332342
- parameter opacity: Alpha for shadow view.
333343
*/
334-
func addShadow(ofColor color: UIColor, radius: CGFloat, offset: CGSize, opacity: Float) {
344+
open func addShadow(ofColor color: UIColor, radius: CGFloat, offset: CGSize, opacity: Float) {
335345
layer.shadowColor = color.cgColor
336346
layer.shadowOffset = offset
337347
layer.shadowRadius = radius
@@ -345,7 +355,7 @@ public extension UIView {
345355

346356
- parameter amount: Amount of paralax effect.
347357
*/
348-
func addParalax(amount: CGFloat) {
358+
open func addParalax(amount: CGFloat) {
349359
motionEffects.removeAll()
350360
let horizontal = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis)
351361
horizontal.minimumRelativeValue = -amount
@@ -363,7 +373,7 @@ public extension UIView {
363373
/**
364374
SparrowKit: Remove paralax.
365375
*/
366-
func removeParalax() {
376+
open func removeParalax() {
367377
motionEffects.removeAll()
368378
}
369379

@@ -375,8 +385,8 @@ public extension UIView {
375385
- parameter duration: Duration of animation.
376386
- parameter completion: Completion when animation ended.
377387
*/
378-
func fadeIn(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {
379-
UIView.animate(withDuration: duration, animations: {
388+
open func fadeIn(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {
389+
UIView.animate(withDuration: duration, delay: .zero, options: [.beginFromCurrentState, .allowUserInteraction], animations: {
380390
self.alpha = 1
381391
}, completion: completion)
382392
}
@@ -387,8 +397,8 @@ public extension UIView {
387397
- parameter duration: Duration of animation.
388398
- parameter completion: Completion when animation ended.
389399
*/
390-
func fadeOut(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {
391-
UIView.animate(withDuration: duration, animations: {
400+
open func fadeOut(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {
401+
UIView.animate(withDuration: duration, delay: .zero, options: [.beginFromCurrentState, .allowUserInteraction], animations: {
392402
self.alpha = 0
393403
}, completion: completion)
394404
}

SparrowKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'SparrowKit'
4-
s.version = '3.2.0'
4+
s.version = '3.2.1'
55
s.summary = 'Collection of native Swift extensions to boost your development. Support tvOS and watchOS.'
66
s.homepage = 'https://github.com/ivanvorobei/SparrowKit'
77
s.source = { :git => 'https://github.com/ivanvorobei/SparrowKit.git', :tag => s.version }

0 commit comments

Comments
 (0)