@momo-kits/native-kits 0.152.1-beta.2 → 0.152.2-beta.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/package.json +7 -6
  2. package/shared/build.gradle.kts +74 -0
  3. package/CODE_OF_CONDUCT.md +0 -133
  4. package/CONTRIBUTING.md +0 -114
  5. package/LICENSE +0 -20
  6. package/README.md +0 -7
  7. package/build.gradle.kts +0 -32
  8. package/compose/MoMoComposeKits.podspec +0 -54
  9. package/compose/build.gradle.kts +0 -149
  10. package/compose/src/androidMain/AndroidManifest.xml +0 -2
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -105
  12. package/compose/src/commonMain/composeResources/files/lottie_circle_loader.json +0 -1
  13. package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
  14. package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
  15. package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
  16. package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
  17. package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
  18. package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
  19. package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
  20. package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
  21. package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
  22. package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
  23. package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
  24. package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
  25. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
  26. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +0 -57
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +0 -201
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +0 -222
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +0 -48
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +0 -86
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +0 -76
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +0 -76
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +0 -306
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +0 -33
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -715
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +0 -214
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +0 -235
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +0 -69
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -77
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -27
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -334
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -345
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -90
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -131
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -543
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -23
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -58
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -143
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -179
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -111
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -384
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -160
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -234
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -223
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -232
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -236
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -228
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -364
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -50
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -34
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -85
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -33
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -338
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -95
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -64
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -89
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -91
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -84
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -208
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -172
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -199
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -237
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -191
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -306
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -13
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -189
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -257
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -2
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -35
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -2
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -59
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -68
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -49
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -232
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -111
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -94
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -159
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -232
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -459
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -169
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -216
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -180
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -251
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -80
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -306
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -31
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -385
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -38
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -62
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -88
  109. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -144
  110. package/gradle.properties +0 -19
  111. package/gradlew +0 -240
  112. package/gradlew.bat +0 -91
  113. package/ios/Application/ApplicationEnvironment.swift +0 -50
  114. package/ios/Application/Components.swift +0 -260
  115. package/ios/Application/ComposeApi.swift +0 -22
  116. package/ios/Application/FloatingButton.swift +0 -172
  117. package/ios/Application/HeaderRight.swift +0 -271
  118. package/ios/Application/Screen.swift +0 -242
  119. package/ios/Badge/BadgeDot.swift +0 -31
  120. package/ios/Button/Button.swift +0 -211
  121. package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +0 -126
  122. package/ios/Checkbox/Checkbox.swift +0 -81
  123. package/ios/Chip/Chip.swift +0 -96
  124. package/ios/Colors+Radius+Spacing/Colors.swift +0 -172
  125. package/ios/Colors+Radius+Spacing/Radius.swift +0 -22
  126. package/ios/Colors+Radius+Spacing/Spacing.swift +0 -12
  127. package/ios/Extensions/Color++.swift +0 -25
  128. package/ios/Icon/Icon.swift +0 -51
  129. package/ios/Image/Image.swift +0 -70
  130. package/ios/Input/Input.swift +0 -207
  131. package/ios/Input/InputPhoneNumber.swift +0 -176
  132. package/ios/Input/InputSearch.swift +0 -238
  133. package/ios/Input/InputTextArea.swift +0 -242
  134. package/ios/Lottie/LottieView.swift +0 -86
  135. package/ios/OTPKeyboard/KeyboardButton.swift +0 -41
  136. package/ios/OTPKeyboard/OTPKeyboard.swift +0 -145
  137. package/ios/Popup/PopupDisplay.swift +0 -284
  138. package/ios/Popup/PopupInput.swift +0 -96
  139. package/ios/Popup/PopupPromotion.swift +0 -73
  140. package/ios/PopupView/FullscreenPopup.swift +0 -251
  141. package/ios/PopupView/Modifiers.swift +0 -158
  142. package/ios/PopupView/PopupView.swift +0 -289
  143. package/ios/PopupView/Utils++.swift +0 -281
  144. package/ios/ScrollIndicator/ScrollIndicator.swift +0 -110
  145. package/ios/Swipeable/SwipeCell.swift +0 -278
  146. package/ios/Swipeable/SwipeCellModel.swift +0 -86
  147. package/ios/Switch/Switch.swift +0 -44
  148. package/ios/Template/Logo/Logo.swift +0 -75
  149. package/ios/Template/TrustBanner/TrustBanner.swift +0 -120
  150. package/ios/Theme.md +0 -18
  151. package/ios/Typography/Text.swift +0 -140
  152. package/ios/Typography/Typography.swift +0 -95
  153. package/ios/native-kits.podspec +0 -18
  154. package/settings.gradle.kts +0 -25
