@codeleap/mobile 2.0.0 → 2.0.3

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 (105) hide show
  1. package/dist/components/ActionIcon/styles.d.ts +58 -58
  2. package/dist/components/Backdrop/index.js +1 -1
  3. package/dist/components/Backdrop/index.js.map +1 -1
  4. package/dist/components/Button/index.d.ts +109 -109
  5. package/dist/components/Button/index.js +5 -7
  6. package/dist/components/Button/index.js.map +1 -1
  7. package/dist/components/Button/styles.d.ts +60 -55
  8. package/dist/components/Button/styles.js +4 -2
  9. package/dist/components/Button/styles.js.map +1 -1
  10. package/dist/components/Checkbox/index.js +4 -2
  11. package/dist/components/Checkbox/index.js.map +1 -1
  12. package/dist/components/Checkbox/styles.d.ts +1 -1
  13. package/dist/components/Checkbox/styles.js +4 -0
  14. package/dist/components/Checkbox/styles.js.map +1 -1
  15. package/dist/components/FileInput/index.d.ts +1 -1
  16. package/dist/components/Image/index.js +3 -0
  17. package/dist/components/Image/index.js.map +1 -1
  18. package/dist/components/Modal/index.js +1 -1
  19. package/dist/components/Modal/index.js.map +1 -1
  20. package/dist/components/MultiSelect/styles.js +1 -4
  21. package/dist/components/MultiSelect/styles.js.map +1 -1
  22. package/dist/components/Navigation/utils.js +0 -1
  23. package/dist/components/Navigation/utils.js.map +1 -1
  24. package/dist/components/Pager/styles.js +13 -11
  25. package/dist/components/Pager/styles.js.map +1 -1
  26. package/dist/components/RadioInput/index.js +3 -1
  27. package/dist/components/RadioInput/index.js.map +1 -1
  28. package/dist/components/RadioInput/styles.d.ts +1 -1
  29. package/dist/components/RadioInput/styles.js +1 -0
  30. package/dist/components/RadioInput/styles.js.map +1 -1
  31. package/dist/components/SegmentedControl/index.d.ts +10 -1
  32. package/dist/components/SegmentedControl/index.js +27 -27
  33. package/dist/components/SegmentedControl/index.js.map +1 -1
  34. package/dist/components/SegmentedControl/styles.d.ts +56 -51
  35. package/dist/components/SegmentedControl/styles.js +10 -3
  36. package/dist/components/SegmentedControl/styles.js.map +1 -1
  37. package/dist/components/Select/index.js +1 -2
  38. package/dist/components/Select/index.js.map +1 -1
  39. package/dist/components/Select/styles.d.ts +1 -1
  40. package/dist/components/Select/styles.js +4 -1
  41. package/dist/components/Select/styles.js.map +1 -1
  42. package/dist/components/Switch/index.js +1 -1
  43. package/dist/components/Switch/index.js.map +1 -1
  44. package/dist/components/Text/index.d.ts +2 -0
  45. package/dist/components/Text/index.js +43 -3
  46. package/dist/components/Text/index.js.map +1 -1
  47. package/dist/components/Text/styles.d.ts +57 -52
  48. package/dist/components/Text/styles.js +11 -3
  49. package/dist/components/Text/styles.js.map +1 -1
  50. package/dist/components/TextInput/index.d.ts +8 -4
  51. package/dist/components/TextInput/index.js +35 -15
  52. package/dist/components/TextInput/index.js.map +1 -1
  53. package/dist/components/TextInput/styles.d.ts +1 -1
  54. package/dist/components/TextInput/styles.js +11 -3
  55. package/dist/components/TextInput/styles.js.map +1 -1
  56. package/dist/components/Touchable/index.d.ts +1 -1
  57. package/dist/components/Touchable/index.js +77 -42
  58. package/dist/components/Touchable/index.js.map +1 -1
  59. package/dist/components/Touchable/styles.d.ts +56 -51
  60. package/dist/components/Touchable/styles.js +6 -1
  61. package/dist/components/Touchable/styles.js.map +1 -1
  62. package/dist/components/defaultStyles.d.ts +263 -263
  63. package/dist/utils/KeyboardAware/lib/KeyboardAwareHOC.d.ts +2 -0
  64. package/dist/utils/KeyboardAware/lib/KeyboardAwareHOC.js +287 -286
  65. package/dist/utils/KeyboardAware/lib/KeyboardAwareHOC.js.map +1 -1
  66. package/dist/utils/OSAlert.d.ts +6 -5
  67. package/dist/utils/OSAlert.js +7 -6
  68. package/dist/utils/OSAlert.js.map +1 -1
  69. package/dist/utils/hooks.d.ts +34 -1
  70. package/dist/utils/hooks.js +54 -1
  71. package/dist/utils/hooks.js.map +1 -1
  72. package/dist/utils/index.d.ts +1 -1
  73. package/dist/utils/index.js +2 -6
  74. package/dist/utils/index.js.map +1 -1
  75. package/dist/utils/notifications.js +4 -4
  76. package/dist/utils/notifications.js.map +1 -1
  77. package/package.json +1 -1
  78. package/src/components/Backdrop/index.tsx +1 -1
  79. package/src/components/Button/index.tsx +7 -11
  80. package/src/components/Button/styles.ts +34 -10
  81. package/src/components/Checkbox/index.tsx +4 -1
  82. package/src/components/Checkbox/styles.ts +5 -0
  83. package/src/components/Image/index.tsx +3 -0
  84. package/src/components/Modal/index.tsx +1 -1
  85. package/src/components/MultiSelect/styles.ts +1 -8
  86. package/src/components/Navigation/utils.tsx +0 -2
  87. package/src/components/Pager/styles.ts +16 -11
  88. package/src/components/RadioInput/index.tsx +3 -1
  89. package/src/components/RadioInput/styles.ts +2 -1
  90. package/src/components/SegmentedControl/index.tsx +31 -18
  91. package/src/components/SegmentedControl/styles.ts +29 -7
  92. package/src/components/Select/index.tsx +2 -1
  93. package/src/components/Select/styles.ts +12 -2
  94. package/src/components/Switch/index.tsx +1 -1
  95. package/src/components/Text/index.tsx +57 -7
  96. package/src/components/Text/styles.ts +25 -9
  97. package/src/components/TextInput/index.tsx +44 -9
  98. package/src/components/TextInput/styles.ts +14 -4
  99. package/src/components/Touchable/index.tsx +84 -35
  100. package/src/components/Touchable/styles.ts +15 -3
  101. package/src/utils/KeyboardAware/lib/KeyboardAwareHOC.tsx +34 -24
  102. package/src/utils/OSAlert.ts +10 -10
  103. package/src/utils/hooks.ts +82 -2
  104. package/src/utils/index.ts +2 -2
  105. package/src/utils/notifications.ts +4 -4
