@codeleap/mobile 1.9.28 → 1.9.29

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 (116) hide show
  1. package/dist/components/Backdrop.d.ts +66 -0
  2. package/dist/components/Backdrop.js +70 -0
  3. package/dist/components/Backdrop.js.map +1 -0
  4. package/dist/components/Button.d.ts +3 -3
  5. package/dist/components/Button.js.map +1 -1
  6. package/dist/components/FileInput.js +0 -2
  7. package/dist/components/FileInput.js.map +1 -1
  8. package/dist/components/Image.js +2 -2
  9. package/dist/components/Image.js.map +1 -1
  10. package/dist/components/List.d.ts +23 -4
  11. package/dist/components/List.js +17 -1
  12. package/dist/components/List.js.map +1 -1
  13. package/dist/components/Modal/index.d.ts +1 -1
  14. package/dist/components/Modal/index.js +26 -27
  15. package/dist/components/Modal/index.js.map +1 -1
  16. package/dist/components/Modal/styles.d.ts +3 -9
  17. package/dist/components/Modal/styles.js +26 -17
  18. package/dist/components/Modal/styles.js.map +1 -1
  19. package/dist/components/NewModal/index.d.ts +27 -0
  20. package/dist/components/NewModal/index.js +99 -0
  21. package/dist/components/NewModal/index.js.map +1 -0
  22. package/dist/components/NewModal/styles.d.ts +57 -0
  23. package/dist/components/NewModal/styles.js +58 -0
  24. package/dist/components/NewModal/styles.js.map +1 -0
  25. package/dist/components/Overlay.js +13 -9
  26. package/dist/components/Overlay.js.map +1 -1
  27. package/dist/components/Scroll.d.ts +4 -2
  28. package/dist/components/Scroll.js.map +1 -1
  29. package/dist/components/SegmentedControl/index.d.ts +42 -0
  30. package/dist/components/SegmentedControl/index.js +137 -0
  31. package/dist/components/SegmentedControl/index.js.map +1 -0
  32. package/dist/components/SegmentedControl/styles.d.ts +54 -0
  33. package/dist/components/SegmentedControl/styles.js +36 -0
  34. package/dist/components/SegmentedControl/styles.js.map +1 -0
  35. package/dist/components/SegmentedControl.d.ts +5 -0
  36. package/dist/components/SegmentedControl.js +32 -0
  37. package/dist/components/SegmentedControl.js.map +1 -0
  38. package/dist/components/Select/index.js +1 -1
  39. package/dist/components/Select/index.js.map +1 -1
  40. package/dist/components/Text.d.ts +8 -3
  41. package/dist/components/Text.js +12 -5
  42. package/dist/components/Text.js.map +1 -1
  43. package/dist/components/TextInput.d.ts +4 -2
  44. package/dist/components/TextInput.js +2 -2
  45. package/dist/components/TextInput.js.map +1 -1
  46. package/dist/components/Touchable.d.ts +5 -3
  47. package/dist/components/Touchable.js +26 -19
  48. package/dist/components/Touchable.js.map +1 -1
  49. package/dist/components/View.js +1 -1
  50. package/dist/components/View.js.map +1 -1
  51. package/dist/components/_Modal/index.d.ts +27 -0
  52. package/dist/components/_Modal/index.js +114 -0
  53. package/dist/components/_Modal/index.js.map +1 -0
  54. package/dist/components/_Modal/styles.d.ts +64 -0
  55. package/dist/components/_Modal/styles.js +60 -0
  56. package/dist/components/_Modal/styles.js.map +1 -0
  57. package/dist/components/components.d.ts +2 -0
  58. package/dist/components/components.js +2 -0
  59. package/dist/components/components.js.map +1 -1
  60. package/dist/index.d.ts +3 -0
  61. package/dist/index.js +16 -1
  62. package/dist/index.js.map +1 -1
  63. package/dist/utils/ModalManager/components.d.ts +5 -5
  64. package/dist/utils/ModalManager/components.js +16 -9
  65. package/dist/utils/ModalManager/components.js.map +1 -1
  66. package/dist/utils/ModalManager/context.d.ts +8 -3
  67. package/dist/utils/ModalManager/context.js +47 -23
  68. package/dist/utils/ModalManager/context.js.map +1 -1
  69. package/dist/utils/ModalManager/index.d.ts +3 -7
  70. package/dist/utils/ModalManager/index.js +1 -1
  71. package/dist/utils/ModalManager/index.js.map +1 -1
  72. package/dist/utils/PermissionManager/components.d.ts +18 -0
  73. package/dist/utils/PermissionManager/components.js +52 -0
  74. package/dist/utils/PermissionManager/components.js.map +1 -0
  75. package/dist/utils/PermissionManager/context.d.ts +52 -0
  76. package/dist/utils/PermissionManager/context.js +325 -0
  77. package/dist/utils/PermissionManager/context.js.map +1 -0
  78. package/dist/utils/PermissionManager/index.d.ts +4 -0
  79. package/dist/utils/PermissionManager/index.js +9 -0
  80. package/dist/utils/PermissionManager/index.js.map +1 -0
  81. package/dist/utils/PermissionManager/types.d.ts +13 -0
  82. package/dist/utils/PermissionManager/types.js +3 -0
  83. package/dist/utils/PermissionManager/types.js.map +1 -0
  84. package/dist/utils/hooks.d.ts +6 -0
  85. package/dist/utils/hooks.js +62 -0
  86. package/dist/utils/hooks.js.map +1 -0
  87. package/package.json +1 -1
  88. package/src/components/Backdrop.tsx +77 -0
  89. package/src/components/Button.tsx +3 -2
  90. package/src/components/FileInput.tsx +2 -2
  91. package/src/components/Image.tsx +3 -2
  92. package/src/components/List.tsx +44 -5
  93. package/src/components/Modal/index.tsx +38 -49
  94. package/src/components/Modal/styles.ts +35 -31
  95. package/src/components/Overlay.tsx +22 -13
  96. package/src/components/Scroll.tsx +3 -1
  97. package/src/components/SegmentedControl/index.tsx +182 -0
  98. package/src/components/SegmentedControl/styles.ts +65 -0
  99. package/src/components/Select/index.tsx +1 -2
  100. package/src/components/Text.tsx +23 -10
  101. package/src/components/TextInput.tsx +4 -2
  102. package/src/components/Touchable.tsx +31 -20
  103. package/src/components/View.tsx +1 -1
  104. package/src/components/_Modal/index.tsx +162 -0
  105. package/src/components/_Modal/styles.ts +125 -0
  106. package/src/components/components.ts +3 -0
  107. package/src/index.ts +6 -0
  108. package/src/modules/imageCropPicker.d.ts +497 -0
  109. package/src/modules/index.d.ts +186 -0
  110. package/src/utils/ModalManager/components.tsx +20 -9
  111. package/src/utils/ModalManager/context.tsx +69 -30
  112. package/src/utils/ModalManager/index.ts +6 -2
  113. package/src/utils/PermissionManager/context.tsx +299 -0
  114. package/src/utils/PermissionManager/index.ts +20 -0
  115. package/src/utils/PermissionManager/types.ts +24 -0
  116. package/src/utils/hooks.ts +65 -0
