Răsfoiți Sursa

Fixed payment method issues

vbea 1 an în urmă
părinte
comite
ade209c2e8

+ 135 - 0
Strides-APP/app/components/VbeSkeleton.js

@@ -0,0 +1,135 @@
+import React, { memo, useMemo } from 'react';
+import { StyleSheet, View } from 'react-native';
+import Animated, {
+  useSharedValue,
+  withRepeat,
+  withTiming,
+  useAnimatedReaction,
+  useDerivedValue,
+  useAnimatedStyle,
+  Easing,
+} from 'react-native-reanimated';
+import { useLayout, useGetBones } from 'react-native-reanimated-skeleton/lib/hooks';
+import TextView from './TextView';
+
+export const ANIMATION_TYPE = {
+  NONE: "none",
+  SHIVER: "shiver",
+  PULSE: "pulse"
+}
+
+export const ANIMATION_DIRECTION = {
+  HORIZONTAL_LEFT: "horizontalLeft",
+  HORIZONTAL_RIGHT: "horizontalRight",
+  VERTICAL_TOP: "verticalTop",
+  VERTICAL_DOWN: "verticalDown",
+  DIAGONAL_DOWN_LEFT: "diagonalDownLeft",
+  DIAGONAL_DOWN_RIGHT: "diagonalDownRight",
+  DIAGONAL_TOP_LEFT: "diagonalTopLeft",
+  DIAGONAL_TOP_RIGHT: "diagonalTopRight"
+}
+
+const VbeSkeleton = ({
+  style=styles.container,
+  viewStyle=styles.viewStyle,
+  textStyle={},
+  text,
+  duration=1200,
+  layout=[],
+  numberOfLines,
+  animationType=ANIMATION_TYPE.SHIVER,
+  animationDirection=ANIMATION_DIRECTION.HORIZONTAL_LEFT,
+  easing=Easing.bezier(0.5, 0, 0.25, 1),
+  isLoading=true,
+  boneColor='#eeeeee',
+  highlightColor='#f6f6f6',
+  hasFadeIn=false,
+  children
+}) => {
+  const animationValue = useSharedValue(0);
+  const loadingValue = useSharedValue(0);
+  const shiverValue = useSharedValue(animationType === 'shiver' ? 1 : 0);
+  const [componentSize, onLayout] = useLayout();
+  const generalStyles = useMemo(
+    () => ({
+      animationDirection,
+      animationType,
+      boneColor,
+      animationValue,
+      highlightColor,
+    }),
+    [
+      animationDirection,
+      animationType,
+      animationValue,
+      boneColor,
+      highlightColor,
+    ],
+  );
+
+  const getBones = useGetBones(componentSize);
+
+  useAnimatedReaction(
+    () => ({ isLoading, loadingValue }),
+    () => {
+      if (isLoading && loadingValue.value !== 1) {
+        /* NOTE: Reset behaviour to ensure animation always starts from the beginning */
+        animationValue.value = 0;
+
+        animationValue.value =
+          shiverValue.value === 1
+            ? withRepeat(withTiming(1, { duration, easing }), -1, false)
+            : withRepeat(
+                withTiming(1, { duration: duration / 2, easing }),
+                -1,
+                true,
+              );
+      }
+    },
+    [isLoading, shiverValue],
+  );
+
+  const opacity = useDerivedValue(() => {
+    if (!isLoading) {
+      return withTiming(1, { duration: 250 });
+    }
+
+    return 0;
+  });
+
+  const animatedStyle = useAnimatedStyle(() => ({
+    opacity: opacity.value,
+  }));
+
+  return (
+    <View style={style} onLayout={onLayout}>
+      {isLoading ? (
+        getBones({
+          bonesLayout: layout,
+          children,
+          generalStyles,
+        })
+      ) : (
+        <Animated.View style={[viewStyle, hasFadeIn ? animatedStyle : {}]}>
+          { text
+          ? <TextView style={textStyle} numberOfLines={numberOfLines}>{text}</TextView>
+          : children
+          }
+        </Animated.View>
+      )}
+    </View>
+  );
+};
+
+export default VbeSkeleton;
+
+const styles = StyleSheet.create({
+  container: {
+    flex: 1,
+    alignItems: 'center',
+    justifyContent: 'center'
+  },
+  viewStyle: {
+    alignItems: 'center'
+  }
+});

+ 9 - 6
Strides-APP/app/pages/chargeV2/PaymentListV2.js

@@ -15,6 +15,7 @@ import Button from '../../components/Button';
 import Dialog from '../../components/Dialog';
 import app from '../../../app.json';
 import utils from '../../utils/utils';
+import VbeSkeleton from '../../components/VbeSkeleton';
 
 export default class PaymentListV2 extends Component {
   constructor(props) {
@@ -143,8 +144,9 @@ export default class PaymentListV2 extends Component {
             <TextView style={styles.numberDot}>{this.state.options.length}</TextView>
           }
           <View style={styles.paymentView}>
-            <Skeleton
-              containerStyle={ui.flex1}
+            <VbeSkeleton
+              style={ui.flex1}
+              viewStyle={ui.flexc}
               isLoading={this.state.isloading}
               animationType="pulse"
               layout={[{width: '60%', height: 20, marginLeft: 10}]}
@@ -152,9 +154,10 @@ export default class PaymentListV2 extends Component {
               <TextView
                 style={styles.valueText}
                 numberOfLines={1}>{this.state.selectOptions?.name}</TextView>
-            </Skeleton>
-            <Skeleton
-              containerStyle={ui.flex1}
+            </VbeSkeleton>
+            <VbeSkeleton
+              style={ui.flex1}
+              viewStyle={ui.flexc}
               isLoading={this.state.isloading}
               animationType="pulse"
               layout={[{width: '60%', height: 20, marginLeft: 20}]}
@@ -162,7 +165,7 @@ export default class PaymentListV2 extends Component {
               <TextView
                 style={styles.paymentText}
                 numberOfLines={1}>{this.state.selectOptions?.desc}</TextView>
-            </Skeleton>
+            </VbeSkeleton>
           </View>
           { this.state.selectOptions?.def &&
             <TextView style={styles.textDefault}>Default</TextView>

+ 4 - 2
Strides-APP/app/pages/chargingV2/StepCharging.js

@@ -170,7 +170,8 @@ const StepCharging = ({
           { app.charge.paymentMethod
           ? <PaymentListV2
               isSelect={false}
-              payType={currentPayment}/>
+              payType={currentPayment}
+              chargeBoxId={connectorInfo.chargeBoxId}/>
           : <PaymentList
               isSelect={false}
               payType={currentPayment}/>
@@ -225,7 +226,8 @@ const StepCharging = ({
         { app.charge.paymentMethod
         ? <PaymentListV2
             isSelect={false}
-            payType={currentPayment}/>
+            payType={currentPayment}
+            chargeBoxId={connectorInfo.chargeBoxId}/>
         : <PaymentList
             isSelect={false}
             payType={currentPayment}/>

+ 1 - 0
Strides-APP/app/pages/chargingV3/StepCharging.js

@@ -74,6 +74,7 @@ const StepCharging = ({
               isSelect={false}
               payType={currentPayment}
               borderColor={textCancel}
+              chargeBoxId={connectorInfo.chargeBoxId}
               style={styles.paymentView}/>
           : <PaymentList
               isSelect={false}