npm package: @revlumofficial/react-native-offerwall
Description: React Native library for integrating the Revlum Offerwall SDK. Easily configure and launch an offerwall on Android and iOS, allowing users to earn rewards through engaging offers.
Author: Revlum
Latest version: 0.1.1

# @revlumofficial/react-native-offerwall

React Native library for integrating the Revlum Offerwall SDK. Easily configure and launch an offerwall on Android and iOS, allowing users to earn rewards through engaging offers.

The Revlum Offerwall Plugin is a React Native plugin that wraps the native Revlum Offerwall SDK implementations for both Android and iOS. For more details on the native implementations, you can refer to the official documentation for [iOS](https://developer.revlum.com/docs/ios) and [Android](https://developer.revlum.com/docs/revlum-android-sdk).

|             | Android   | iOS       |
|-------------|-----------|-----------|
| **Support** | minSdk 24 | iOS 16.0+ |

## Installation
Install the package using `yarn`:

```bash
yarn add @revlumofficial/react-native-offerwall
```
or with `npm`:

```sh
npm install @revlumofficial/react-native-offerwall
```

## Setup

### Android

1. **Minimum SDK Requirement:**
   Ensure that your Android `minSdkVersion` is set to 24 or higher.

2. **Add Revlum Maven Repository:**
   In your Android project, navigate to your `android/build.gradle` file and ensure that the Revlum Maven repository is added under the `allprojects` section. It should look like this:

   ```gradle
   allprojects {
       repositories {
           maven {
               url = uri("https://sdk-revlum-android.s3.amazonaws.com/")
               content {
                   includeGroup("com.revlum")
               }
           }
           google()
           mavenCentral()
       }
   }
   ```

### iOS

1. **Modify `AppDelegate.mm`:**
   In your `AppDelegate.mm`, set up the navigation controller as shown below:

   ```objective-c
   #import "AppDelegate.h"
   #import <React/RCTBundleURLProvider.h>
   #import <React/RCTRootView.h>

   @implementation AppDelegate 

   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
   {
     self.moduleName = @"OfferwallExample";
     self.initialProps = @{};
     
     // Begin: Add the following code to initialize the React Native view and set up the navigation controller. Don't forget to replace 'moduleName' with the correct value above.
     NSURL *jsCodeLocation = [self bundleURL];

     RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                         moduleName:@"OfferwallExample"
                                                  initialProperties:nil
                                                      launchOptions:launchOptions];

     UIViewController *rootViewController = [UIViewController new];
     rootViewController.view = rootView;

     self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
     self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
     [self.window makeKeyAndVisible];

     return YES;
     // End: Added code for React Native view and navigation controller setup
   }

   - (NSURL *)bundleURL
   {
   #if DEBUG
     return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
   #else
     return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
   #endif
   }

   @end
   ```

## Usage

### 1. Configure the Offerwall

Before launching the Offerwall or checking for rewards, configure the SDK by calling the `configure` method. You need to provide the API key and optional parameters like `userId` and `subId`. If you do not provide a user ID, the SDK will automatically generate one. If a user ID is set, it will be used unless manually changed.

```javascript
import { configure } from '@revlumofficial/react-native-offerwall';

const initOfferwall = async () => {
  try {
    await configure('your_api_key', null, 'Revlum');
  } catch (error) {
    console.error('Configure error:', error);
  }
};
```

### 2. Launch the Offerwall

After configuring the SDK, you can launch the Offerwall using the `launch` method:

```javascript
import { launch } from '@revlumofficial/react-native-offerwall';

const handleLaunchOfferwall = async () => {
  try {
    await launch();
  } catch (error) {
    console.error('Launch error:', error);
  }
};
```

### 3. Check for rewards

Check for rewards by using the `checkReward` function. It returns a reward value (which will be 0 if there is no reward) and a list of conversions:

```javascript
import { checkReward } from '@revlumofficial/react-native-offerwall';

const checkRewards = async () => {
  try {
    const rewardData = await checkReward();
    console.log('Reward:', rewardData.reward);
  } catch (error) {
    console.error('Check reward error:', error);
  }
};
```

### Full Example

```javascript
import { useRef, useEffect } from 'react';
import { View, Button, AppState, AppStateStatus, StyleSheet } from 'react-native';
import { configure, launch, checkReward } from '@revlumofficial/react-native-offerwall';

export default function App() {
  const appState = useRef(AppState.currentState);

  useEffect(() => {

    const _initOfferwall = async () => {
      try {
        await configure('your_api_key', null, 'Revlum');
      } catch (error) {
        console.error('Configure error:', error);
      }
    };

    _initOfferwall();

    const _checkRewards = async () => {
      try {
        const rewardData = await checkReward();
        console.log(`checkReward: reward: ${rewardData.reward}`);
      } catch (error) {
        console.error('checkReward error:', error);
      }
    };

    const subscription = AppState.addEventListener('change', (nextAppState: AppStateStatus) => {
      if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
        _checkRewards();
      }
      appState.current = nextAppState;
    });

    return () => {
      subscription.remove();
    };
  }, []);

  const _handleLaunchOfferwall = async () => {
    try {
      await launch();
    } catch (error) {
      console.error('Launch error:', error);
    }
  };

  return (
    <View style={styles.container}>
      <Button title="Launch Offerwall" onPress={_handleLaunchOfferwall} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});
```

## Contributing

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)