Linking
React Native 0.68+
From React Native v0.68 and above, linking is automatic via Autolinking. No manual linking is required.
iOS
After installation, navigate to the ios directory and install CocoaPods dependencies:
cd ios && pod install
Android
No additional steps required. The library will be automatically linked during the build process.
Deprecated
The following sections are for legacy versions only. If you are using React Native 0.68+ and react-native-screenguard v1.0.8+, you can skip this entire section.
React Native 0.59 and below (Manual Linking)
React Native 0.59 and below is no longer supported in v2.0.0. Please upgrade to React Native 0.68+ to use the latest version.
iOS Manual Linking
- In Xcode, right-click on
Librariesin the project navigator - Select Add Files to [your project's name]
- Navigate to
node_modules/react-native-screenguardand addScreenGuard.xcodeproj - Select your project in the navigator, go to Build Phases → Link Binary With Libraries
- Add
libScreenguard.a
Android Manual Linking
- Open
android/app/src/main/java/[...]/MainActivity.java:
import com.screenguard.ScreenGuardPackage; // Add this import
// Add to getPackages() method:
new ScreenGuardPackage()
- Add to
android/settings.gradle:
include ':react-native-screenguard'
project(':react-native-screenguard').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-screenguard/android')
- Add to
android/app/build.gradledependencies:
implementation project(':react-native-screenguard')
Android Post-Installation (v1.0.6 and below)
Starting from v1.0.8, the activity is automatically declared in the library's AndroidManifest.xml and merged during build. This step is only required for v1.0.6 and below.
For versions v1.0.6 and below, you must manually declare the ScreenGuardColorActivity in your AndroidManifest.xml to enable background color and blur effects.
Step 1: Update AndroidManifest.xml
Open android/app/src/main/AndroidManifest.xml and add the activity:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application ...>
<activity android:name=".MainActivity" ...>
...
</activity>
<!-- Add this activity -->
<activity
android:name="com.screenguard.ScreenGuardColorActivity"
android:theme="@style/Theme.AppCompat.Translucent"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
android:exported="false"
/>
</application>
</manifest>
Step 2: Add Translucent Theme
Open android/app/src/main/res/values/styles.xml and add the theme:
<resources>
<style name="AppTheme">
<!-- Your existing theme -->
</style>
<!-- Add this theme -->
<style name="Theme.AppCompat.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
</resources>