@momo-kits/native-kits 0.152.4-beta.6 → 0.152.4-beta.9

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 (157) hide show
  1. package/CODE_OF_CONDUCT.md +133 -0
  2. package/CONTRIBUTING.md +114 -0
  3. package/LICENSE +20 -0
  4. package/README.md +7 -0
  5. package/build.gradle.kts +32 -0
  6. package/compose/MoMoComposeKits.podspec +54 -0
  7. package/compose/build.gradle.kts +149 -0
  8. package/compose/src/androidMain/AndroidManifest.xml +2 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +105 -0
  10. package/compose/src/commonMain/composeResources/files/lottie_circle_loader.json +1 -0
  11. package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
  12. package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
  13. package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
  14. package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
  15. package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
  16. package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
  17. package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
  18. package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
  19. package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
  20. package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
  21. package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
  22. package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
  23. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
  24. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +57 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +201 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +222 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +48 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +306 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +715 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +214 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +236 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +77 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +27 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +334 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +345 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +90 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +131 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +543 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +58 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +143 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +179 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +111 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +384 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +160 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +234 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +223 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +232 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +236 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +228 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +364 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +50 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +34 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +85 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +33 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +338 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +95 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +64 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +89 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +91 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +84 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +208 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +172 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +199 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +237 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +191 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +306 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +13 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +191 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +258 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +2 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +35 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +2 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +59 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +68 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +49 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +232 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +111 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +94 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +159 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +232 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScaleSizeScope.kt +17 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +459 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +169 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +216 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +180 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +251 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +80 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +306 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +31 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +385 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +38 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +62 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +88 -0
  108. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +144 -0
  109. package/gradle.properties +19 -0
  110. package/gradlew +240 -0
  111. package/gradlew.bat +91 -0
  112. package/ios/Application/ApplicationEnvironment.swift +50 -0
  113. package/ios/Application/Components.swift +263 -0
  114. package/ios/Application/ComposeApi.swift +22 -0
  115. package/ios/Application/FloatingButton.swift +172 -0
  116. package/ios/Application/HeaderRight.swift +271 -0
  117. package/ios/Application/Screen.swift +249 -0
  118. package/ios/Badge/Badge.swift +91 -0
  119. package/ios/Badge/BadgeDot.swift +31 -0
  120. package/ios/Badge/BadgeRibbon.swift +174 -0
  121. package/ios/Button/Button.swift +211 -0
  122. package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +126 -0
  123. package/ios/Checkbox/Checkbox.swift +81 -0
  124. package/ios/Chip/Chip.swift +96 -0
  125. package/ios/Colors+Radius+Spacing/Colors.swift +172 -0
  126. package/ios/Colors+Radius+Spacing/Radius.swift +22 -0
  127. package/ios/Colors+Radius+Spacing/Spacing.swift +12 -0
  128. package/ios/Extensions/Color++.swift +25 -0
  129. package/ios/Icon/Icon.swift +51 -0
  130. package/ios/Image/Image.swift +70 -0
  131. package/ios/Input/Input.swift +207 -0
  132. package/ios/Input/InputPhoneNumber.swift +176 -0
  133. package/ios/Input/InputSearch.swift +238 -0
  134. package/ios/Input/InputTextArea.swift +242 -0
  135. package/ios/Lottie/LottieView.swift +86 -0
  136. package/ios/OTPKeyboard/KeyboardButton.swift +41 -0
  137. package/ios/OTPKeyboard/OTPKeyboard.swift +145 -0
  138. package/ios/Popup/PopupDisplay.swift +284 -0
  139. package/ios/Popup/PopupInput.swift +96 -0
  140. package/ios/Popup/PopupPromotion.swift +73 -0
  141. package/ios/PopupView/FullscreenPopup.swift +251 -0
  142. package/ios/PopupView/Modifiers.swift +158 -0
  143. package/ios/PopupView/PopupView.swift +289 -0
  144. package/ios/PopupView/Utils++.swift +281 -0
  145. package/ios/ScrollIndicator/ScrollIndicator.swift +110 -0
  146. package/ios/Swipeable/SwipeCell.swift +278 -0
  147. package/ios/Swipeable/SwipeCellModel.swift +86 -0
  148. package/ios/Switch/Switch.swift +44 -0
  149. package/ios/Template/Logo/Logo.swift +75 -0
  150. package/ios/Template/TrustBanner/TrustBanner.swift +120 -0
  151. package/ios/Theme.md +18 -0
  152. package/ios/Typography/Text.swift +140 -0
  153. package/ios/Typography/Typography.swift +95 -0
  154. package/ios/native-kits.podspec +18 -0
  155. package/package.json +6 -7
  156. package/settings.gradle.kts +25 -0
  157. package/shared/build.gradle.kts +0 -74
