@momo-kits/native-kits 0.152.4-beta.3 → 0.152.5

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 (155) 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 -236
  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 -69
  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 -191
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -258
  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/ScaleSizeScope.kt +0 -17
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -459
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -169
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -216
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -180
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -251
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -80
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -306
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -31
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -385
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -38
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -62
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -88
  110. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -144
  111. package/gradle.properties +0 -19
  112. package/gradlew +0 -240
  113. package/gradlew.bat +0 -91
  114. package/ios/Application/ApplicationEnvironment.swift +0 -50
  115. package/ios/Application/Components.swift +0 -263
  116. package/ios/Application/ComposeApi.swift +0 -22
  117. package/ios/Application/FloatingButton.swift +0 -172
  118. package/ios/Application/HeaderRight.swift +0 -271
  119. package/ios/Application/Screen.swift +0 -249
  120. package/ios/Badge/BadgeDot.swift +0 -31
  121. package/ios/Button/Button.swift +0 -211
  122. package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +0 -126
  123. package/ios/Checkbox/Checkbox.swift +0 -81
  124. package/ios/Chip/Chip.swift +0 -96
  125. package/ios/Colors+Radius+Spacing/Colors.swift +0 -172
  126. package/ios/Colors+Radius+Spacing/Radius.swift +0 -22
  127. package/ios/Colors+Radius+Spacing/Spacing.swift +0 -12
  128. package/ios/Extensions/Color++.swift +0 -25
  129. package/ios/Icon/Icon.swift +0 -51
  130. package/ios/Image/Image.swift +0 -70
  131. package/ios/Input/Input.swift +0 -207
  132. package/ios/Input/InputPhoneNumber.swift +0 -176
  133. package/ios/Input/InputSearch.swift +0 -238
  134. package/ios/Input/InputTextArea.swift +0 -242
  135. package/ios/Lottie/LottieView.swift +0 -86
  136. package/ios/OTPKeyboard/KeyboardButton.swift +0 -41
  137. package/ios/OTPKeyboard/OTPKeyboard.swift +0 -145
  138. package/ios/Popup/PopupDisplay.swift +0 -284
  139. package/ios/Popup/PopupInput.swift +0 -96
  140. package/ios/Popup/PopupPromotion.swift +0 -73
  141. package/ios/PopupView/FullscreenPopup.swift +0 -251
  142. package/ios/PopupView/Modifiers.swift +0 -158
  143. package/ios/PopupView/PopupView.swift +0 -289
  144. package/ios/PopupView/Utils++.swift +0 -281
  145. package/ios/ScrollIndicator/ScrollIndicator.swift +0 -110
  146. package/ios/Swipeable/SwipeCell.swift +0 -278
  147. package/ios/Swipeable/SwipeCellModel.swift +0 -86
  148. package/ios/Switch/Switch.swift +0 -44
  149. package/ios/Template/Logo/Logo.swift +0 -75
  150. package/ios/Template/TrustBanner/TrustBanner.swift +0 -120
  151. package/ios/Theme.md +0 -18
  152. package/ios/Typography/Text.swift +0 -140
  153. package/ios/Typography/Typography.swift +0 -95
  154. package/ios/native-kits.podspec +0 -18
  155. package/settings.gradle.kts +0 -25
