microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.99k stars 1.47k forks source link

function component codePushStatusDidChange method bind? #2475

Closed xclidongbo closed 1 year ago

xclidongbo commented 1 year ago

import React, {Component, useState, useEffect, useCallback} from 'react';
import {
  SafeAreaView,
  StyleSheet,
  ScrollView,
  View,
  Text,
  StatusBar,
} from 'react-native';

import {
  Header,
  LearnMoreLinks,
  Colors,
  DebugInstructions,
  ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
import CodePush from 'react-native-code-push';

const CodePushOptions = {
  checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME,
  // mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE,
  installMode: CodePush.InstallMode.ON_NEXT_RESUME,
  minimumBackgroundDuration: 5,
  // updateDialog: {
  //   appendReleaseDescription: true,
  //   title: 'a new update is available!',
  // },
};

class App extends Component {
  codePushStatusDidChange = (status) => {
    switch (status) {
      case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
        console.log('Checking for updates.');
        break;
      case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
        console.log('Downloading package.');
        break;
      case CodePush.SyncStatus.INSTALLING_UPDATE:
        console.log('Installing update.');
        break;
      case CodePush.SyncStatus.UP_TO_DATE:
        console.log('Up-to-date.');
        break;
      case CodePush.SyncStatus.UPDATE_INSTALLED:
        console.log('Update installed.');
        break;
    }
  };
  codePushDownloadDidProgress = (progress) => {
    console.log(
      progress.receivedBytes + ' of ' + progress.totalBytes + ' received.',
    );
  };
  render() {
    return (
      <View>
        <Text>App</Text>
        <Text>App</Text>
        <Text>App</Text>
        <Text>App</Text>
        <Text>App123123</Text>
      </View>
    );
  }
}

// const downloadProgressCallback = useCallback((progress) => {
//   console.log(
//     progress.receivedBytes + ' of ' + progress.totalBytes + ' received.',
//   );
// }, []);

// const checkUpdate = async () => {
//   try {
//     const update = await CodePush.checkForUpdate();
//     if (update) {
//       CodePush.sync({}, codePushStatusDidChange, codePushDownloadDidProgress);
//     }
//   } catch (error) {}
// };

export default CodePush(CodePushOptions)(App);

How can I do for function component?

microsoft-github-policy-service[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs within 15 days of this comment.

microsoft-github-policy-service[bot] commented 1 year ago

This issue will now be closed because it hasn't had any activity for 15 days after stale. Please feel free to open a new issue if you still have a question/issue or suggestion.

microsoft-github-policy-service[bot] commented 1 year ago

This issue will now be closed because it hasn't had any activity for 15 days after stale. Please feel free to open a new issue if you still have a question/issue or suggestion.