ordering-ui-react-native 0.14.4 → 0.14.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.14.4",
3
+ "version": "0.14.5",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,5 +1,5 @@
1
- import React, { useState, useRef, useCallback } from 'react'
2
- import { View, TouchableOpacity, StyleSheet, TextStyle, ScrollView, I18nManager, Platform } from 'react-native'
1
+ import React, { useState, useRef, useCallback, useEffect } from 'react'
2
+ import { View, TouchableOpacity, StyleSheet, TextStyle, ScrollView, I18nManager, Platform, KeyboardAvoidingView, Keyboard } from 'react-native'
3
3
  import {
4
4
  BusinessAndProductList,
5
5
  useLanguage,
@@ -36,7 +36,7 @@ import { Cart } from '../Cart'
36
36
  import { OrderSummary } from '../OrderSummary'
37
37
  import NavBar from '../NavBar'
38
38
  import SocialShareFav from '../SocialShare'
39
-
39
+ import { SafeAreaContainer } from '../../layouts/SafeAreaContainer'
40
40
  const PIXELS_TO_SCROLL = 1000
41
41
 
42
42
  const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
@@ -112,6 +112,8 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
112
112
  const [categoriesLayout, setCategoriesLayout] = useState<any>({})
113
113
  const [productListLayout, setProductListLayout] = useState<any>(null)
114
114
  const [selectedCategoryId, setSelectedCategoryId] = useState<any>('cat_all')
115
+ const [isKeyboardOpen, setIsKeyBoardOpen] = useState(false)
116
+ const cartRef = useRef<any>()
115
117
 
116
118
  const scrollViewRef = useRef<any>(null)
117
119
 
@@ -187,6 +189,21 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
187
189
  setCategoryClicked(false);
188
190
  }, []);
189
191
 
192
+ useEffect(() => {
193
+ Keyboard.addListener('keyboardDidShow', () => {
194
+ setIsKeyBoardOpen(true)
195
+ })
196
+
197
+ Keyboard.addListener('keyboardDidHide', () => [
198
+ setIsKeyBoardOpen(false)
199
+ ])
200
+
201
+ return () => {
202
+ Keyboard.removeAllListeners('keyboardDidShow')
203
+ Keyboard.removeAllListeners('keyboardDidHide')
204
+ }
205
+ }, [])
206
+
190
207
  return (
191
208
  <>
192
209
  <Animated.View style={{ flex: 1, backgroundColor: theme.colors.white, position: 'absolute', width: '100%', top: top, zIndex: 1 }}>
@@ -358,18 +375,36 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
358
375
  entireModal
359
376
  customClose
360
377
  >
361
- <ScrollView stickyHeaderIndices={[0]} style={{ backgroundColor: 'white' }} contentContainerStyle={{ paddingBottom: 100 }}>
362
- <NavBar title={t('CART', 'Cart')} onActionLeft={handleCloseCartModal} leftImg={theme.images.general.close} noBorder btnStyle={{ paddingLeft: 0 }} />
363
- <OrderSummary
364
- cart={currentCart}
365
- isCartPending={currentCart?.status === 2}
366
- hasUpSelling={true}
367
- isFromCheckout
368
- title={t('ITEMS', 'Items')}
369
- paddingH={40}
370
- />
371
- </ScrollView>
372
- <FloatingButton btnText={t('CHECKOUT', 'Checkout')} handleClick={() => handleUpsellingPage()} />
378
+ <SafeAreaContainer>
379
+ <KeyboardAvoidingView
380
+ style={{ flex: 1 }}
381
+ behavior={Platform.OS === 'ios' ? 'height' : 'padding'}
382
+ enabled={Platform.OS === 'ios'}
383
+ >
384
+ <ScrollView
385
+ stickyHeaderIndices={[0]}
386
+ style={{ backgroundColor: 'white' }}
387
+ contentContainerStyle={{ paddingBottom: 100 }}
388
+ ref={(ref : any) => cartRef.current = ref}
389
+ >
390
+ <NavBar title={t('CART', 'Cart')} onActionLeft={handleCloseCartModal} leftImg={theme.images.general.close} noBorder btnStyle={{ paddingLeft: 0 }} />
391
+ <OrderSummary
392
+ cart={currentCart}
393
+ isCartPending={currentCart?.status === 2}
394
+ hasUpSelling={true}
395
+ isFromCheckout
396
+ title={t('ITEMS', 'Items')}
397
+ paddingH={40}
398
+ cartRef={cartRef}
399
+ />
400
+ </ScrollView>
401
+ <FloatingButton
402
+ style={{bottom: isKeyboardOpen && Platform.OS === 'ios' ? 30 : 0}}
403
+ btnText={t('CHECKOUT', 'Checkout')}
404
+ handleClick={() => handleUpsellingPage()}
405
+ />
406
+ </KeyboardAvoidingView>
407
+ </SafeAreaContainer>
373
408
  </OModal>
374
409
  </>
375
410
  )
@@ -19,7 +19,8 @@ const FloatingButtonUI = (props: FloatingButtonParams) => {
19
19
  btnText,
20
20
  handleButtonClick,
21
21
  disabled,
22
- isSecondaryBtn
22
+ isSecondaryBtn,
23
+ style
23
24
  } = props
24
25
 
25
26
  const theme = useTheme();