@@ -494,3 +494,189 @@ declare module 'react-native-image-crop-picker' {
494
494
 
495
495
  export default ImageCropPicker
496
496
  }
497
+
498
+ import * as React from 'react'
499
+ import {
500
+ ScrollViewProps,
501
+ FlatListProps,
502
+ SectionListProps,
503
+ } from 'react-native'
504
+ export namespace KeyboardAwareScrollViewTypes {
505
+ interface KeyboardAwareProps {
506
+ /**
507
+ * Catches the reference of the component.
508
+ *
509
+ *
510
+ * @type {function}
511
+ * @memberof KeyboardAwareProps
512
+ */
513
+ innerRef?: (ref: JSX.Element) => void
514
+ /**
515
+ * Adds an extra offset that represents the TabBarIOS height.
516
+ *
517
+ * Default is false
518
+ * @type {boolean}
519
+ * @memberof KeyboardAwareProps
520
+ */
521
+ viewIsInsideTabBar?: boolean
522
+
523
+ /**
524
+ * Coordinates that will be used to reset the scroll when the keyboard hides.
525
+ *
526
+ * @type {{
527
+ * x: number,
528
+ * y: number
529
+ * }}
530
+ * @memberof KeyboardAwareProps
531
+ */
532
+ resetScrollToCoords?: {
533
+ x: number
534
+ y: number
535
+ }
536
+
537
+ /**
538
+ * Lets the user enable or disable automatic resetScrollToCoords
539
+ *
540
+ * @type {boolean}
541
+ * @memberof KeyboardAwareProps
542
+ */
543
+ enableResetScrollToCoords?: boolean
544
+
545
+ /**
546
+ * When focus in TextInput will scroll the position
547
+ *
548
+ * Default is true
549
+ *
550
+ * @type {boolean}
551
+ * @memberof KeyboardAwareProps
552
+ */
553
+
554
+ enableAutomaticScroll?: boolean
555
+ /**
556
+ * Enables keyboard aware settings for Android
557
+ *
558
+ * Default is false
559
+ *
560
+ * @type {boolean}
561
+ * @memberof KeyboardAwareProps
562
+ */
563
+ enableOnAndroid?: boolean
564
+
565
+ /**
566
+ * Adds an extra offset when focusing the TextInputs.
567
+ *
568
+ * Default is 75
569
+ * @type {number}
570
+ * @memberof KeyboardAwareProps
571
+ */
572
+ extraHeight?: number
573
+
574
+ /**
575
+ * Adds an extra offset to the keyboard.
576
+ * Useful if you want to stick elements above the keyboard.
577
+ *
578
+ * Default is 0
579
+ *
580
+ * @type {number}
581
+ * @memberof KeyboardAwareProps
582
+ */
583
+ extraScrollHeight?: number
584
+
585
+ /**
586
+ * Sets the delay time before scrolling to new position
587
+ *
588
+ * Default is 250
589
+ *
590
+ * @type {number}
591
+ * @memberof KeyboardAwareProps
592
+ */
593
+ keyboardOpeningTime?: number
594
+
595
+ /**
596
+ * Callback when the keyboard will show.
597
+ *
598
+ * @param frames Information about the keyboard frame and animation.
599
+ */
600
+ onKeyboardWillShow?: (frames: Object) => void
601
+
602
+ /**
603
+ * Callback when the keyboard did show.
604
+ *
605
+ * @param frames Information about the keyboard frame and animation.
606
+ */
607
+ onKeyboardDidShow?: (frames: Object) => void
608
+
609
+ /**
610
+ * Callback when the keyboard will hide.
611
+ *
612
+ * @param frames Information about the keyboard frame and animation.
613
+ */
614
+ onKeyboardWillHide?: (frames: Object) => void
615
+
616
+ /**
617
+ * Callback when the keyboard did hide.
618
+ *
619
+ * @param frames Information about the keyboard frame and animation.
620
+ */
621
+ onKeyboardDidHide?: (frames: Object) => void
622
+
623
+ /**
624
+ * Callback when the keyboard frame will change.
625
+ *
626
+ * @param frames Information about the keyboard frame and animation.
627
+ */
628
+ onKeyboardWillChangeFrame?: (frames: Object) => void
629
+
630
+ /**
631
+ * Callback when the keyboard frame did change.
632
+ *
633
+ * @param frames Information about the keyboard frame and animation.
634
+ */
635
+ onKeyboardDidChangeFrame?: (frames: Object) => void
636
+ }
637
+
638
+ interface KeyboardAwareScrollViewProps
639
+ extends KeyboardAwareProps,
640
+ ScrollViewProps {}
641
+ interface KeyboardAwareFlatListProps<ItemT>
642
+ extends KeyboardAwareProps,
643
+ FlatListProps<ItemT> {}
644
+ interface KeyboardAwareSectionListProps<ItemT>
645
+ extends KeyboardAwareProps,
646
+ SectionListProps<ItemT> {}
647
+
648
+ interface KeyboardAwareState {
649
+ keyboardSpace: number
650
+ }
651
+
652
+ declare class ScrollableComponent<P, S> extends React.Component<P, S> {
653
+ getScrollResponder: () => void
654
+
655
+ scrollToPosition: (x: number, y: number, animated?: boolean) => void
656
+
657
+ scrollToEnd: (animated?: boolean) => void
658
+
659
+ scrollForExtraHeightOnAndroid: (extraHeight: number) => void
660
+
661
+ scrollToFocusedInput: (
662
+ reactNode: Object,
663
+ extraHeight?: number,
664
+ keyboardOpeningTime?: number
665
+ ) => void
666
+ }
667
+
668
+ export class KeyboardAwareMixin {}
669
+ export class KeyboardAwareScrollView extends ScrollableComponent<
670
+ KeyboardAwareScrollViewProps,
671
+ KeyboardAwareState
672
+ > {}
673
+ export class KeyboardAwareFlatList extends ScrollableComponent<
674
+ KeyboardAwareFlatListProps<any>,
675
+ KeyboardAwareState
676
+ > {}
677
+ export class KeyboardAwareSectionList extends ScrollableComponent<
678
+ KeyboardAwareSectionListProps<any>,
679
+ KeyboardAwareState
680
+ > {}
681
+
682
+ }
@@ -2,19 +2,21 @@ import * as React from 'react'
2
2
  import { usePrevious, onMount, onUpdate, PropsOf } from '@codeleap/common'