@@ -7,14 +7,14 @@ import {
7
7
 
8
8
  useCodeleapContext,
9
9
  AnyFunction,
10
- defaultPresets,
11
10
  } from '@codeleap/common'
12
- import { Platform, Pressable, StyleSheet, View as RNView } from 'react-native'
11
+ import { Pressable, StyleSheet, View as RNView } from 'react-native'
13
12
 
14
13
  import { createAnimatableComponent } from 'react-native-animatable'
15
14
  import { TouchableComposition, TouchableStyles } from './styles'
16
15
  import { StylesOf } from '../../types'
17
16
  import { View } from '../View'
17
+ import { usePressableFeedback } from '../../utils'
18
18
  export type TouchableProps = Omit<
19
19
  ComponentPropsWithoutRef<typeof Pressable>,
20
20
  'onPress'
@@ -25,18 +25,19 @@ export type TouchableProps = Omit<
25
25
  debugName: string
26
26
  activeOpacity?: number
27
27
  debugComponent?: string
28
- feedbackVariant?: 'opacity' | 'none' | 'highlight'
29
28
  onPress?: AnyFunction
29
+ noFeedback?: boolean
30
30
  styles?: StylesOf<TouchableComposition>
31
31
  } & BaseViewProps
32
32
  export * from './styles'
33
33
 