@@ -0,0 +1,278 @@
1
+ import Foundation
2
+ import SwiftUI
3
+
4
+ // MARK: - SwipeCellModifier
5
+
6
+ public struct SwipeCellModifier: ViewModifier {
7
+ var id: String
8
+ var cellWidth: CGFloat = .infinity
9
+ var leadingSideGroup: [SwipeCellActionItem] = []
10
+ var trailingSideGroup: [SwipeCellActionItem] = []
11
+ @Binding var currentUserInteractionCellID: String?
12
+ var settings: SwipeCellSettings = .init()
13
+
14
+ @State private var offsetX: CGFloat = 0
15
+
16
+ let generator = UINotificationFeedbackGenerator()
17
+ @State private var hapticFeedbackOccurred: Bool = false
18
+ @State private var openSideLock: SwipeGroupSide?
19
+
20
+ public func body(content: Content)->some View {
21
+ ZStack {
22
+ if self.leadingSideGroup.isEmpty == false && self.offsetX != 0 {
23
+ self.swipeToRevealArea(swipeItemGroup: self.leadingSideGroup, side: .leading)
24
+ }
25
+
26
+ if self.trailingSideGroup.isEmpty == false && self.offsetX != 0 {
27
+ self.swipeToRevealArea(swipeItemGroup: self.trailingSideGroup, side: .trailing)
28
+ }
29
+
30
+ content
31
+ .offset(x: self.offsetX)
32
+ .simultaneousGesture(
33
+ DragGesture(minimumDistance: 30, coordinateSpace: .local)
34
+ .onChanged { value in
35
+ self.dragOnChanged(value: value)
36
+ }
37
+ .onEnded { value in
38
+ self.dragOnEnded(value: value)
39
+ }
40
+ )
41
+
42
+ }.frame(width: cellWidth)
43
+ .edgesIgnoringSafeArea(.horizontal)
44
+ .clipped()
45
+ .valueChanged(value: self.currentUserInteractionCellID) { _ in
46
+ if let currentDragCellID = self.currentUserInteractionCellID, currentDragCellID != self.id && self.openSideLock != nil {
47
+ // if this cell has an open side area and is not the cell being dragged, close the cell
48
+ self.setOffsetX(value: 0)
49
+ // reset the drag cell id to nil
50
+ self.currentUserInteractionCellID = nil
51
+ }
52
+ }
53
+ }
54
+
55
+ internal func swipeToRevealArea(swipeItemGroup: [SwipeCellActionItem], side: SwipeGroupSide)->some View {
56
+ HStack {
57
+ if side == .trailing {
58
+ Spacer()
59
+ }
60
+ ZStack {
61
+ HStack(spacing: 0) {
62
+ ForEach(swipeItemGroup) { item in
63
+ SwiftUI.Button {
64
+ self.setOffsetX(value: 0)
65
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
66
+ item.actionCallback()
67
+ }
68
+ } label: {
69
+ self.buttonContentView(item: item, group: swipeItemGroup, side: side)
70
+ }.buttonStyle(BorderlessButtonStyle())
71
+ }
72
+ }
73
+ }.opacity(self.swipeRevealAreaOpacity(side: side))
74
+
75
+ if side == .leading {
76
+ Spacer()
77
+ }
78
+ }
79
+ }
80
+
81
+ internal func buttonContentView(item: SwipeCellActionItem, group: [SwipeCellActionItem], side: SwipeGroupSide)->some View {
82
+ ZStack {
83
+ item.backgroundColor
84
+
85
+ HStack {
86
+ if self.warnSwipeOutCondition(side: side, hasSwipeOut: item.swipeOutAction) && item.swipeOutButtonView != nil {
87
+ item.swipeOutButtonView!()
88
+ } else {
89
+ item.buttonView()
90
+ }
91
+ }
92
+
93
+ }.frame(width: self.itemButtonWidth(item: item, itemGroup: group, side: side))
94
+ }
95
+
96
+ internal func menuWidth(side: SwipeGroupSide)->CGFloat {
97
+ switch side {
98
+ case .leading:
99
+ return self.leadingSideGroup.map { $0.buttonWidth }.reduce(0, +)
100
+
101
+ case .trailing:
102
+ return self.trailingSideGroup.map { $0.buttonWidth }.reduce(0, +)
103
+ }
104
+ }
105
+
106
+ // MARK: drag gesture
107
+
108
+ internal func dragOnChanged(value: DragGesture.Value) {
109
+ let horizontalTranslation = value.translation.width
110
+ if self.nonDraggableCondition(horizontalTranslation: horizontalTranslation) {
111
+ return
112
+ }
113
+
114
+ if self.openSideLock != nil {
115
+ // if one side is open, we need to add the menu width!
116
+ let menuWidth = self.openSideLock == .leading ? self.menuWidth(side: .leading) : self.menuWidth(side: .trailing)
117
+ self.offsetX = menuWidth * openSideLock!.sideFactor + horizontalTranslation
118
+ self.triggerHapticFeedbackIfNeeded(horizontalTranslation: horizontalTranslation)
119
+ return
120
+ }
121
+
122
+ self.triggerHapticFeedbackIfNeeded(horizontalTranslation: horizontalTranslation)
123
+
124
+ if horizontalTranslation > 8 || horizontalTranslation < -8 { // makes sure the swipe cell doesn't open too easily
125
+ self.currentUserInteractionCellID = self.id
126
+ self.offsetX = horizontalTranslation
127
+ } else {
128
+ self.offsetX = 0
129
+ }
130
+ }
131
+
132
+ internal func nonDraggableCondition(horizontalTranslation: CGFloat)->Bool {
133
+ return self.offsetX == 0 && (self.leadingSideGroup.isEmpty && horizontalTranslation > 0 || self.trailingSideGroup.isEmpty && horizontalTranslation < 0)
134
+ }
135
+
136
+ internal func dragOnEnded(value: DragGesture.Value) {
137
+ let swipeOutTriggerValue = self.cellWidth * self.settings.swipeOutTriggerRatio
138
+
139
+ if self.offsetX == 0 {
140
+ self.openSideLock = nil
141
+ } else if self.offsetX > 0 {
142
+ if self.leadingSideGroup.isEmpty == false {
143
+ if self.offsetX < settings.openTriggerValue || (self.openSideLock == .leading && self.offsetX < self.menuWidth(side: .leading) * 0.8) {
144
+ self.setOffsetX(value: 0)
145
+ } else if let leftItem = self.leadingSideGroup.filter({ $0.swipeOutAction == true }).first, self.offsetX.magnitude > swipeOutTriggerValue {
146
+ self.swipeOutAction(item: leftItem, sideFactor: 1)
147
+ } else {
148
+ self.lockSideMenu(side: .leading)
149
+ }
150
+
151
+ } else {
152
+ // leading group emtpy
153
+ self.setOffsetX(value: 0)
154
+ }
155
+ } else if self.offsetX < 0 {
156
+ if self.trailingSideGroup.isEmpty == false {
157
+ if self.offsetX.magnitude < settings.openTriggerValue || (self.openSideLock == .trailing && self.offsetX > -self.menuWidth(side: .trailing) * 0.8) {
158
+ self.setOffsetX(value: 0)
159
+ } else if let rightItem = self.trailingSideGroup.filter({ $0.swipeOutAction == true }).first, self.offsetX.magnitude > swipeOutTriggerValue {
160
+ self.swipeOutAction(item: rightItem, sideFactor: -1)
161
+ } else {
162
+ self.lockSideMenu(side: .trailing)
163
+ }
164
+
165
+ } else {
166
+ // trailing group emtpy
167
+ self.setOffsetX(value: 0)
168
+ }
169
+ }
170
+ }
171
+
172
+ internal func triggerHapticFeedbackIfNeeded(horizontalTranslation: CGFloat) {
173
+ let side: SwipeGroupSide = horizontalTranslation > 0 ? .leading : .trailing
174
+ let group = side == .leading ? self.leadingSideGroup : self.trailingSideGroup
175
+ let swipeOutActionCondition = self.warnSwipeOutCondition(side: side, hasSwipeOut: true)
176
+ if let item = self.swipeOutItemWithHapticFeedback(group: group), self.hapticFeedbackOccurred == false, swipeOutActionCondition == true {
177
+ self.generator.notificationOccurred(item.swipeOutHapticFeedbackType!)
178
+ self.hapticFeedbackOccurred = true
179
+ }
180
+ }
181
+
182
+ internal func swipeOutItemWithHapticFeedback(group: [SwipeCellActionItem])->SwipeCellActionItem? {
183
+ if let item = group.filter({ $0.swipeOutAction == true }).first {
184
+ if item.swipeOutHapticFeedbackType != nil {
185
+ return item
186
+ }
187
+ }
188
+ return nil
189
+ }
190
+
191
+ internal func swipeOutAction(item: SwipeCellActionItem, sideFactor: CGFloat) {
192
+ if item.swipeOutIsDestructive {
193
+ let swipeOutWidth = cellWidth + 10
194
+ self.setOffsetX(value: swipeOutWidth * sideFactor)
195
+ self.openSideLock = nil
196
+ } else {
197
+ self.setOffsetX(value: 0) // open side lock set in function!
198
+ }
199
+
200
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
201
+ item.actionCallback()
202
+ }
203
+ }
204
+
205
+ internal func lockSideMenu(side: SwipeGroupSide) {
206
+ self.setOffsetX(value: side.sideFactor * self.menuWidth(side: side))
207
+ self.openSideLock = side
208
+ self.hapticFeedbackOccurred = false
209
+ }
210
+
211
+ internal func setOffsetX(value: CGFloat) {
212
+ withAnimation(.spring()) {
213
+ self.offsetX = value
214
+ }
215
+ if self.offsetX == 0 {
216
+ self.openSideLock = nil
217
+ self.hapticFeedbackOccurred = false
218
+ }
219
+ }
220
+
221
+ internal func itemButtonWidth(item: SwipeCellActionItem, itemGroup: [SwipeCellActionItem], side: SwipeGroupSide)->CGFloat {
222
+ let dynamicButtonWidth = self.dynamicButtonWidth(item: item, itemCount: itemGroup.count, side: side)
223
+ let triggerValue = self.cellWidth * settings.swipeOutTriggerRatio
224
+ let swipeOutActionCondition = side == .leading ? self.offsetX > triggerValue : self.offsetX < -triggerValue
225
+
226
+ if item.swipeOutAction && swipeOutActionCondition {
227
+ return self.offsetX.magnitude + settings.addWidthMargin
228
+ } else if swipeOutActionCondition && item.swipeOutAction == false && itemGroup.contains(where: { $0.swipeOutAction == true }) {
229
+ return 0
230
+ } else {
231
+ return dynamicButtonWidth
232
+ }
233
+ }
234
+
235
+ internal func dynamicButtonWidth(item: SwipeCellActionItem, itemCount: Int, side: SwipeGroupSide)->CGFloat {
236
+ let menuWidth = self.menuWidth(side: side)
237
+ return (self.offsetX.magnitude + settings.addWidthMargin) * (item.buttonWidth / menuWidth)
238
+ }
239
+
240
+ internal func warnSwipeOutCondition(side: SwipeGroupSide, hasSwipeOut: Bool)->Bool {
241
+ if hasSwipeOut == false {
242
+ return false
243
+ }
244
+ let triggerValue = self.cellWidth * settings.swipeOutTriggerRatio
245
+ return (side == .trailing && self.offsetX < -triggerValue) || (side == .leading && self.offsetX > triggerValue)
246
+ }
247
+
248
+ internal func swipeRevealAreaOpacity(side: SwipeGroupSide)->Double {
249
+ switch side {
250
+ case .leading:
251
+
252
+ return self.offsetX > 5 ? 1 : 0
253
+ case .trailing:
254
+ return self.offsetX < -5 ? 1 : 0
255
+ }
256
+ }
257
+ }
258
+
259
+ public extension View {
260
+ /// swipe cell modifier
261
+ /// - Parameters:
262
+ /// - id: the string id of this cell. The default value is a uuid string. If you want to set the currentUserInteractionCellID yourself, e.g. for tap to close functionality, you need to override this id value with your own cell id.
263
+ /// - cellWidth: the width of the content view - typically a cell or row in a list under which the swipe to reveal menu should appear.
264
+ /// - leadingSideGroup: the button group on the leading side that shall appear when the user swipes the cell to the right
265
+ /// - trailingSideGroup: the button group on the trailing side that shall appear when the user swipes the cell to the left
266
+ /// - currentUserInteractionCellID: a Binding of an optional UUID that should be set either in the view model of the parent view in which the cells appear or as a State variable into the parent view itself. Don't assign it a value!
267
+ /// - settings: settings. can be omitted in which case the settings struct default values apply.
268
+ /// - Returns: the modified view of the view that can be swiped.
269
+ func swipeCell(id: String = UUID().uuidString, cellWidth: CGFloat = .infinity, leadingSideGroup: [SwipeCellActionItem], trailingSideGroup: [SwipeCellActionItem], currentUserInteractionCellID: Binding<String?> = .constant(""), settings: SwipeCellSettings = SwipeCellSettings())->some View {
270
+ self.modifier(SwipeCellModifier(id: id, cellWidth: cellWidth, leadingSideGroup: leadingSideGroup, trailingSideGroup: trailingSideGroup, currentUserInteractionCellID: currentUserInteractionCellID, settings: settings))
271
+ }
272
+ }
273
+
274
+ public extension View {
275
+ func castToAnyView()->AnyView {
276
+ return AnyView(self)
277
+ }
278
+ }
@@ -0,0 +1,86 @@
1
+
2
+
3
+ import Foundation
4
+ import SwiftUI
5
+
6
+ // MARK: - SwipeGroupSide
7
+
8
+ public enum SwipeGroupSide {
9
+ case leading
10
+ case trailing
11
+
12
+ // MARK: Internal
13
+
14
+ var sideFactor: CGFloat {
15
+ switch self {
16
+ case .leading:
17
+ return 1
18
+
19
+ case .trailing:
20
+ return -1
21
+ }
22
+ }
23
+ }
24
+
25
+ // MARK: - SwipeCellActionItem
26
+
27
+ public struct SwipeCellActionItem: Identifiable {
28
+ // MARK: Lifecycle
29
+
30
+ /// Initializer
31
+ /// - Parameter id: Required to identify each buttin in the side menu. Default is a random uuid string.
32
+ /// - Parameter buttonView: The view in the foreground of the menu button. Make sure to set a maximum frame height less than the cell height!
33
+ /// - Parameter swipeOutButtonView: Alternative button view that is displayed only when the offset during swipe is beyond the swipe out trigger value.
34
+ /// - Parameter buttonWidth: Width of the button. The the open side menu width is calculated from the sum of all button widths. Default is 75.
35
+ /// - Parameter backgroundColor: The background colour of the the menu button.
36
+ /// - Parameter swipeOutAction: A Boolean that determines if a swipe out action is activated or not. Default is false.
37
+ /// - Parameter swipeOutHapticFeedbackType: If a swipeOutAction is activated, a haptic feedback will occur after the swipe out threshold is passed. Default is nil.
38
+ /// - Parameter swipeOutIsDestructive: A Boolean that determines if the swipe out is destructive. If true, the content cell view will be "move out of sight" once the swipe out is triggered.
39
+ public init(id: String = UUID().uuidString, buttonView: @escaping ()->AnyView, swipeOutButtonView: (()->AnyView)? = nil, buttonWidth: CGFloat = 75, backgroundColor: Color, swipeOutAction: Bool = false, swipeOutHapticFeedbackType: UINotificationFeedbackGenerator.FeedbackType? = nil, swipeOutIsDestructive: Bool = true, actionCallback: @escaping ()->()) {
40
+ self.id = id
41
+ self.buttonView = buttonView
42
+ self.swipeOutButtonView = swipeOutButtonView
43
+ self.buttonWidth = buttonWidth
44
+ self.backgroundColor = backgroundColor
45
+ self.swipeOutAction = swipeOutAction
46
+ self.swipeOutHapticFeedbackType = swipeOutHapticFeedbackType
47
+ self.swipeOutIsDestructive = swipeOutIsDestructive
48
+ self.actionCallback = actionCallback
49
+ }
50
+
51
+ // MARK: Public
52
+
53
+ public var id: String
54
+ public var buttonView: ()->AnyView
55
+ public var swipeOutButtonView: (()->AnyView)?
56
+ public var buttonWidth: CGFloat
57
+ public var backgroundColor: Color
58
+ public var swipeOutAction: Bool
59
+ public var swipeOutHapticFeedbackType: UINotificationFeedbackGenerator.FeedbackType?
60
+ public var swipeOutIsDestructive: Bool
61
+ /// public var swipeOutButtonViewScaleFactor: CGFloat
62
+ public var actionCallback: ()->()
63
+ }
64
+
65
+ // MARK: - SwipeCellSettings
66
+
67
+ /// Swipe Cell Settings
68
+ public struct SwipeCellSettings {
69
+ // MARK: Lifecycle
70
+
71
+ /// initializer
72
+ public init(openTriggerValue: CGFloat = 60, swipeOutTriggerRatio: CGFloat = 0.7, addWidthMargin: CGFloat = 5) {
73
+ self.openTriggerValue = openTriggerValue
74
+ self.swipeOutTriggerRatio = swipeOutTriggerRatio
75
+ self.addWidthMargin = addWidthMargin
76
+ }
77
+
78
+ // MARK: Public
79
+
80
+ /// minimum horizontal translation value necessary to open the side menu
81
+ public var openTriggerValue: CGFloat
82
+ /// the ratio of the total cell width that triggers a swipe out action (provided one action has swipe out activated)
83
+ public var swipeOutTriggerRatio: CGFloat = 0.7
84
+ /// An additional value to add to the open menu width. This is useful if the cell has rounded corners.
85
+ public var addWidthMargin: CGFloat = 5
86
+ }
@@ -0,0 +1,44 @@
1
+ import Foundation
2
+ import SwiftUI
3
+
4
+ public struct Switch: View{
5
+ @Binding var value: Bool
6
+ var disabled: Bool
7
+ var onChange: ((Bool)->Void)?
8
+
9
+ public init(_ value: Binding<Bool>,disabled: Bool = false, onChange: ((Bool)->Void)? = nil){
10
+ self._value = value
11
+ self.disabled = disabled
12
+ self.onChange = onChange
13
+ }
14
+
15
+
16
+ public var body: some View {
17
+ SwiftUI.Button(action: {
18
+ withAnimation{
19
+ value.toggle()
20
+ onChange?(value)
21
+ }
22
+ }){
23
+ HStack{
24
+ HStack {
25
+ }
26
+ .frame(width: 6, height: 6)
27
+ .background(value ? Colors.pink03 : Colors.black07)
28
+ .clipShape(Circle())
29
+ .opacity(disabled ? 0.4 : 1)
30
+ }
31
+ .frame(width: 14, height: 14)
32
+ .background(Colors.black01)
33
+ .clipShape(Circle())
34
+ .padding(.leading,5)
35
+ .padding(.trailing,5)
36
+
37
+ }
38
+ .disabled(disabled)
39
+ .frame(width: 40, height: 24, alignment: value == true ? .trailing : .leading)
40
+ .background(value ? Colors.pink03 : Colors.black07)
41
+ .clipShape(Capsule())
42
+ .opacity(disabled ? 0.4 : 1)
43
+ }
44
+ }
@@ -0,0 +1,75 @@
1
+ import Foundation
2
+ import SwiftUI
3
+
4
+ public struct LogoView: View {
5
+ var type: String
6
+ var useShadow: Bool
7
+ var useBorder: Bool
8
+ var useBackground : Bool
9
+ var backgroundColor: Color
10
+ var shadowColor : Color
11
+ var borderColor : Color
12
+ var source: String
13
+ var radius: CGFloat
14
+
15
+ public init(source: String = "",
16
+ type: String = "image",
17
+ useBackground : Bool = true,
18
+ useShadow: Bool = true,
19
+ useBorder : Bool = true,
20
+ backgroundColor: Color = Colors.black01,
21
+ shadowColor : Color = Color(hex: "d9d9d9"),
22
+ borderColor : Color = Color(hex: "e2e2e2")){
23
+ self.type = type
24
+ self.useShadow = useShadow
25
+ self.useBorder = useBorder
26
+ self.useBackground = useBackground
27
+ self.backgroundColor = backgroundColor
28
+ self.borderColor = borderColor
29
+ self.source = source
30
+ self.shadowColor = shadowColor
31
+ self.radius = type == "image" ? 7 : 0
32
+ }
33
+
34
+
35
+ public var body: some View {
36
+ return ImageView(source)
37
+ .scaledToFit()
38
+ .frame(width: 28, height: 28)
39
+ .cornerRadius(radius)
40
+ .containerBorder(type, useBorder, borderColor)
41
+ .containerBackground(type, useBackground, backgroundColor)
42
+ .containerShadow(useShadow, shadowColor)
43
+ }
44
+
45
+ }
46
+
47
+ private extension View {
48
+ func containerBorder (_ type: String, _ useBorder: Bool, _ borderColor: Color) -> some View {
49
+ Group {
50
+ if (useBorder && type != "icon") {
51
+ self.overlay(RoundedRectangle(cornerRadius: 8).stroke(borderColor, lineWidth: 1))
52
+ } else {
53
+ self
54
+ }
55
+ }
56
+ }
57
+ func containerBackground (_ type: String, _ useBackground: Bool, _ backgroundColor: Color) -> some View {
58
+ Group {
59
+ if (useBackground && type != "icon") {
60
+ self.background(backgroundColor)
61
+ } else {
62
+ self
63
+ }
64
+ }
65
+ }
66
+ func containerShadow (_ useShadow: Bool, _ shadowColor: Color) -> some View {
67
+ Group {
68
+ if useShadow {
69
+ self.shadow(color: shadowColor, radius: 2, x: 0, y: 2)
70
+ } else {
71
+ self
72
+ }
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,120 @@
1
+ //
2
+ // TrustBanner.swift
3
+ // MoMoUIKits
4
+ //
5
+ // Created by Nguyễn Hoàng Sơn on 14/12/2023.
6
+ //
7
+
8
+ import Foundation
9
+ import SwiftUI
10
+ import SDWebImageSwiftUI
11
+
12
+ let jsonUrl = "https://static.momocdn.net/app/json/component-kits/design_system.json"
13
+
14
+ public struct TrustBannerData: Decodable {
15
+ let content: [String: String]
16
+ let subContent: [String: String]
17
+ let pciImage: String
18
+ let sslImage: String
19
+ let urlConfig: String
20
+ let icons: [String]
21
+ let momoImage: String
22
+
23
+ enum CodingKeys: String, CodingKey {
24
+ case content
25
+ case subContent
26
+ case pciImage
27
+ case sslImage
28
+ case icons
29
+ case momoImage
30
+ case urlConfig = "url_config"
31
+ }
32
+ }
33
+
34
+ let defaultBanner = TrustBannerData(
35
+ content: ["vi": "An toàn tài sản & Bảo mật thông tin của bạn là ưu tiên hàng đầu của MoMo.",
36
+ "en": "Ensuring financial security and data privacy is MoMo's highest priority."],
37
+ subContent: [
38
+ "vi": "Tìm hiểu thêm",
39
+ "en": "Learn more"
40
+ ],
41
+ pciImage: "https://static.momocdn.net/app/img/kits/trustBanner/pci.png",
42
+ sslImage: "https://static.momocdn.net/app/img/kits/trustBanner/ssl.png",
43
+ urlConfig: "login_and_security",
44
+ icons: [
45
+ "https://static.momocdn.net/app/img/kits/trustBanner/ic_viettinbank.png",
46
+ "https://static.momocdn.net/app/img/kits/trustBanner/ic_agribank.png",
47
+ "https://static.momocdn.net/app/img/kits/trustBanner/ic_vietcombank.png",
48
+ "https://static.momocdn.net/app/img/kits/trustBanner/ic_bidv.png"
49
+ ],
50
+ momoImage: "https://static.momocdn.net/app/img/kits/trustBanner/ic_secu.png"
51
+ )
52
+
53
+ public struct TrustBanner: View {
54
+ @EnvironmentObject var applicationEnvironment: ApplicationEnvironment
55
+
56
+ var onPress: ((String)->Void)?
57
+
58
+ public init(onPress: ((String)->Void)?) {
59
+ self.onPress = onPress
60
+ }
61
+
62
+ var language: String? = "vi"
63
+
64
+ func onPressSecurity() {
65
+ if (onPress != nil) {
66
+ onPress!(applicationEnvironment.config?.trustBanner?.urlConfig ?? defaultBanner.urlConfig)
67
+ }
68
+ }
69
+
70
+
71
+ public var body: some View {
72
+ HStack(alignment: .center, spacing: 8) {
73
+ WebImage(url: URL(string: applicationEnvironment.config?.trustBanner?.momoImage ?? defaultBanner.momoImage))
74
+ .resizable()
75
+ .scaledToFit()
76
+ .frame(width: 64, height: 64)
77
+ VStack(alignment: .leading){
78
+ Text(applicationEnvironment.config?.trustBanner?.content[language ?? "vi"] as? String ?? defaultBanner.content[language ?? "vi"])
79
+ .foregroundColor(Color(hex: "484848"))
80
+ .lineLimit(2)
81
+ .font(.system(size: 13, weight: Font.Weight.regular))
82
+ .lineSpacing(3)
83
+ .padding(.bottom, 8)
84
+ HStack {
85
+ HStack(spacing: 0) {
86
+ Text(applicationEnvironment.config?.trustBanner?.subContent[language ?? "vi"] as? String ?? defaultBanner.subContent[language ?? "vi"])
87
+ .foregroundColor(Colors.pink03)
88
+ .font(.system(size: 13, weight: .bold))
89
+ .padding(.trailing, 4)
90
+
91
+ Icon(source: "arrow_chevron_right_small", color: Colors.pink03)
92
+ }.onTapGesture {
93
+ onPressSecurity()
94
+ }
95
+
96
+ Spacer()
97
+ HStack{
98
+ WebImage(url: URL(string: applicationEnvironment.config?.trustBanner?.pciImage ?? defaultBanner.pciImage))
99
+ .resizable()
100
+ .scaledToFit()
101
+ .frame(width: 24, height: 20)
102
+ WebImage(url: URL(string: applicationEnvironment.config?.trustBanner?.sslImage ?? defaultBanner.sslImage))
103
+ .resizable()
104
+ .scaledToFit()
105
+ .frame(width: 52, height: 20)
106
+ }
107
+ }
108
+
109
+ }
110
+
111
+ }
112
+ .padding(.all, 12)
113
+ .background(Color(hex: "F2F8FF"))
114
+ .cornerRadius(12)
115
+ .onTapGesture {
116
+ onPressSecurity()
117
+ }
118
+ .frame(maxWidth: UIScreen.main.bounds.size.width)
119
+ }
120
+ }
package/ios/Theme.md ADDED
@@ -0,0 +1,18 @@
1
+ ## 🎯 Usage
2
+ ### Declaring themes with Asset
3
+ To get started, you need to define four different types of assets in xcode
4
+ ```swift
5
+ public static let primary = Color("Primary")
6
+ public static let primaryDark = Color("PrimaryDark")
7
+ public static let primaryLight = Color("PrimaryLight")
8
+ public static let secondary = Color("Secondary")
9
+ public static let background = Color("Background")
10
+ public static let border = Color("Border")
11
+ public static let text = Color("Text")
12
+ public static let textSecondary = Color("TextSecondary")
13
+ public static let card = Color("Card")
14
+ public static let error = Color("Error")
15
+ public static let info = Color("Info")
16
+ public static let success = Color("Success")
17
+ ```
18
+ > You can refer Colors class with static colors