https://github.com/nextfaze/react-native-manup
https://github.com/nextfaze/react-native-manup
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nextfaze/react-native-manup
- Owner: NextFaze
- License: mit
- Created: 2025-08-01T04:52:04.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-08-01T08:51:32.000Z (11 months ago)
- Last Synced: 2025-08-01T10:50:56.559Z (11 months ago)
- Language: TypeScript
- Size: 1.78 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# react-native-manup
A React Native library for handling mandatory app updates and maintenance mode. This library provides a simple way to check if your app version is supported, requires an update, or if the app is in maintenance mode.
## Features
- 🔄 **Version Validation**: Automatically validates app version against minimum and latest requirements
- 🚧 **Maintenance Mode**: Support for putting apps in maintenance mode
- 🔥 **Firebase Remote Config**: Integration with Firebase Remote Config for dynamic configuration
- 🌐 **HTTP Configuration**: Support for HTTP-based configuration endpoints
- 📱 **Platform Specific**: Different configuration for iOS and Android
- ⚡ **Real-time Updates**: Automatic status updates with callback support
## Installation
```sh
npm install react-native-manup
```
### Peer Dependencies
This library requires the following peer dependencies:
```sh
npm install react-native-device-info
```
#### Optional Firebase Dependencies
If you plan to use Firebase Remote Config as your configuration source, you'll also need to install:
```sh
npm install @react-native-firebase/app @react-native-firebase/remote-config
```
## Usage
### Remote Config Provider
The `RemoteConfigProvider` is a unified solution that works with any config source. It provides automatic caching, refetching, and change detection through react-query.
#### HTTP Configuration Example
Can also see the full example code at [example/App.tsx](example/App.tsx)
```tsx
import React from 'react';
import { Alert } from 'react-native';
import { RemoteConfigProvider, useRemoteConfigManUp } from 'react-native-manup';
function App() {
return (
{
const response = await fetch('https://your-api.com/config.json', { cache: 'no-store'});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}}
refetchInterval={3600000} // 1 hour (optional)
queryKey="httpConfig" // optional
>
);
}
function HomeScreen() {
const { status, message } = useRemoteConfigManUp({
const onUpdateAvailable = () => {
// - Display update available modal
// - Modal can be dismissed
};
const onUpdateRequired = () => {
// - Display update required modal
// - Modal shouldn't be dismissible as user is required to update the app
};
const onMaintenanceMode = () => {
// - Display maintenance mode modal
// - Modal shouldn't be dismissible as the app is in maintenance mode
};
});
return (
// Your app content
);
}
```
#### Firebase Remote Config Example
> **Prerequisite**: You must install and set up Firebase in your React Native app before using this provider. Follow the [React Native Firebase setup guide](https://rnfirebase.io/#installation) to configure `@react-native-firebase/app` and `@react-native-firebase/remote-config`.
```tsx
import React from 'react';
import { Alert } from 'react-native';
import { RemoteConfigProvider, useRemoteConfigManUp } from 'react-native-manup';
import remoteConfig from '@react-native-firebase/remote-config';
function App() {
return (
{
await remoteConfig().fetchAndActivate();
return JSON.parse(remoteConfig().getValue('appConfig').asString());
}}
queryKey="firebaseConfig"
>
);
}
function HomeScreen() {
const { status, message } = useRemoteConfigManUp({
const onUpdateAvailable = () => {
// - Display update available modal
// - Modal can be dismissed
};
const onUpdateRequired = () => {
// - Display update required modal
// - Modal shouldn't be dismissible as user is required to update the app
};
const onMaintenanceMode = () => {
// - Display maintenance mode modal
// - Modal shouldn't be dismissible as the app is in maintenance mode
};
});
return (
// Your app content
);
}
```
## Configuration
The library expects a configuration object with platform-specific data. Here's the structure:
```typescript
interface Config {
[key: string]: PlatFormData;
}
interface PlatFormData {
latest: string; // Latest available version
minimum: string; // Minimum supported version
url: string; // Download URL for the app
enabled: boolean; // Whether the app is enabled
}
```
### Example Configuration
```json
{
"ios": {
"latest": "1.2.0",
"minimum": "1.0.0",
"url": "https://apps.apple.com/app/yourapp",
"enabled": true,
// Custom platform-specific property - can be any additional data you need
"publicApiUrl": "https://api.ios-example.com/v1"
},
"android": {
"latest": "1.2.0",
"minimum": "1.0.0",
"url": "https://play.google.com/store/apps/details?id=com.yourapp",
"enabled": true,
// Custom platform-specific property - can be any additional data you need
"publicApiUrl": "https://api.android-example.com/v1"
},
// Custom global property - shared across all platforms
"publicApiUrl": "https://api.example.com/v1"
}
```
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
## License
MIT
---
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)