@@ -39,7 +40,7 @@ const FloatingButtonUI = (props: FloatingButtonParams) => {
39
40
  const { bottom } = useSafeAreaInsets();
40
41
 
41
42
  return (
42
- <Container isIos={Platform.OS === 'ios'} style={{ paddingBottom: bottom + 10 }}>
43
+ <Container isIos={Platform.OS === 'ios'} style={{ ...style, paddingBottom: bottom + 10 }}>
43
44
  <Button
44
45
  style={[isSecondaryBtn ? styles.secodaryBtn : styles.primaryBtn]}
45
46
  onPress={handleButtonClick}
@@ -272,7 +272,8 @@ const MessagesUI = (props: MessagesParams) => {
272
272
  {...props}
273
273
  containerStyle={{
274
274
  padding: Platform.OS === 'ios' && isKeyboardShow ? 0 : 10,
275
- flexDirection: 'column-reverse'
275
+ flexDirection: 'column-reverse',
276
+ marginBottom: Platform.OS === 'ios' && isKeyboardShow ? 500 : 0
276
277
  }}
277
278
  primaryStyle={{ alignItems: 'center', justifyContent: 'flex-start' }}
278
279
  renderAccessory={() => renderAccessory()}
@@ -41,7 +41,8 @@ const OrderSummaryUI = (props: any) => {
41
41
  paddingH,
42
42
  isMini,
43
43
  commentState,
44
- handleChangeComment
44
+ handleChangeComment,
45
+ cartRef
45
46
  } = props;
46
47
 
47
48
  const theme = useTheme();
@@ -256,6 +257,7 @@ const OrderSummaryUI = (props: any) => {
256
257
  }}
257
258
  multiline
258
259
  inputStyle={{color: theme.colors.textPrimary}}
260
+ onFocus={() => cartRef?.current?.scrollToEnd?.()}
259
261
  />
260
262
  {commentState?.loading && (
261
263
  <View style={{ position: 'absolute', right: 20 }}>
@@ -1,4 +1,4 @@
1
- import React from 'react'
1
+ import React, { useState, useRef, useEffect } from 'react'
2
2
  import {
3
3
  ProductForm as ProductOptions,
4
4
  useSession,
@@ -8,7 +8,7 @@ import {
8
8
  } from 'ordering-components/native'
9
9
  import { ProductIngredient } from '../ProductIngredient'
10
10
  import { ProductOption } from '../ProductOption'
11
- import { View, TouchableOpacity, StyleSheet, Dimensions, ScrollView, I18nManager, TextStyle, Platform, KeyboardAvoidingView } from 'react-native'
11
+ import { View, TouchableOpacity, StyleSheet, Dimensions, ScrollView, I18nManager, TextStyle, Platform, KeyboardAvoidingView, Keyboard } from 'react-native'
12
12
  import {
13
13
  ProductHeader,
14
14
  WrapHeader,
@@ -107,9 +107,9 @@ export const ProductOptionsUI = (props: any) => {
107
107
  const [orderState] = useOrder()
108
108
  const [{ auth }] = useSession()
109
109
  const { product, loading, error } = productObject
110
-
111
110
  const { bottom } = useSafeAreaInsets();
112
-
111
+ const [commentY, setCommentY] = useState(0)
112
+ const productFormRef = useRef<any>()
113
113
  const isError = (id: number) => {
114
114
  let bgColor = theme.colors.white
115
115
  if (errors[`id:${id}`]) {
@@ -136,13 +136,25 @@ export const ProductOptionsUI = (props: any) => {
136
136
 
137
137
  const saveErrors = orderState.loading || maxProductQuantity === 0 || Object.keys(errors).length > 0
138
138
 
139
+ useEffect(() => {
140
+ Keyboard.addListener('keyboardDidShow', () => {
141
+ if (commentY > 100) {
142
+ productFormRef?.current?.scrollTo?.({ x: 0, y: commentY + 300, animated: true })
143
+ }
144
+ })
145
+
146
+ return () => {
147
+ Keyboard.removeAllListeners('keyboardDidShow')
148
+ }
149
+ }, [productFormRef?.current, commentY])
150
+
139
151
  return (
140
152
  <KeyboardAvoidingView
141
153
  style={{ flex: 1 }}
142
154
  behavior={Platform.OS ? 'padding' : 'height'}
143
155
  enabled={Platform.OS === 'ios'}
144
156
  >
145
- <ScrollView style={styles.mainContainer}>
157
+ <ScrollView style={styles.mainContainer} ref={(ref) => productFormRef.current = ref}>
146
158
  {!error && (
147
159
  <View style={{ paddingBottom: 80 }}>
148
160
  <WrapHeader>
@@ -275,7 +287,7 @@ export const ProductOptionsUI = (props: any) => {
275
287
  </React.Fragment>
276
288
  )
277
289
  }))}
278
- <ProductComment>
290
+ <ProductComment onLayout={(e: any) => setCommentY(e.nativeEvent.layout.y + e.nativeEvent.layout.height)}>
279
291
  <SectionTitle>
280
292
  <OText style={theme.labels.middle as TextStyle}>{t('SPECIAL_COMMENT', 'Special comment')}</OText>
281
293
  </SectionTitle>
@@ -99,6 +99,7 @@ const OInput = (props: Props): React.ReactElement => {
99
99
  returnKeyType={props.returnKeyType}
100
100
  onSubmitEditing={props.onSubmitEditing}
101
101
  blurOnSubmit={props.blurOnSubmit}
102
+ onFocus={props.onFocus}
102
103
  ref={props.forwardRef}
103
104
  style={{padding: 0, ...props.inputStyle}}
104
105
  />
@@ -365,6 +365,7 @@ export interface FloatingButtonParams {
365
365
  btnLeftValueShow?: boolean;
366
366
  btnRightValueShow?: boolean;
367
367
  handleClick?: any;
368
+ style?: ViewStyle
368
369
  }
369
370
  export interface MomentOptionParams {
370
371
  navigation: any;