ios – Obtain progress not work on bodily iPhone in Expo

0
2
ios – Obtain progress not work on bodily iPhone in Expo


It really works accurately within the simulator en ios however when i generated the .IPA the state shouldn’t be working. Im working with zustand and axios

// Retailer
import { create } from 'zustand';

interface Props {
  isDownloadProcessing: boolean;
  downloadProgress: quantity;

  setIsDownloadProcessing: (worth: boolean) => void;
  setDownloadProgress: (worth: quantity) => void;
}

export const useGlobalDownloadProgressStore = create()((set, get) => ({
  isDownloadProcessing: false,
  downloadProgress: 0,

  setIsDownloadProcessing: (worth: boolean) => {
    console.log('[Zustand] setIsDownloadProcessing:', worth);
    set({ isDownloadProcessing: worth });
  },

  setDownloadProgress: (worth: quantity) => {
    const isProcessing = get().isDownloadProcessing;
    console.log('[Zustand] setDownloadProgress:', worth, 'isProcessing:', isProcessing);
    set({ downloadProgress: isProcessing ? worth : 0 });
  },
}));


// Componentes React / React Native
import { useEffect, useRef } from 'react';
import { Platform } from 'react-native';
// Librerías de terceros
import * as FileSystem from 'expo-file-system';
import * as MediaLibrary from 'expo-media-library';
import * as Sharing from 'expo-sharing';
import { AxiosError } from 'axios';
// Comunicación con endpoints
import { downloadDocumentUrlByHashName } from '@/core/actions/doc/obtain.doc.url.by.hash.identify';
// Configuraciones e Interfaces (Declarada como tipos)
import { IDocumentDTO } from '@/core/infrastructure/interfaces/doc.dto';
// Hooks y utilidades
import { useGlobalDownloadProgressStore } from '@retailer/paperwork/obtain.international.progress.retailer';
import { useAuthStore } from '@retailer/useAuthStore';
import { useGlobalAlertStore } from '@retailer/globalAlertStore';
// Property
// Atoms
// Molecules
// Organisms
// Layouts
// Containers
// Screens

const URL = course of.env.EXPO_PUBLIC_DOCUMENT_TRANSFER_URL

/**
 * Customized hook para la descarga de documentos.
 */
export const useDownloadDocument = () => {
  const setDownloadProgress = useGlobalDownloadProgressStore((state) => state.setDownloadProgress);

  const setIsDownloadProcessing = useGlobalDownloadProgressStore((state) => state.setIsDownloadProcessing);
  const showGlobalAlert = useGlobalAlertStore((state) => state.showGlobalAlert);
  const userData = useAuthStore((state) => state.userData);

  const prevUserIdRef = useRef(userData?.id ?? null);

  useEffect(() => {
    const currentUserId = userData?.id ?? null;

    if (prevUserIdRef.present !== null && prevUserIdRef.present !== currentUserId) {
      const controller = useAuthStore.getState().downloadAbortController;
      if (controller) {
        controller.abort();
        useAuthStore.getState().setDownloadAbortController(null);
        console.log('Descarga cancelada por cambio de usuario');
      }
    }

    prevUserIdRef.present = currentUserId;
  }, [userData]);


  const handleFileDownload = async (doc: IDocumentDTO, userId: quantity, setProgress?: (progress: quantity) => void) => {
    setIsDownloadProcessing(true);

    const DownloadController = new AbortController();
    const { sign } = DownloadController;
    useAuthStore.getState().setDownloadAbortController(DownloadController);

    const title = doc.title + '.' + doc.sort;

    strive {
      await downloadDocumentUrlByHashName(
        doc.hash,
        userId,
        (progress: quantity) => {
          setDownloadProgress(progress); 
          if (setProgress) {
            console.log('Progress:', progress);
            setProgress(progress);
          }
        },
        sign
      );

      if (sign.aborted) {
        setIsDownloadProcessing(false);
        return;
      }

      const fileUrl = `${URL}/obtain/${doc.hash}?userId=${userData?.id ?? 0}`;
      const fileUri = `${FileSystem.documentDirectory}${title}`;
      const { uri } = await FileSystem.downloadAsync(fileUrl, fileUri);

      handleFileValidation(fileUrl, uri, title, doc);
    } catch (error: unknown) {
      if (error instanceof AxiosError) {
        handleAxiosError(error);
      } else {
        console.error('Error no identificado en la descarga:', error);
        showGlobalAlert('Error al descargar el documento', 'error');
      }
    } lastly {
      setIsDownloadProcessing(false);
      useAuthStore.getState().setDownloadAbortController(null);
    }
  };

  const handleFileValidation = async (fileUrl: string, uri: string, title: string, doc: IDocumentDTO) => {
    if (fileUrl.size > 0 && userData) {
      if (Platform.OS === 'ios') {
        await handleIOSFileSharing(uri);
      } else if (Platform.OS === 'android') {
        await handleAndroidFileSaving(uri, title, doc);
      }
    }
  };

  const handleIOSFileSharing = async (uri: string) => {
    if (await Sharing.isAvailableAsync()) {
      await Sharing.shareAsync(uri);
    } else {
      console.error('Error', 'Sharing shouldn't be accessible on this machine.');
    }
  };

  const handleAndroidFileSaving = async (uri: string, title: string, doc: IDocumentDTO) => {
    const { standing } = await MediaLibrary.requestPermissionsAsync();
    if (standing !== 'granted') {
      return;
    }
    const permissions = await FileSystem.StorageAccessFramework.requestDirectoryPermissionsAsync();

    if (permissions.granted) {
      const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 });

      await FileSystem.StorageAccessFramework.createFileAsync(permissions.directoryUri, title, doc.sort)
        .then(async (uri) => {
          await FileSystem.writeAsStringAsync(uri, base64, { encoding: FileSystem.EncodingType.Base64 });
        })
        .catch((e) => console.error(e));
    }
  };

 
Element
import { lightTheme } from '@/config/theme/Colours';
import { useGlobalDownloadProgressStore } from '@/presentation/retailer/paperwork/obtain.international.progress.retailer';
import React, { useEffect, useRef } from 'react';
import { View, Animated } from 'react-native';

const ProgressBar = () => {
  const animatedProgress = useRef(new Animated.Worth(0)).present;
  const downloadProgress = useGlobalDownloadProgressStore((state) => state.downloadProgress);
  const downloadProgressfinal = downloadProgress / 100;
  const bgProgressBar = lightTheme.secondary1;

  useEffect(() => {
    Animated.timing(animatedProgress, {
      toValue: downloadProgressfinal,
      length: 300,
      useNativeDriver: false,
    }).begin();
  }, [downloadProgressfinal]);

  return (
    
      
    
  );
};

export default ProgressBar;

And dont get error simply the shop initalize in 0 and never replace o change

android and ios simulator works additionally android apk however when i deploy in testlight the bar shouldn’t be working, assist plss 🙁

LEAVE A REPLY

Please enter your comment!
Please enter your name here