34
- const rippleStyles = {
34
+ const defaultWrapperStyles = {
35
35
  paddingTop: 0,
36
36
  paddingLeft: 0,
37
37
  paddingRight: 0,
38
38
  paddingBottom: 0,
39
39
  overflow: 'hidden',
40
+ alignItems: 'stretch',
40
41
  }
41
42
 
42
43
  const defaultPressableStyles = {
@@ -44,12 +45,22 @@ const defaultPressableStyles = {
44
45
  marginLeft: 0,
45
46
  marginRight: 0,
46
47
  marginBottom: 0,
48
+
49
+ }
50
+
51
+ const ripplePressableStyles = {
52
+ // position: 'absolute',
53
+ // top: 0,
54
+ // left: 0,
55
+ // right: 0,
56
+ // bottom: 0,
57
+ // width: '100%',
58
+ // minWidth: '100%',
59
+ // maxWidth: '100%',
47
60
  // height: '100%',
48
- minWidth: '100%',
49
61
  // minHeight: '100%',
50
62
  // maxHeight: '100%',
51
- maxWidth: '100%',
52
-
63
+ // flex: 1,
53
64
  }
54
65
 
55
66
  export const Touchable: React.FC<TouchableProps> = forwardRef<
@@ -61,14 +72,13 @@ export const Touchable: React.FC<TouchableProps> = forwardRef<
61
72
  children,
62
73
  onPress,
63
74
  style,
64
- activeOpacity = 0.5,
65
75
  debugName,
66
76
  debugComponent,
77
+ noFeedback = false,
67
78
  styles,
68
- feedbackVariant = 'opacity',
69
79
  ...props
70
80
  } = touchableProps
71
- const _feedbackVariant = onPress ? feedbackVariant : 'none'
81
+
72
82
  const variantStyles = useDefaultComponentStyle<'u:Touchable', typeof TouchableStyles>('u:Touchable', {
73
83
  variants,
74
84
  transform: StyleSheet.flatten,
@@ -91,38 +101,77 @@ export const Touchable: React.FC<TouchableProps> = forwardRef<
91
101
 
92
102
  const _styles = StyleSheet.flatten([variantStyles.wrapper, style])
93
103
 
94
- const hasRipple = (!!variantStyles.ripple || !!props.android_ripple) && _feedbackVariant !== 'none'
95
- function getFeedbackStyle(pressed:boolean) {
96
- if (Platform.OS === 'android' && hasRipple) return {}
97
- switch (_feedbackVariant) {
98
- case 'highlight':
99
- return {
100
- backgroundColor: pressed ? '#e0e0e0' : 'transparent',
101
- }
102
- break
103
- case 'opacity':
104
- return {
105
- opacity: pressed ? activeOpacity : 1,
106
- }
107
- case 'none':
108
- return {}
109
- }
110
- }
104
+ const disableFeedback = !onPress || noFeedback
111
105
 
112
- const rippleConfig = hasRipple ? {
113
- ...(variantStyles.ripple || {}),
114
- ...(props.android_ripple || {}),
115
- } : null
106
+ const { rippleConfig, getFeedbackStyle } = usePressableFeedback(_styles, {
107
+ hightlightPropertyIn: 'backgroundColor',
108
+ hightlightPropertyOut: 'backgroundColor',
109
+ disabled: disableFeedback,
110
+ feedbackConfig: variantStyles?.feedback,
111
+ })
116
112
 
117
113
  const Wrapper = View
118
114
 
115
+ const { wrapperStyle, pressableStyle } = React.useMemo(() => {
116
+ const wrapperkeys = [
117
+ 'margin',
118
+ 'alignSelf',
119
+ 'border',
120
+ // 'flex!',
121
+ ]
122
+ const sharedKeys = [
123
+ 'width!',
124
+ 'height!',
125
+ 'flex!',
126
+ 'position!',
127
+ 'top!',
128
+ 'left!',
129
+ 'right!',
130
+ 'bottom!',
131
+ ]
132
+
133
+ const wrapperStyle = {} as any
134
+ const pressableStyle = {} as any
135
+ const match = (k, key) => {
136
+ if (k.endsWith('!')) {
137
+ return key === k.substring(0, k.length - 1)
138
+ } else {
139
+
140
+ return key.startsWith(k)
141
+ }
142
+ }
143
+ Object.entries(_styles).forEach(([key, value]) => {
144
+
145
+ if (wrapperkeys.some(k => match(k, key))) {
146
+ wrapperStyle[key] = value
147
+ } else if (sharedKeys.some(k => match(k, key))) {
148
+ wrapperStyle[key] = value
149
+
150
+ pressableStyle[key] = value
151
+ } else {
152
+ pressableStyle[key] = value
153
+ }
154
+ })
155
+
156
+ wrapperStyle.overflow = 'hidden'
157
+ // wrapperStyle.flexDirection = 'row'
158
+ // wrapperStyle.alignItems = 'stretch'
159
+
160
+ return {
161
+ wrapperStyle,
162
+ pressableStyle,
163
+ }
164
+ }, [JSON.stringify(_styles)])
165
+
119
166
  return (
120
- <Wrapper style={[_styles, rippleStyles]}>
167
+ <Wrapper style={[wrapperStyle]}>
121
168
  <Pressable onPress={press} style={({ pressed }) => ([
169
+
170
+ // defaultPressableStyles,
171
+ pressableStyle,
172
+ // !!rippleConfig && ripplePressableStyles,
122
173
  getFeedbackStyle(pressed),
123
- variantStyles.pressable,
124
- _styles,
125
- defaultPressableStyles,
174
+
126
175
  ])} android_ripple={rippleConfig} {...props} ref={ref}>
127
176
  {children}
128
177
  </Pressable>
@@ -1,8 +1,17 @@
1
1
  import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+ import { StylesOf } from '../../types'
3
+ import { TouchableFeedbackConfig } from '../../utils'
2
4
 
3
- export type TouchableComposition = 'wrapper' | 'ripple' | 'pressable'
5
+ export type TouchableComposition = 'wrapper' | 'feedback' | 'pressable'
4
6
 
5
- const createTouchableStyle = createDefaultVariantFactory<TouchableComposition>()
7
+ export type TouchableStylesGen<TCSS = any> = StylesOf<Exclude<TouchableComposition, 'feedback'>> & {
8
+ feedback?: TouchableFeedbackConfig
9
+ }
10
+
11
+ const createTouchableStyle = createDefaultVariantFactory<
12
+ TouchableComposition,
13
+ TouchableStylesGen
14
+ >()
6
15
 
7
16
  const presets = includePresets((styles) => createTouchableStyle(() => ({ wrapper: styles, pressable: styles })),
8
17
  )
@@ -10,7 +19,10 @@ const presets = includePresets((styles) => createTouchableStyle(() => ({ wrapper
10
19
  export const TouchableStyles = {
11
20
  ...presets,
12
21
  default: createTouchableStyle((t) => ({
13
-
22
+ feedback: {
23
+ type: 'opacity',
24
+ value: 0.5,
25
+ },
14
26
  })),
15
27
 
16
28
  }
@@ -15,6 +15,7 @@ import {
15
15
  EventSubscription,
16
16
  KeyboardEventListener,
17
17
  NativeSyntheticEvent,
18
+ ScrollView,
18
19
  } from 'react-native'
19
20
  import type { KeyboardAwareInterface } from './KeyboardAwareInterface'
20
21
  export function isIphoneX() {
@@ -74,7 +75,9 @@ export type KeyboardAwareHOCProps = {
74
75
  update?: Function
75
76
  contentContainerStyle?: any
76
77
  enableOnAndroid?: boolean
78
+ Scrollable: any
77
79
  innerRef?: Function
80
+ hocOptions?: any
78
81
  } & typeof keyboardAwareHOCTypeEvents
79
82
  export type KeyboardAwareHOCState = {
80
83
  keyboardSpace: number
@@ -157,18 +160,7 @@ const ScrollIntoViewDefaultOptions: KeyboardAwareHOCOptions = {
157
160
  },
158
161
  }
159
162
 
160
- function KeyboardAwareHOC(
161
- ScrollableComponent: React.ComponentClass<any>,
162
- userOptions = ScrollIntoViewDefaultOptions,
163
- ) {
164
-
165
- const hocOptions: KeyboardAwareHOCOptions = {
166
- ...ScrollIntoViewDefaultOptions,
167
- ...userOptions,
168
- }
169
-
170
- return class extends React.Component<KeyboardAwareHOCProps, KeyboardAwareHOCState>
171
- implements KeyboardAwareInterface {
163
+ class KeyboardAwareScrollable extends React.Component<KeyboardAwareHOCProps, KeyboardAwareHOCState> implements KeyboardAwareInterface {
172
164
  _rnkasv_keyboardView: any
173
165
 
174
166
  keyboardWillShowEvent: EventSubscription
@@ -187,7 +179,7 @@ function KeyboardAwareHOC(
187
179
 
188
180
  state: KeyboardAwareHOCState
189
181
 
190
- static displayName = `KeyboardAware${getDisplayName(ScrollableComponent)}`
182
+ static displayName = `KeyboardAware`
191
183
 
192
184
  static propTypes = {
193
185
  viewIsInsideTabBar: PropTypes.bool,
@@ -213,13 +205,13 @@ function KeyboardAwareHOC(
213
205
 
214
206
  // HOC options are used to init default props, so that these options can be overriden with component props
215
207
  static defaultProps = {
216
- enableAutomaticScroll: hocOptions.enableAutomaticScroll,
217
- extraHeight: hocOptions.extraHeight,
218
- extraScrollHeight: hocOptions.extraScrollHeight,
219
- enableResetScrollToCoords: hocOptions.enableResetScrollToCoords,
220
- keyboardOpeningTime: hocOptions.keyboardOpeningTime,
221
- viewIsInsideTabBar: hocOptions.viewIsInsideTabBar,
222
- enableOnAndroid: hocOptions.enableOnAndroid,
208
+ enableAutomaticScroll: ScrollIntoViewDefaultOptions.enableAutomaticScroll,
209
+ extraHeight: ScrollIntoViewDefaultOptions.extraHeight,
210
+ extraScrollHeight: ScrollIntoViewDefaultOptions.extraScrollHeight,
211
+ enableResetScrollToCoords: ScrollIntoViewDefaultOptions.enableResetScrollToCoords,
212
+ keyboardOpeningTime: ScrollIntoViewDefaultOptions.keyboardOpeningTime,
213
+ viewIsInsideTabBar: ScrollIntoViewDefaultOptions.viewIsInsideTabBar,
214
+ enableOnAndroid: ScrollIntoViewDefaultOptions.enableOnAndroid,
223
215
  }
224
216
 
225
217
  constructor(props: KeyboardAwareHOCProps) {
@@ -533,7 +525,7 @@ function KeyboardAwareHOC(
533
525
  }
534
526
 
535
527
  _handleRef = (ref: React.ComponentClass<any>) => {
536
- this._rnkasv_keyboardView = ref ? hocOptions.extractNativeRef(ref) : ref
528
+ this._rnkasv_keyboardView = ref ? this.props.hocOptions.extractNativeRef(ref) : ref
537
529
  if (this.props.innerRef) {
538
530
  this.props.innerRef(this._rnkasv_keyboardView)
539
531
  }
@@ -552,7 +544,7 @@ function KeyboardAwareHOC(
552
544
  }
553
545
 
554
546
  render() {
555
- const { enableOnAndroid, contentContainerStyle, onScroll } = this.props
547
+ const { enableOnAndroid, contentContainerStyle, onScroll, Scrollable } = this.props
556
548
  let newContentContainerStyle
557
549
  if (Platform.OS === 'android' && enableOnAndroid) {
558
550
  newContentContainerStyle = [].concat(contentContainerStyle).concat({
@@ -561,9 +553,9 @@ function KeyboardAwareHOC(
561
553
  this.state.keyboardSpace,
562
554
  })
563
555
  }
564
- const refProps = { [hocOptions.refPropName]: this._handleRef }
556
+ const refProps = { [this.props.hocOptions.refPropName]: this._handleRef }
565
557
  return (
566
- <ScrollableComponent
558
+ <Scrollable
567
559
  {...refProps}
568
560
  keyboardDismissMode='interactive'
569
561
  contentInset={{ bottom: this.state.keyboardSpace }}
@@ -589,7 +581,25 @@ function KeyboardAwareHOC(
589
581
  />
590
582
  )
591
583
  }
584
+ }
585
+
586
+ function KeyboardAwareHOC(
587
+ ScrollableComponent: React.ComponentClass<any>,
588
+ userOptions = ScrollIntoViewDefaultOptions,
589
+ ) {
590
+
591
+ const hocOptions: KeyboardAwareHOCOptions = {
592
+ ...ScrollIntoViewDefaultOptions,
593
+ ...userOptions,
592
594
  }
595
+
596
+ return React.forwardRef((props, ref) => <KeyboardAwareScrollable
597
+ hocOptions={hocOptions}
598
+ // @ts-ignore
599
+ ref={ref}
600
+ Scrollable={ScrollableComponent}
601
+ {...props}
602
+ />)
593
603
  }
594
604
 
595
605
  // Allow to pass options, without breaking change, and curried for composition
@@ -16,14 +16,14 @@ import { Alert, AlertButton } from 'react-native'
16
16
 
17
17
  type NativeAlertArgs = Parameters<typeof Alert.alert>
18
18
 
19
- type OSAlertArgs = {
19
+ export type OSAlertArgs = {
20
20
  title: NativeAlertArgs['0']
21
21
  body?: NativeAlertArgs['1']
22
22
  options?: NativeAlertArgs['2']
23
23
  }
24
- type AlertEvent = AlertButton['onPress']
25
- type OSAlertType = 'info' | 'error' | 'warn' | 'ask'
26
- type NamedEvents<E extends string> = Partial<Record<E, AlertEvent>>
24
+ export type AlertEvent = AlertButton['onPress']
25
+ export type OSAlertType = 'info' | 'error' | 'warn' | 'ask'
26
+ export type NamedEvents<E extends string> = Partial<Record<E, AlertEvent>>
27
27
 
28
28
  const currentAlerts = {
29
29
 
@@ -57,7 +57,7 @@ function ask({ title, body, options = null }: OSAlertArgs) {
57
57
  if (!title) {
58
58
  title = 'Quick quetion'
59
59
  }
60
- OSAlert({
60
+ _OSAlert({
61
61
  title,
62
62
  body,
63
63
  options,
@@ -84,7 +84,7 @@ function warn(args: OSAlertArgs & NamedEvents<'onReject' | 'onAccept'>) {
84
84
  if (!onReject) {
85
85
  onReject = () => null
86
86
  }
87
- OSAlert({
87
+ _OSAlert({
88
88
  title,
89
89
  body,
90
90
  options: [
@@ -120,7 +120,7 @@ function info(args: OSAlertArgs & NamedEvents<'onDismiss'>) {
120
120
  if (!title) {
121
121
  title = 'FYI'
122
122
  }
123
- OSAlert({
123
+ _OSAlert({
124
124
  title,
125
125
  body,
126
126
  options: [
@@ -151,7 +151,7 @@ function OSError(args: OSAlertArgs & NamedEvents<'onDismiss'>) {
151
151
  if (!body) {
152
152
  body = 'Something went wrong'
153
153
  }
154
- OSAlert({
154
+ _OSAlert({
155
155
  title,
156
156
  body,
157
157
  options: [
@@ -166,13 +166,13 @@ function OSError(args: OSAlertArgs & NamedEvents<'onDismiss'>) {
166
166
  })
167
167
  }
168
168
 
169
- function OSAlert(params: OSAlertArgs) {
169
+ function _OSAlert(params: OSAlertArgs) {
170
170
  Alert.alert(params.title, params.body, params.options, {
171
171
  cancelable: false,
172
172
  })
173
173
  }
174
174
 
175
- export default {
175
+ export const OSAlert = {
176
176
  ask,
177
177
  warn,
178
178
  info,
@@ -1,5 +1,5 @@
1
- import { onMount, onUpdate, usePrevious, useRef, useState } from '@codeleap/common'
2
- import { Animated, AppState, AppStateStatus } from 'react-native'
1
+ import { onMount, onUpdate, shadeColor, TypeGuards, usePrevious, useRef, useState } from '@codeleap/common'
2
+ import { Animated, AppState, AppStateStatus, Platform, PressableAndroidRippleConfig } from 'react-native'
3
3
 
4
4
  export function useAnimateColor(value: string, opts?: Partial<Animated.TimingAnimationConfig>) {
5
5
  const iters = useRef(0)
@@ -63,3 +63,83 @@ export function useStaticAnimationStyles<T extends Record<string|number|symbol,
63
63
  [P in K] : T[K]
64
64
  }
65
65
  }
66
+
67
+ export type FeedbackConfig =
68
+ | { type: 'opacity'; value?: number }
69
+ | {type: 'highlight'; color?: string; brightness?: number; shiftOpacity?: number}
70
+ | {type: 'none'}
71
+
72
+ type RippleConfig = {
73
+ type: 'ripple'
74
+ config?: PressableAndroidRippleConfig
75
+ iosFallback?: FeedbackConfig
76
+ }
77
+ export type TouchableFeedbackConfig = RippleConfig | FeedbackConfig
78
+
79
+ export type UsePressableFeedbackConfig = {
80
+ disabled?: boolean
81
+ feedbackConfig?: TouchableFeedbackConfig
82
+ hightlightPropertyIn: 'backgroundColor' | 'borderColor' | 'color'
83
+ hightlightPropertyOut: 'backgroundColor' | 'borderColor' | 'color'
84
+ }
85
+
86
+ export function usePressableFeedback(styles: any, config:UsePressableFeedbackConfig) {
87
+ const {
88
+ disabled,
89
+ feedbackConfig,
90
+ hightlightPropertyIn = 'backgroundColor',
91
+ hightlightPropertyOut = 'backgroundColor',
92
+ } = config
93
+ const _feedbackConfig = {
94
+ ...feedbackConfig,
95
+ }
96
+ const disableFeedback = disabled
97
+
98
+ const rippleEnabled = _feedbackConfig?.type === 'ripple' && !disableFeedback
99
+ const rippleConfig = rippleEnabled ? _feedbackConfig?.config : null
100
+
101
+ function getFeedbackStyle(pressed:boolean) {
102
+ if (disableFeedback) return {}
103
+ let feedbackConfig = { ..._feedbackConfig }
104
+
105
+ if (rippleEnabled && feedbackConfig.type === 'ripple' && Platform.OS === 'ios' && !!_feedbackConfig?.iosFallback) {
106
+ feedbackConfig = feedbackConfig?.iosFallback
107
+ }
108
+ switch (feedbackConfig.type) {
109
+ case 'highlight':
110
+ if (!pressed && hightlightPropertyIn !== hightlightPropertyOut) return {}
111
+ let highlightColorDefault = styles?.[hightlightPropertyIn] || '#0000'
112
+ if (pressed) {
113
+ if (feedbackConfig?.color) {
114
+ highlightColorDefault = feedbackConfig?.color
115
+ } else {
116
+ let opacity = feedbackConfig?.shiftOpacity
117
+ let brightness = feedbackConfig?.brightness
118
+ if (!TypeGuards.isNumber(opacity)) {
119
+ opacity = 1
120
+ }
121
+ if (!TypeGuards.isNumber(brightness)) {
122
+ brightness = 0
123
+ }
124
+ highlightColorDefault = shadeColor(highlightColorDefault, brightness * 100, opacity)
125
+ }
126
+ }
127
+ return {
128
+ [hightlightPropertyOut]: highlightColorDefault,
129
+ }
130
+ break
131
+ case 'opacity':
132
+ return {
133
+ opacity: pressed ? feedbackConfig?.value : 1,
134
+ }
135
+
136
+ case 'none':
137
+ return {}
138
+ }
139
+ }
140
+
141
+ return {
142
+ getFeedbackStyle,
143
+ rippleConfig,
144
+ }
145
+ }
@@ -1,4 +1,4 @@
1
- export { default as OSAlert } from './OSAlert'
1
+ export * from './OSAlert'
2
2
  export * from './hooks'
3
3
  export * from './misc'
4
4
  export * from './notifications'
@@ -6,4 +6,4 @@ export * from './ModalManager'
6
6
  import * as Permissions from './PermissionManager'
7
7
 
8
8
  export { Permissions }
9
- export * from './KeyboardAware'
9
+ export * from './KeyboardAware'
@@ -114,7 +114,7 @@ export class NotificationManager {
114
114
  set initialized(to:boolean) {
115
115
 
116
116
  if (to) {
117
- this.logger.log('Initialized', '', MODULE)
117
+ this.logger.info('Initialized', '', MODULE)
118
118
  this.unsubscribeFromMessage = messaging().onMessage((msg) => {
119
119
  this.handleNotification({
120
120
  data: msg,
@@ -130,7 +130,7 @@ export class NotificationManager {
130
130
  })
131
131
 
132
132
  this.unsubscribeFromPress = messaging().onNotificationOpenedApp(msg => {
133
- this.logger.log('Notification press', msg, MODULE)
133
+ this.logger.info('Notification press', msg, MODULE)
134
134
  this.handleNotification({
135
135
  data: msg,
136
136
  type: 'press',
@@ -140,7 +140,7 @@ export class NotificationManager {
140
140
  if (!this._initialNoficationHandled && this.autoHandleInitialNotification) {
141
141
  this.getInitialNotification().then(msg => {
142
142
  if (!msg.data) return
143
- this.logger.log('Notification initial', msg, MODULE)
143
+ this.logger.info('Notification initial', msg, MODULE)
144
144
  this.handleNotification(msg).then(() => {
145
145
  this._initialNoficationHandled = true
146
146
  }).catch(e => {
@@ -156,7 +156,7 @@ export class NotificationManager {
156
156
 
157
157
  this.unsubscribeFromPress = null
158
158
 
159
- this.logger.log('Deinitialized', '', MODULE)
159
+ this.logger.info('Deinitialized', '', MODULE)
160
160
  }
161
161
  this._initialized = to
162
162