3
3
  import { useModalContext } from './context'
4
4
  import { Portal } from '@gorhom/portal'
5
- import { Modal } from '../../components/Modal'
5
+ import { Modal as _Modal } from '../../components/Modal'
6
6
 
7
- type AbsoluteModalProps = Omit<PropsOf<typeof Modal>, 'visible' | 'toggle'> & {
7
+ export type ManagedModalProps<T = PropsOf<typeof _Modal>> = Omit<T, 'visible' | 'toggle'> & {
8
8
  id?: string
9
9
  initialVisible ?: boolean
10
10
  parent?: string
11
+ absolute?: boolean
11
12
  visible?: boolean
12
- toggle?: PropsOf<typeof Modal>['toggle']
13
+ toggle?: PropsOf<typeof _Modal>['toggle']
13
14
  }
14
15
 
15
- export const AbsoluteModal:React.FC<AbsoluteModalProps> = ({
16
+ export const Modal:React.FC<ManagedModalProps> = ({
16
17
  children,
17
18
  id,
19
+ absolute = true,
18
20
  initialVisible = false,
19
21
  parent,
20
22
  ...props
@@ -43,16 +45,25 @@ export const AbsoluteModal:React.FC<AbsoluteModalProps> = ({
43
45
 
44
46
  const visible = modalId ? modals.isVisible(modalId) : props.visible
45
47
 
46
- return <Portal>
47
- <Modal {...props} visible={visible} toggle={() => {
48
+ const ctxProps = modals?.state?.[modalId]?.props
49
+ const content = (
50
+ <_Modal {...props} {...ctxProps} visible={visible} toggle={() => {
48
51
  if (modalId) {
49
52
  modals.toggleModal(modalId)
50
53
  } else {
51
- props.toggle()
54
+ props?.toggle?.()
52
55
  }
53
56
  }}>
54
57
  {children}
55
- </Modal>
56
- </Portal>
58
+ </_Modal>
59
+ )
60
+
61
+ if (absolute) {
62
+ return <Portal>
63
+ {content}
64
+ </Portal>
65
+ }
66
+
67
+ return content
57
68
  }
58
69
 
@@ -1,25 +1,29 @@
1
1
  import * as React from 'react'
2
- import { AnyFunction, useCodeleapContext, useState } from '@codeleap/common'
2
+ import { AnyFunction, onUpdate, TypeGuards, useCodeleapContext, useState } from '@codeleap/common'
3
3
  import { PortalProvider } from '@gorhom/portal'
4
+ import { ModalProps } from '../../components/Modal'
4
5
 
5
6
  export type AppModalProps = {
6
7
  visible: boolean
7
8
  attachments: string[]
8
9
  attachedTo: string[]
10
+ props?: any
9
11
  }
10
12
  type TModalState = AppModalProps
11
13
  type ModalTransitionOptions = {
12
14
  duration?: number
15
+ props?: any
13
16
  }
14
17
 
15
18
  type TModalContext = {
16
- state: Record<string, TModalState>
17
- toggleModal: (name: string, setTo?: boolean) => void
18
- setModal: (name: string, to: Partial<TModalState>) => void
19
- currentModal: string
19
+ state: Record<string, TModalState>
20
+ toggleModal: (name: string, setTo?: boolean, props?: any) => void
21
+ setModal: (name: string, to: Partial<TModalState>) => void
22
+ currentModal: string
20
23
  isVisible: (name: string) => boolean
21
24
  transition: (from: string, to: string, options?: ModalTransitionOptions) => Promise<void>
22
- attach: (modal: string, to: string) => void
25
+ attach: (modal: string, to: string) => void
26
+ transitionDuration: number
23
27
  }
24
28
 
25
29
  const ModalContext = React.createContext({} as TModalContext)
@@ -32,7 +36,7 @@ export function Provider({ children }) {
32
36
  return !!modals[name]?.visible
33
37
  }
34
38
 
35
- const toggleModal:TModalContext['toggleModal'] = (name, set?: boolean) => {
39
+ const toggleModal:TModalContext['toggleModal'] = (name, set?: boolean, props?: any) => {
36
40
  const visible = isVisible(name)
37
41
 
38
42
  const newVisible = typeof set === 'boolean' ? set : !visible
@@ -44,6 +48,7 @@ export function Provider({ children }) {
44
48
  [name]: {
45
49
  ...current[name],
46
50
  visible: newVisible,
51
+ props,
47
52
  },
48
53
  ...Object.fromEntries(attached),
49
54
  }
@@ -64,30 +69,37 @@ export function Provider({ children }) {
64
69
  }
65
70
 
66
71
  const codeleapCtx = useCodeleapContext()
67
-
72
+ const defaultDuration = codeleapCtx?.Theme?.values?.transitions?.modal?.duration || 300
68
73
  const transition:TModalContext['transition'] = (from, to, options) => {
69
- const _options:ModalTransitionOptions = {
70
- duration: codeleapCtx?.Theme?.values?.modalTransitionDuration || 300,
71
- ...options,
72
- }
73
-
74
- const toVisible = isVisible(to)
75
- const fromVisible = isVisible(from)
76
- if (toVisible) return
77
- if (!fromVisible && !toVisible) {
78
- toggleModal(to)
79
- return
80
- }
81
-
82
- toggleModal(from)
83
74
  return new Promise((resolve) => {
84
75
  setTimeout(() => {
85
- if (to) {
86
- toggleModal(to)
76
+
77
+ if (!from) {
78
+ toggleModal(to, true, options?.props)
79
+ return
80
+ }
81
+ const _options:ModalTransitionOptions = {
82
+ duration: defaultDuration,
83
+ ...options,
87
84
  }
88
- resolve()
89
- }, _options.duration)
90
85
 
86
+ const toVisible = isVisible(to)
87
+ const fromVisible = isVisible(from)
88
+
89
+ // if (!fromVisible && !toVisible) {
90
+ // toggleModal(to, true, options?.props)
91
+ // return
92
+ // }
93
+
94
+ toggleModal(from, false)
95
+ setTimeout(() => {
96
+
97
+ toggleModal(to, true, options?.props)
98
+
99
+ resolve()
100
+ }, _options.duration)
101
+
102
+ })
91
103
  })
92
104
  }
93
105
 
@@ -123,6 +135,7 @@ export function Provider({ children }) {
123
135
  attach,
124
136
  isVisible,
125
137
  transition,
138
+ transitionDuration: defaultDuration,
126
139
 
127
140
  }}>
128
141
  <PortalProvider>
@@ -143,6 +156,7 @@ export type UseModalSequenceOptions = {
143
156
  closeLastOnFinish?: boolean
144
157
  waitForLastToCloseBeforeCallingFinish?: boolean
145
158
  transitionOpts?: Partial<Parameters<TModalContext['transition']>[2]>
159
+ autoOpen?: boolean
146
160
  }
147
161
 
148
162
  export function useModalSequence(ids: string[], options?: UseModalSequenceOptions) {
@@ -163,7 +177,16 @@ export function useModalSequence(ids: string[], options?: UseModalSequenceOption
163
177
  nextId: ids[idx + 1],
164
178
  previousId: ids[idx - 1],
165
179
  }
166
- function next() {
180
+
181
+ onUpdate(() => {
182
+ if (_options.autoOpen && typeof ids?.[0] === 'number') {
183
+ if (!modals.isVisible(ids[0])) {
184
+ modals.toggleModal(ids[0])
185
+ }
186
+ }
187
+ }, [_options.autoOpen, ids?.[0]])
188
+
189
+ function next(props?: any) {
167
190
  if (idx === ids.length - 1) {
168
191
  if (_options.closeLastOnFinish) {
169
192
  modals.transition(ids[idx], null).then(() => {
@@ -181,16 +204,31 @@ export function useModalSequence(ids: string[], options?: UseModalSequenceOption
181
204
  return
182
205
  } else {
183
206
  if (!state.nextId) return
184
- modals.transition(ids[idx], ids[idx + 1])
207
+ modals.transition(ids[idx], state.nextId, props)
185
208
  setIdx(i => i + 1)
186
209
  }
187
210
  }
188
- function previous() {
211
+ function previous(props?: any) {
189
212
  if (!state.previousId) return
190
- modals.transition(ids[idx], ids[idx - 1])
213
+
214
+ modals.transition(ids[idx], state.previousId, props)
191
215
  setIdx(i => i - 1)
192
216
 
193
217
  }
218
+
219
+ function goto(idxOrId: string | number, props?: any) {
220
+ let newId:string = null
221
+ if (TypeGuards.isString(idxOrId)) {
222
+ newId = idxOrId
223
+
224
+ } else {
225
+ newId = ids[idxOrId]
226
+ }
227
+ modals.transition(ids[idx], newId, {
228
+ props,
229
+ })
230
+ setIdx(ids.indexOf(newId))
231
+ }
194
232
  function reset() {
195
233
  setIdx(0)
196
234
  }
@@ -200,6 +238,7 @@ export function useModalSequence(ids: string[], options?: UseModalSequenceOption
200
238
  next,
201
239
  previous,
202
240
  setModal: setIdx,
241
+ goto,
203
242
  currentIdx: idx,
204
243
  ...state,
205
244
 
@@ -1,9 +1,13 @@
1
1
  import { useModalContext, useModalSequence, Provider } from './context'
2
- import { AbsoluteModal } from './components'
2
+ import { Modal, ManagedModalProps } from './components'
3
3
 
4
4
  export const ModalManager = {
5
5
  useModalContext,
6
- AbsoluteModal,
6
+ Modal,
7
7
  Provider,
8
8
  useModalSequence,
9
9
  }
10
+
11
+ export type {
12
+ ManagedModalProps,
13
+ }