ordering-ui-react-native 0.16.48 → 0.16.49

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.
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import {
3
3
  useLanguage,
4
4
  useConfig,
@@ -10,6 +10,8 @@ import { useTheme } from 'styled-components/native';
10
10
  import { SingleProductCardParams } from '../../types';
11
11
  import { CardContainer, CardInfo, SoldOut, QuantityContainer, PricesContainer, RibbonBox, LogoWrapper } from './styles';
12
12
  import { StyleSheet, View, TouchableOpacity, Image } from 'react-native';
13
+ import { InView } from 'react-native-intersection-observer'
14
+ import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
13
15
  import { OText } from '../shared';
14
16
  import FastImage from 'react-native-fast-image'
15
17
  import IconAntDesign from 'react-native-vector-icons/AntDesign'
@@ -87,7 +89,7 @@ const SinguleProductCardUI = React.memo((props: SingleProductCardParams) => {
87
89
  const [stateConfig] = useConfig();
88
90
  const [{ parsePrice, optimizeImage }] = useUtils();
89
91
  const [orderState] = useOrder();
90
-
92
+ const [isIntersectionObserver, setIsIntersectionObserver] = useState(false)
91
93
  const editMode = typeof product?.code !== 'undefined';
92
94
 
93
95
  const removeToBalance = editMode ? product?.quantity : 0;
@@ -117,103 +119,110 @@ const SinguleProductCardUI = React.memo((props: SingleProductCardParams) => {
117
119
  }
118
120
 
119
121
  return (
120
- <CardContainer
121
- style={[
122
- styles.container,
123
- (isSoldOut || maxProductQuantity <= 0) && styles.soldOutBackgroundStyle,
124
- (style && { ...style }),
125
- ]}
126
- onPress={() => onProductClick?.(product)}>
127
- {productAddedToCartLength > 0 && (
128
- <QuantityContainer style={[styles.quantityContainer, {
129
- transform: [{ translateX: 10 }, { translateY: -10 }],
130
- }]}>
131
- <OText size={12} color={theme.colors.white}>{productAddedToCartLength.toString()}</OText>
132
- </QuantityContainer>
133
- )}
134
- <CardInfo>
135
- <View style={styles.titleWrapper}>
136
- <OText
137
- size={12}
138
- weight={'500'}
139
- numberOfLines={1}
140
- ellipsizeMode="tail"
141
- style={styles.line18}>
142
- {product?.name}
143
- </OText>
144
- <TouchableOpacity
145
- onPress={handleChangeFavorite}
146
- >
147
- <IconAntDesign
148
- name={product?.favorite ? 'heart' : 'hearto'}
149
- color={theme.colors.danger5}
150
- size={18}
151
- />
152
- </TouchableOpacity>
153
- </View>
154
- <PricesContainer>
155
- <OText color={theme.colors.primary}>{product?.price ? parsePrice(product?.price) : ''}</OText>
156
- {product?.offer_price !== null && product?.in_offer && (
157
- <OText style={styles.regularPriceStyle}>{product?.offer_price ? parsePrice(product?.offer_price) : ''}</OText>
122
+ <InView style={{ minHeight: 140 }} triggerOnce={true} onChange={(inView: boolean) => setIsIntersectionObserver(true)}>
123
+ {isIntersectionObserver && (
124
+ <CardContainer
125
+ style={[
126
+ styles.container,
127
+ (isSoldOut || maxProductQuantity <= 0) && styles.soldOutBackgroundStyle,
128
+ (style && { ...style }),
129
+ ]}
130
+ onPress={() => onProductClick?.(product)}>
131
+ {productAddedToCartLength > 0 && (
132
+ <QuantityContainer style={[styles.quantityContainer, {
133
+ transform: [{ translateX: 10 }, { translateY: -10 }],
134
+ }]}>
135
+ <OText size={12} color={theme.colors.white}>{productAddedToCartLength.toString()}</OText>
136
+ </QuantityContainer>
158
137
  )}
159
- </PricesContainer>
160
- <OText
161
- size={10}
162
- numberOfLines={2}
163
- ellipsizeMode="tail"
164
- color={theme.colors.textSecondary}
165
- style={styles.line15}>
166
- {product?.description}
167
- </OText>
168
- </CardInfo>
169
- <LogoWrapper>
170
- {product?.ribbon?.enabled && (
171
- <RibbonBox
172
- bgColor={product?.ribbon?.color}
173
- isRoundRect={product?.ribbon?.shape === shape?.rectangleRound}
174
- isCapsule={product?.ribbon?.shape === shape?.capsuleShape}
175
- >
138
+ <CardInfo>
139
+ <View style={styles.titleWrapper}>
140
+ <OText
141
+ size={12}
142
+ weight={'500'}
143
+ numberOfLines={1}
144
+ ellipsizeMode="tail"
145
+ style={styles.line18}>
146
+ {product?.name}
147
+ </OText>
148
+ <TouchableOpacity
149
+ onPress={handleChangeFavorite}
150
+ >
151
+ <IconAntDesign
152
+ name={product?.favorite ? 'heart' : 'hearto'}
153
+ color={theme.colors.danger5}
154
+ size={18}
155
+ />
156
+ </TouchableOpacity>
157
+ </View>
158
+ <PricesContainer>
159
+ <OText color={theme.colors.primary}>{product?.price ? parsePrice(product?.price) : ''}</OText>
160
+ {product?.offer_price !== null && product?.in_offer && (
161
+ <OText style={styles.regularPriceStyle}>{product?.offer_price ? parsePrice(product?.offer_price) : ''}</OText>
162
+ )}
163
+ </PricesContainer>
176
164
  <OText
177
165
  size={10}
178
- weight={'400'}
179
- color={theme.colors.white}
180
166
  numberOfLines={2}
181
- ellipsizeMode='tail'
182
- lineHeight={13}
183
- >
184
- {product?.ribbon?.text}
167
+ ellipsizeMode="tail"
168
+ color={theme.colors.textSecondary}
169
+ style={styles.line15}>
170
+ {product?.description}
185
171
  </OText>
186
- </RibbonBox>
187
- )}
188
- {product?.images ? (
189
- <FastImage
190
- style={styles.productStyle}
191
- source={{
192
- uri: optimizeImage(product?.images, 'h_250,c_limit'),
193
- priority: FastImage.priority.normal,
194
- }}
195
- resizeMode={FastImage.resizeMode.cover}
196
- />
197
- ) : (
198
- <FastImage
199
- style={styles.productStyle}
200
- source={{
201
- uri: Image.resolveAssetSource(theme.images.dummies.product).uri,
202
- priority: FastImage.priority.normal,
203
- }}
204
- resizeMode={FastImage.resizeMode.cover}
205
- />
206
- )}
207
- </LogoWrapper>
208
-
209
- {(isSoldOut || maxProductQuantity <= 0) && (
210
- <SoldOut>
211
- <OText size={12} weight="bold" color={theme.colors.textSecondary} style={styles.soldOutTextStyle}>
212
- {t('SOLD_OUT', 'SOLD OUT')}
213
- </OText>
214
- </SoldOut>
172
+ </CardInfo>
173
+ <LogoWrapper>
174
+ {product?.ribbon?.enabled && (
175
+ <RibbonBox
176
+ bgColor={product?.ribbon?.color}
177
+ isRoundRect={product?.ribbon?.shape === shape?.rectangleRound}
178
+ isCapsule={product?.ribbon?.shape === shape?.capsuleShape}
179
+ >
180
+ <OText
181
+ size={10}
182
+ weight={'400'}
183
+ color={theme.colors.white}
184
+ numberOfLines={2}
185
+ ellipsizeMode='tail'
186
+ lineHeight={13}
187
+ >
188
+ {product?.ribbon?.text}
189
+ </OText>
190
+ </RibbonBox>
191
+ )}
192
+ {product?.images ? (
193
+ <>
194
+ {isIntersectionObserver && (
195
+ <FastImage
196
+ style={styles.productStyle}
197
+ source={{
198
+ uri: optimizeImage(product?.images, 'h_250,c_limit'),
199
+ priority: FastImage.priority.normal,
200
+ }}
201
+ resizeMode={FastImage.resizeMode.cover}
202
+ />
203
+ )}
204
+ </>
205
+ ) : (
206
+ <FastImage
207
+ style={styles.productStyle}
208
+ source={{
209
+ uri: Image.resolveAssetSource(theme.images.dummies.product).uri,
210
+ priority: FastImage.priority.normal,
211
+ }}
212
+ resizeMode={FastImage.resizeMode.cover}
213
+ />
214
+ )}
215
+ </LogoWrapper>
216
+ {(isSoldOut || maxProductQuantity <= 0) && (
217
+ <SoldOut>
218
+ <OText size={12} weight="bold" color={theme.colors.textSecondary} style={styles.soldOutTextStyle}>
219
+ {t('SOLD_OUT', 'SOLD OUT')}
220
+ </OText>
221
+ </SoldOut>
222
+ )}
223
+ </CardContainer>
215
224
  )}
216
- </CardContainer>
225
+ </InView >
217
226
  );
218
227
  }, SingleProductCardPropsAreEqual);
219
228