{"id":20980518,"url":"https://github.com/hyperjumptech/universal-update-checker","last_synced_at":"2025-05-14T15:30:41.457Z","repository":{"id":36646773,"uuid":"229230413","full_name":"hyperjumptech/universal-update-checker","owner":"hyperjumptech","description":"React component to check if there is a new version of a mobile app","archived":false,"fork":false,"pushed_at":"2023-01-04T13:43:09.000Z","size":1071,"stargazers_count":31,"open_issues_count":18,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-08T22:09:22.457Z","etag":null,"topics":["firebase","hook","indonesia","javascript","react","react-native"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyperjumptech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-2.0.txt","code_of_conduct":"CODE_OF_CONDUCTS.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-20T09:10:55.000Z","updated_at":"2022-12-27T11:52:32.000Z","dependencies_parsed_at":"2023-01-17T03:42:17.104Z","dependency_job_id":null,"html_url":"https://github.com/hyperjumptech/universal-update-checker","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Funiversal-update-checker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Funiversal-update-checker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Funiversal-update-checker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Funiversal-update-checker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperjumptech","download_url":"https://codeload.github.com/hyperjumptech/universal-update-checker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254122807,"owners_count":22018412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firebase","hook","indonesia","javascript","react","react-native"],"created_at":"2024-11-19T05:28:59.588Z","updated_at":"2025-05-14T15:30:40.944Z","avatar_url":"https://github.com/hyperjumptech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/hyperjumptech/universal-update-checker.svg?branch=master)](https://travis-ci.org/hyperjumptech/universal-update-checker)\n[![Build Status](https://dev.azure.com/hyperjumptech/universal-update-checker/_apis/build/status/hyperjumptech.universal-update-checker?branchName=master)](https://dev.azure.com/hyperjumptech/universal-update-checker/_build/latest?definitionId=1\u0026branchName=master)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n# Universal Update Checker\n\n## About\n\nThis library provides react native app ability to perform certain actions when the current version of the app is out of date. With this library you can define `latest` version and `required` version of the app, then force the user to update the app if the current version of the app is lower than `required` version. If the app is higher than the required version but lower than the latest version, you can recommend the user to update the app.\n\nThis library is flexible on:\n\n- how to get the current version of the app. You can simply tell the library what version to use, or you can provide it with your own function that returns the current version.\n- how to get the latest and required version of the app.\n- how to compare the current version and the latest and/or required version. You can write a function that returns one of three strings: `none`, `required`, or `latest`: `none` string if the app is up to date, `required` string if the current version of the app is less than the required version, and `latest` string if the there is a new version of the app.\n\nYou can use the functions defined in `universal-update-checker/default-local-remote` to get the local version and remove versions:\n\n- `getLocalVersion`: this function returns the app version on iOS (e.g., `1.0.0`) and the `versionCode` on Android.\n- `getVersionsFromFirebase`: this function fetches the required and latest versions from Firebase Remote Config.\n- `getUpdateStatus`: this function compares the local version and the remote versions. This function will simply compare the versions with `\u003c` and `\u003e` operators. \n\n## Requirements\n\nIf you don't provide your own functions to get the current version of the app and to compare the versions, your react native app must\n\n1. install the following dependencies:\n\n   - [react-native-device-info](https://github.com/react-native-community/react-native-device-info)\n   - [react-native-firebase](https://rnfirebase.io/)\n\n2. Set up your app to use Firebase.\n3. Create 4 parameters in your [project's remote config](https://console.firebase.google.com/):\n\n   - `latest_version_ios`\n   - `required_version_ios`\n   - `latest_version_android`\n   - `required_version_android`\n\n## Installation\n\nUsing npm:\n\n```\nnpm i @hyperjumptech/universal-update-checker\n```\n\nor using yarn:\n\n```\nyarn add @hyperjumptech/universal-update-checker\n```\n\n## Usage\n\nUsing render props:\n\n```javascript\nimport UpdateChecker from \"@hyperjumptech/universal-update-checker\";\nimport {\n  getUpdateStatus,\n  getVersionsFromFirebase,\n  getLocalVersion\n} from \"@hyperjumptech/universal-update-checker/default-local-remote\";\n\nconst Root = () =\u003e {\n  return (\n    \u003cUpdateChecker\n      getLocalVersion={getLocalVersion}\n      getLatestAndRequiredVersions={getVersionsFromFirebase}\n      getUpdateStatus={getUpdateStatus}\n    \u003e\n      {({ isChecking, updateState, versions, checkNow }) =\u003e {\n        if (isChecking) {\n          return \u003cActivityIndicator size=\"large\" color=\"#0000ff\" /\u003e;\n        } else {\n          if (updateState === \"required\") {\n            // show modal screen\n            return (\n              \u003cView style={styles.updateRequired}\u003e\n                \u003cText style={styles.centerText}\u003e\n                  You have to update the app from the App Store or Play Store.\n                  Current vesion: {versions.local}. Required version:{\" \"}\n                  {versions.required}\n                \u003c/Text\u003e\n              \u003c/View\u003e\n            );\n          } else if (updateState === \"latest\") {\n            // show alert\n            Alert.alert(\n              \"New Update\",\n              \"There is a new update in the App Store or Play Store\"\n            );\n            return null;\n          } else if (updateState === \"none\") {\n            // continue with your App\n            return \u003cApp /\u003e;\n          }\n        }\n      }}\n    \u003c/UpdateChecker\u003e\n  );\n};\n```\n\nUsing react hook:\n\n```javascript\nimport { useUpdateChecker } from \"@hyperjumptech/universal-update-checker\";\nimport {\n  getUpdateStatus,\n  getVersionsFromFirebase,\n  getLocalVersion\n} from \"@hyperjumptech/universal-update-checker/default-local-remote\";\n\nconst Root = () =\u003e {\n  const { isChecking, updateState } = useUpdateChecker({\n    getLocalVersion,\n    getLatestAndRequiredVersions: getVersionsFromFirebase,\n    getUpdateStatus\n  });\n\n  if (isChecking) {\n    return \u003cActivityIndicator /\u003e;\n  }\n\n  if (updateState === \"required\") {\n    // show modal screen\n    return (\n      \u003cView style={styles.updateRequired}\u003e\n        \u003cText style={styles.centerText}\u003e\n          You have to update the app from the App Store or Play Store. Current\n          vesion: {versions.local}. Required version: {versions.required}\n        \u003c/Text\u003e\n      \u003c/View\u003e\n    );\n  } else if (updateState === \"latest\") {\n    // show alert\n    Alert.alert(\n      \"New Update\",\n      \"There is a new update in the App Store or Play Store\"\n    );\n    return null;\n  }\n\n  // continue with your App\n  return \u003cApp /\u003e;\n};\n```\n\n## API\n\n`UpdateChecker` component and `useUpdateChecker` hook receives the same props/arguments and returns the same object.\n\nProps/arguments:\n\n- `getLocalVersion`: Func. The function is to get the current version of the app. By default, it uses the build number returned by react-native-device-info.\n- `getLatestAndRequiredVersions`: Func. This function is to get the latest and required version of the app. By default, it uses firebase remote-config.\n- `getUpdateStatus`: Func. The function to compare the local version and the latest/required version. It returns either \"`required`\", \"`latest`\", or \"`none`\" string.\n- `interval`: number. The number in miliseconds to perform the version check periodically. Default is `0` which means it is only executed once.\n- `version`: any. The optional current local version of the app. If this is set, getLocalVersion func will not be used to determine the current version of the app.\n- `onUpdateStateResolved`: Func. This function will be called when the updateState has been resolved. This will give a chance for component that uses this library to do non-declarative work with the result of the update check, e.g., to save to storage. The function will receive an object as argument:\n\n```\n{\n  status: \"required\" | \"latest\" | \"none\";\n  versions: {\n    latest: string | number;\n    required: string | number;\n  };\n}\n```\n\nReturns:\n\n1.  `isChecking`: boolean. if true, the hook is checking and comparing the version of the app.\n2.  `updateState`: \"`required`\" | \"`latest`\" | \"`none`\" string.\n\n    - \"required\" means the current version of the app is lower than the minimum required version.\n    - \"latest\" means there is a new version of the app but not required to update.\n    - \"none\" means there is no new version of the app, a.k.a, the current version is up to date.\n\n3.  `error`: Error object. This property is set when error occurs. Default `null`.\n4.  `lastChecked`: Date. The last time this hook checks and compare the versions.\n5.  `checkNow`: Func. You can call this function to initiate the version checking.\n6.  `versions`: `{ latest: any, required: any }`. This property contains the latest and required version.\n\n## TODO\n\n- Example app\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjumptech%2Funiversal-update-checker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperjumptech%2Funiversal-update-checker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjumptech%2Funiversal-update-checker/lists"}