@@ -1,263 +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 headerTransparent: Bool = false
73
- var fullScreenContent: Bool = false
74
-
75
- public init(
76
- headerType: HeaderType = .default,
77
- scrollState: CGFloat = 0,
78
- headerTransparent: Bool = false,
79
- fullScreenContent: Bool = false
80
- ) {
81
- self.headerType = headerType
82
- self.scrollState = scrollState
83
- self.headerTransparent = headerTransparent
84
- self.fullScreenContent = fullScreenContent
85
- }
86
-
87
- public var body: some View {
88
-
89
- let statusBarHeight = safeAreaTopInset()
90
- let opacity = max(0, 1 - scrollState / 200)
91
- let height = fullScreenContent ? 0 : statusBarHeight + 52
92
- let backgroundColor = headerTransparent ? Color.clear : Colors.black01
93
-
94
- Group {
95
- switch headerType {
96
- case .default:
97
- ZStack(alignment: .bottom) {
98
- Rectangle()
99
- .fill(backgroundColor)
100
- .opacity(headerTransparent ? 0 : opacity)
101
- .frame(height: height)
102
- .shadow(color: Colors.black20.opacity(0.2), radius: 10, x: 0, y: -2)
103
- .background(backgroundColor)
104
- .overlay(
105
- headerTransparent ? AnyView(EmptyView()) :
106
- AnyView(
107
- Rectangle()
108
- .fill(LinearGradient(
109
- gradient: Gradient(colors: [
110
- Color(red: 1, green: 0.8, blue: 0.87),
111
- Color(red: 1, green: 0.8, blue: 0.87).opacity(0.5)
112
- ]),
113
- startPoint: .top,
114
- endPoint: .bottom))
115
- .opacity(opacity)
116
- .frame(height: height))
117
- )
118
-
119
- if !headerTransparent {
120
- Rectangle()
121
- .fill(Color.black.opacity(0.1))
122
- .frame(height: 1)
123
- .frame(maxWidth: .infinity)
124
- }
125
- }
126
-
127
- case .extended:
128
- ZStack {
129
- if !headerTransparent {
130
- Colors.black01
131
- LinearGradient(
132
- gradient: Gradient(colors: [
133
- Color(red: 1, green: 0.8, blue: 0.87),
134
- Color(red: 1, green: 0.8, blue: 0.87).opacity(0)
135
- ]),
136
- startPoint: .top,
137
- endPoint: .bottom
138
- )
139
- .opacity(opacity)
140
- .frame(height: 154)
141
- }
142
- }
143
-
144
- case .none:
145
- EmptyView()
146
- }
147
- }
148
- }
149
- }
150
-
151
- // MARK: - Header View
152
-
153
- public struct Header: View {
154
- var headerType: HeaderType = .default
155
- var titlePosition: TitlePosition
156
- var title: String
157
- var headerRight: (()->any View)? = {HeaderRight()}
158
- var goBack: (() -> Void)?
159
- var opacity: CGFloat = 1
160
- var animatedHeader: AnimatedHeader?
161
- var scrollState: CGFloat = 0
162
- var inputSearchProps: InputSearchProps?
163
- var tintColor: Color?
164
-
165
- public init(
166
- headerType: HeaderType = .default,
167
- titlePosition: TitlePosition,
168
- title: String,
169
- headerRight: (()->any View)? = {HeaderRight()},
170
- goBack: (() -> Void)? = nil,
171
- opacity: CGFloat = 1,
172
- animatedHeader: AnimatedHeader? = nil,
173
- scrollState: CGFloat = 0,
174
- inputSearchProps: InputSearchProps? = nil,
175
- tintColor: Color? = nil
176
- ) {
177
- self.headerType = headerType
178
- self.titlePosition = titlePosition
179
- self.title = title
180
- self.headerRight = headerRight
181
- self.goBack = goBack
182
- self.opacity = opacity
183
- self.animatedHeader = animatedHeader
184
- self.scrollState = scrollState
185
- self.inputSearchProps = inputSearchProps
186
- self.tintColor = tintColor
187
- }
188
-
189
- public var body: some View {
190
-
191
- let backgroundButtonColor: Color = tintColor == Colors.black01 ? Colors.black20.opacity(0.6) : Colors.black01.opacity(0.6)
192
- let borderColor: Color = tintColor == Colors.black01 ? Colors.black01.opacity(0.2) : Colors.black20.opacity(0.2)
193
-
194
- if headerType != .none {
195
- VStack(spacing: 0) {
196
- ZStack {
197
- // MARK: - Left and Right Controls
198
- HStack {
199
- if let goBack = goBack {
200
- SwiftUI.Button(action: goBack) {
201
- Circle()
202
- .stroke(borderColor, lineWidth: 0.2)
203
- .background(Circle().fill(backgroundButtonColor))
204
- .frame(width: 28, height: 28)
205
- .overlay(
206
- Icon(source: "arrow-back", size: 20, color: tintColor ?? Colors.black17)
207
- )
208
- }
209
- }
210
-
211
- Spacer()
212
-
213
- if let headerRight = headerRight {
214
- AnyView(headerRight())
215
- }
216
- }
217
- .padding(.horizontal, 12)
218
-
219
- // MARK: - Title or Search
220
- HStack {
221
- if titlePosition == .left && goBack != nil {
222
- Spacer().frame(width: 38)
223
- }
224
-
225
- if let inputProps = inputSearchProps {
226
- InputSearch(
227
- text: inputProps.$text,
228
- buttonText: inputProps.buttonText,
229
- showButtonText: inputProps.showButtonText,
230
- showBorder: inputProps.showBorder,
231
- placeholder: inputProps.placeholder,
232
- onChangeText: inputProps.onChangeText,
233
- onPressButtonText: inputProps.onPressButtonText,
234
- error: inputProps.error,
235
- disabled: inputProps.disabled,
236
- icon: inputProps.icon,
237
- iconColor: inputProps.iconColor,
238
- onRightIconPressed: inputProps.onRightIconPressed,
239
- onFocus: inputProps.onFocus,
240
- onBlur: inputProps.onBlur,
241
- loading: inputProps.loading,
242
- fontWeight: inputProps.fontWeight,
243
- keyboardType: inputProps.keyboardType
244
- )
245
- } else {
246
- Text(title)
247
- .font(.system(size: 17, weight: .bold))
248
- .foregroundColor(tintColor ?? Colors.black17)
249
- .frame(maxWidth: titlePosition == .center ? UIScreen.main.bounds.width - 252 : nil)
250
- .frame(maxWidth: titlePosition == .center ? .infinity : UIScreen.main.bounds.width - 172, alignment: titlePosition == .center ? .center : .leading)
251
- .lineLimit(1)
252
- }
253
-
254
- Spacer()
255
- }
256
- .padding(.horizontal)
257
- }
258
- .background(Color.clear)
259
- .frame(height: 52)
260
- }
261
- }
262
- }
263
- }
@@ -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
- }