@@ -1,260 +0,0 @@
1
- //
2
- // Components.swift
3
- // Pods
4
- //
5
- // Created by sophia on 24/1/25.
6
- //
7
-
8
- import SwiftUI
9
-
10
- // MARK: - Enums
11
-
12
- public enum TitlePosition {
13
- case left, center
14
- }
15
-
16
- public enum HeaderType {
17
- case `default`, extended, none
18
- }
19
-
20
- public enum AnimatedHeaderRatio {
21
- case ratio16_9
22
- case ratio1_1
23
- case ratio3_2
24
-
25
- var value: CGFloat {
26
- switch self {
27
- case .ratio16_9: return 16.0 / 9.0
28
- case .ratio1_1: return 1.0
29
- case .ratio3_2: return 3.0 / 2.0
30
- }
31
- }
32
- }
33
-
34
-
35
- // MARK: - Animated Header Config
36
-
37
- public struct AnimatedHeader {
38
- public var aspectRatio: AnimatedHeaderRatio = .ratio16_9
39
- public var isSurface: Bool = true
40
- public var composable: (_ scrollState: CGFloat) -> AnyView = { _ in AnyView(EmptyView()) }
41
-
42
- public init(
43
- aspectRatio: AnimatedHeaderRatio = .ratio16_9,
44
- isSurface: Bool = true,
45
- composable: @escaping (_ scrollState: CGFloat) -> AnyView = { _ in AnyView(EmptyView()) }
46
- ) {
47
- self.aspectRatio = aspectRatio
48
- self.isSurface = isSurface
49
- self.composable = composable
50
- }
51
- }
52
-
53
- // MARK: - Utils
54
-
55
- func safeAreaTopInset() -> CGFloat {
56
- if #available(iOS 15.0, *) {
57
- return UIApplication.shared.connectedScenes
58
- .compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.top }
59
- .first ?? 0
60
- } else {
61
- return UIApplication.shared.connectedScenes
62
- .compactMap { ($0 as? UIWindowScene)?.windows.first?.safeAreaInsets.top }
63
- .first ?? 0
64
- }
65
- }
66
-
67
- // MARK: - Header Background
68
-
69
- public struct HeaderBackground: View {
70
- var headerType: HeaderType = .default
71
- var scrollState: CGFloat
72
- var isTransparent: Bool = false
73
-
74
- public init(
75
- headerType: HeaderType = .default,
76
- scrollState: CGFloat = 0,
77
- isTransparent: Bool = false
78
- ) {
79
- self.headerType = headerType
80
- self.scrollState = scrollState
81
- self.isTransparent = isTransparent
82
- }
83
-
84
- public var body: some View {
85
-
86
- let statusBarHeight = safeAreaTopInset()
87
- let opacity = max(0, 1 - scrollState / 200)
88
- let height = statusBarHeight + 52
89
- let backgroundColor = isTransparent ? Color.clear : Colors.black01
90
-
91
- Group {
92
- switch headerType {
93
- case .default:
94
- ZStack(alignment: .bottom) {
95
- Rectangle()
96
- .fill(backgroundColor)
97
- .opacity(isTransparent ? 0 : opacity)
98
- .frame(height: height)
99
- .shadow(color: Colors.black20.opacity(0.2), radius: 10, x: 0, y: -2)
100
- .background(Colors.black01)
101
- .overlay(
102
- isTransparent ? AnyView(EmptyView()) :
103
- AnyView(
104
- Rectangle()
105
- .fill(LinearGradient(
106
- gradient: Gradient(colors: [
107
- Color(red: 1, green: 0.8, blue: 0.87),
108
- Color(red: 1, green: 0.8, blue: 0.87).opacity(0.5)
109
- ]),
110
- startPoint: .top,
111
- endPoint: .bottom))
112
- .opacity(opacity)
113
- .frame(height: height))
114
- )
115
-
116
- if !isTransparent {
117
- Rectangle()
118
- .fill(Color.black.opacity(0.1))
119
- .frame(height: 1)
120
- .frame(maxWidth: .infinity)
121
- }
122
- }
123
-
124
- case .extended:
125
- ZStack {
126
- if !isTransparent {
127
- Colors.black01
128
- LinearGradient(
129
- gradient: Gradient(colors: [
130
- Color(red: 1, green: 0.8, blue: 0.87),
131
- Color(red: 1, green: 0.8, blue: 0.87).opacity(0)
132
- ]),
133
- startPoint: .top,
134
- endPoint: .bottom
135
- )
136
- .opacity(opacity)
137
- .frame(height: 154)
138
- }
139
- }
140
-
141
- case .none:
142
- EmptyView()
143
- }
144
- }
145
- }
146
- }
147
-
148
- // MARK: - Header View
149
-
150
- public struct Header: View {
151
- var headerType: HeaderType = .default
152
- var titlePosition: TitlePosition
153
- var title: String
154
- var headerRight: (()->any View)? = {HeaderRight()}
155
- var goBack: (() -> Void)?
156
- var opacity: CGFloat = 1
157
- var animatedHeader: AnimatedHeader?
158
- var scrollState: CGFloat = 0
159
- var inputSearchProps: InputSearchProps?
160
- var tintColor: Color?
161
-
162
- public init(
163
- headerType: HeaderType = .default,
164
- titlePosition: TitlePosition,
165
- title: String,
166
- headerRight: (()->any View)? = {HeaderRight()},
167
- goBack: (() -> Void)? = nil,
168
- opacity: CGFloat = 1,
169
- animatedHeader: AnimatedHeader? = nil,
170
- scrollState: CGFloat = 0,
171
- inputSearchProps: InputSearchProps? = nil,
172
- tintColor: Color? = nil
173
- ) {
174
- self.headerType = headerType
175
- self.titlePosition = titlePosition
176
- self.title = title
177
- self.headerRight = headerRight
178
- self.goBack = goBack
179
- self.opacity = opacity
180
- self.animatedHeader = animatedHeader
181
- self.scrollState = scrollState
182
- self.inputSearchProps = inputSearchProps
183
- self.tintColor = tintColor
184
- }
185
-
186
- public var body: some View {
187
-
188
- let backgroundButtonColor: Color = tintColor == Colors.black01 ? Colors.black20.opacity(0.6) : Colors.black01.opacity(0.6)
189
- let borderColor: Color = tintColor == Colors.black01 ? Colors.black01.opacity(0.2) : Colors.black20.opacity(0.2)
190
-
191
- if headerType != .none {
192
- VStack(spacing: 0) {
193
- ZStack {
194
- // MARK: - Left and Right Controls
195
- HStack {
196
- if let goBack = goBack {
197
- SwiftUI.Button(action: goBack) {
198
- Circle()
199
- .stroke(borderColor, lineWidth: 0.2)
200
- .background(Circle().fill(backgroundButtonColor))
201
- .frame(width: 28, height: 28)
202
- .overlay(
203
- Icon(source: "arrow-back", size: 20, color: tintColor ?? Colors.black17)
204
- )
205
- }
206
- }
207
-
208
- Spacer()
209
-
210
- if let headerRight = headerRight {
211
- AnyView(headerRight())
212
- }
213
- }
214
- .padding(.horizontal, 12)
215
-
216
- // MARK: - Title or Search
217
- HStack {
218
- if titlePosition == .left && goBack != nil {
219
- Spacer().frame(width: 38)
220
- }
221
-
222
- if let inputProps = inputSearchProps {
223
- InputSearch(
224
- text: inputProps.$text,
225
- buttonText: inputProps.buttonText,
226
- showButtonText: inputProps.showButtonText,
227
- showBorder: inputProps.showBorder,
228
- placeholder: inputProps.placeholder,
229
- onChangeText: inputProps.onChangeText,
230
- onPressButtonText: inputProps.onPressButtonText,
231
- error: inputProps.error,
232
- disabled: inputProps.disabled,
233
- icon: inputProps.icon,
234
- iconColor: inputProps.iconColor,
235
- onRightIconPressed: inputProps.onRightIconPressed,
236
- onFocus: inputProps.onFocus,
237
- onBlur: inputProps.onBlur,
238
- loading: inputProps.loading,
239
- fontWeight: inputProps.fontWeight,
240
- keyboardType: inputProps.keyboardType
241
- )
242
- } else {
243
- Text(title)
244
- .font(.system(size: 17, weight: .bold))
245
- .foregroundColor(tintColor ?? Colors.black17)
246
- .frame(maxWidth: titlePosition == .center ? UIScreen.main.bounds.width - 252 : nil)
247
- .frame(maxWidth: titlePosition == .center ? .infinity : UIScreen.main.bounds.width - 172, alignment: titlePosition == .center ? .center : .leading)
248
- .lineLimit(1)
249
- }
250
-
251
- Spacer()
252
- }
253
- .padding(.horizontal)
254
- }
255
- .background(Color.clear)
256
- .frame(height: 52)
257
- }
258
- }
259
- }
260
- }
@@ -1,22 +0,0 @@
1
- import Foundation
2
-
3
- public protocol ComposeApi {
4
- func request(funcName: String, params: Any, _ completion: ((String) -> Void)?)
5
- func request(funcName: String, params: Any) -> String
6
- }
7
-
8
- // Default implementation
9
- public class ComposeApiImpl: ComposeApi {
10
- public static let shared = ComposeApiImpl()
11
-
12
- private init() {}
13
-
14
- public func request(funcName: String, params: Any, _ completion: ((String) -> Void)?) {
15
- // Implement your API request logic here
16
- }
17
-
18
- public func request(funcName: String, params: Any) -> String {
19
- // Implement your API request logic here
20
- return ""
21
- }
22
- }
@@ -1,172 +0,0 @@
1
- import SwiftUI
2
- import Combine
3
-
4
- public enum FABSize {
5
- case small
6
- case large
7
-
8
- }
9
-
10
- public enum FABPosition {
11
- case right
12
- case center
13
- }
14
-
15
- public struct FabProps {
16
- public let icon: String?
17
- public let iconColor: Color?
18
- public let label: String?
19
- public let onClick: (() -> Void)?
20
- public let containerColor: Color?
21
- public let size: FABSize?
22
- public let iconSize: CGFloat?
23
- public let scrollOffset: CGFloat?
24
- public let position: FABPosition?
25
- public let bottomPadding: CGFloat?
26
- public let renderComponent: (() -> AnyView)?
27
-
28
- public init(
29
- icon: String? = nil,
30
- iconColor: Color? = .white,
31
- label: String? = nil,
32
- onClick: (() -> Void)? = nil,
33
- containerColor: Color? = Colors.primary,
34
- size: FABSize? = .small,
35
- iconSize: CGFloat? = nil,
36
- scrollOffset: CGFloat? = nil,
37
- position: FABPosition? = .right,
38
- bottomPadding: CGFloat? = nil,
39
- renderComponent: (() -> AnyView)? = nil
40
- ) {
41
- self.icon = icon
42
- self.iconColor = iconColor
43
- self.label = label
44
- self.onClick = onClick
45
- self.containerColor = containerColor
46
- self.size = size
47
- self.iconSize = iconSize
48
- self.scrollOffset = scrollOffset
49
- self.position = position
50
- self.bottomPadding = bottomPadding
51
- self.renderComponent = renderComponent
52
- }
53
- }
54
-
55
- public struct FloatingButton: View {
56
- @State private var lastScrollOffset: CGFloat = 0
57
- @State private var isExpanded: Bool = false
58
- @State private var internalScrollOffset: CGFloat = 0
59
- @State private var showText: Bool = true
60
- @State private var fullWidth: CGFloat? = nil
61
- @State private var currentWidth: CGFloat = 0
62
- @State private var lastDirection: String? = nil
63
-
64
- private let props: FabProps
65
- private var keyboardOffset: CGFloat
66
- private var scrollOffset: CGFloat
67
- private var bottomPadding: CGFloat { props.bottomPadding ?? 12 + keyboardOffset}
68
- private var position: FABPosition? { props.position ?? .right }
69
- private var containerColor: Color? { props.containerColor ?? Colors.primary }
70
- private var iconColor: Color? { props.iconColor ?? .white }
71
- private var label: String? { props.label }
72
- private var icon: String? { props.icon }
73
- private var size: FABSize? { props.size }
74
- private var iconSize: CGFloat? { props.iconSize ?? defaultIconSize}
75
- private var onClick: (() -> Void)? { props.onClick }
76
- private var renderComponent: (() -> AnyView)? { props.renderComponent }
77
-
78
- public init(props: FabProps, keyboardOffset: CGFloat = 0, scrollOffset: CGFloat = 0) {
79
- self.props = props
80
- self.keyboardOffset = keyboardOffset
81
- self.scrollOffset = scrollOffset
82
- }
83
-
84
- private var height: CGFloat {
85
- if(iconSize == nil) {
86
- size == .small ? 36 : 48
87
- }
88
- else {
89
- iconSize!
90
- }
91
- }
92
-
93
- private var minWidth: CGFloat {
94
- size == .small ? 36 : 48
95
- }
96
-
97
- private var defaultIconSize: CGFloat {
98
- size == .small ? 12 : 24
99
- }
100
-
101
- public var body: some View {
102
- Group {
103
- if ((icon?.isEmpty) == nil), let render = renderComponent {
104
- render()
105
- } else {
106
- content
107
- }
108
- }
109
- .onTapGesture {
110
- onClick?()
111
- }
112
- .padding(Spacing.M)
113
- .frame(height: height + (Spacing.M * 2))
114
- .background(containerColor)
115
- .cornerRadius(100)
116
- .padding(.bottom, bottomPadding)
117
- .frame(alignment: position == .center ? .center : .trailing)
118
- .onAppear {
119
- internalScrollOffset = scrollOffset
120
- isExpanded = label != nil
121
- }
122
- .onReceive(Just(scrollOffset)) { newValue in
123
- let direction = newValue > internalScrollOffset ? "down" : "up"
124
-
125
- if direction != lastDirection {
126
- lastDirection = direction
127
- if direction == "down" {
128
- withAnimation(.easeOut(duration: 0.1)) {
129
- isExpanded = false
130
- }
131
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
132
- showText = false
133
- }
134
- } else {
135
- showText = true
136
- withAnimation(.easeIn(duration: 0.1)) {
137
- isExpanded = true
138
- }
139
-
140
- }
141
- }
142
- }
143
- }
144
-
145
- private var content: some View {
146
- HStack(spacing: 0) {
147
- ImageView(icon ?? "")
148
- .scaledToFit()
149
- .frame(width: iconSize, height: iconSize)
150
- .foregroundColor(iconColor)
151
-
152
- if let label = label {
153
- if showText {
154
- Spacer().frame(width: 8)
155
- Text(label)
156
- .foregroundColor(.white)
157
- .font(.system(size: 16, weight: .bold))
158
- .lineLimit(1)
159
- .background(
160
- GeometryReader { geo in
161
- Color.clear.onAppear {
162
- fullWidth = geo.size.width
163
- }
164
- }
165
- )
166
- .opacity(isExpanded ? 1 : 0)
167
- }
168
- }
169
-
170
- }
171
- }
172
- }