8b8753fbd4d7bea56920a3eb08f450e26807595c
[mirrors/VoiceChatSdk_iOS.git] /
1 //
2 //  IQUIScrollView+Additions.swift
3 //  https://github.com/hackiftekhar/IQKeyboardManager
4 //  Copyright (c) 2013-24 Iftekhar Qurashi.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23
24 import UIKit
25
26 @available(iOSApplicationExtension, unavailable)
27 @MainActor
28 private struct AssociatedKeys {
29     static var ignoreScrollingAdjustment: Int = 0
30     static var ignoreContentInsetAdjustment: Int = 0
31     static var restoreContentOffset: Int = 0
32 }
33
34 // swiftlint:disable identifier_name
35 // swiftlint:disable unused_setter_value
36 @available(iOSApplicationExtension, unavailable)
37 extension UIScrollView: IQKeyboardManagerCompatible {
38
39     // This property is explicitly written otherwise we were having
40     // compilation error when archiving
41     public var iq: IQKeyboardManagerWrapper<UIView> {
42         get { IQKeyboardManagerWrapper(self) }
43         set {}
44     }
45 }
46 // swiftlint:enable unused_setter_value
47 // swiftlint:enable identifier_name
48
49 @available(iOSApplicationExtension, unavailable)
50 @MainActor
51 public extension IQKeyboardManagerWrapper where Base: UIScrollView {
52
53     /**
54      If YES, then scrollview will ignore scrolling (simply not scroll it) for adjusting textfield position.
55      Default is NO.
56      */
57     var ignoreScrollingAdjustment: Bool {
58         get {
59             return objc_getAssociatedObject(base, &AssociatedKeys.ignoreScrollingAdjustment) as? Bool ?? false
60         }
61         set(newValue) {
62             objc_setAssociatedObject(base, &AssociatedKeys.ignoreScrollingAdjustment,
63                                      newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
64         }
65     }
66
67     /**
68      If YES, then scrollview will ignore content inset adjustment (simply not updating it) when keyboard is shown.
69      Default is NO.
70      */
71     var ignoreContentInsetAdjustment: Bool {
72         get {
73             return objc_getAssociatedObject(base, &AssociatedKeys.ignoreContentInsetAdjustment) as? Bool ?? false
74         }
75         set(newValue) {
76             objc_setAssociatedObject(base, &AssociatedKeys.ignoreContentInsetAdjustment,
77                                      newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
78         }
79     }
80
81     /**
82      To set customized distance from keyboard for textField/textView. Can't be less than zero
83      */
84     var restoreContentOffset: Bool {
85         get {
86             return objc_getAssociatedObject(base, &AssociatedKeys.restoreContentOffset) as? Bool ?? false
87         }
88         set(newValue) {
89             objc_setAssociatedObject(base, &AssociatedKeys.restoreContentOffset,
90                                      newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
91         }
92     }
93 }
94
95 // swiftlint:disable unused_setter_value
96 @available(iOSApplicationExtension, unavailable)
97 @objc public extension UIScrollView {
98     @available(*, unavailable, renamed: "iq.ignoreScrollingAdjustment")
99     var shouldIgnoreScrollingAdjustment: Bool {
100         get { false }
101         set { }
102     }
103
104     @available(*, unavailable, renamed: "iq.ignoreContentInsetAdjustment")
105     var shouldIgnoreContentInsetAdjustment: Bool {
106         get { false }
107         set { }
108     }
109
110     @available(*, unavailable, renamed: "iq.restoreContentOffset")
111     var shouldRestoreScrollViewContentOffset: Bool {
112         get { false }
113         set { }
114     }
115 }
116 // swiftlint:enable unused_setter_value