Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-native-appearance
Advanced tools
Polyfill for `Appearance` API which will be available in `react-native@0.62`.
Access operating system appearance information on iOS, Android, and web. Currently supports detecting preferred color scheme (light/dark).
Installation instructions vary depending on whether you're using a managed Expo project or a bare React Native project.
This library is supported in Expo SDK 35+ (SDK 35 includes iOS support, SDK 36 and higher includes support for all platforms).
expo install react-native-appearance
Android support and web support are available on SDK36+.
yarn add react-native-appearance
If you are not using AndroidX on your project already (this is the default on React Native 0.60+, but not on lower versions) you will want to use the
jetifier
npm package. Install the package withyarn add -D jetifier
and then underscripts
add"postinstall": "jetify -r"
. Next runyarn jetify
.
After installing the package you need to link the native parts of the library for the platforms you are using. The easiest way to link the library is using the CLI tool by running this command from the root of your project:
react-native link react-native-appearance
If you can't or don't want to use the CLI tool, you can also manually link the library using the instructions below (click on the arrow to show them):
Either follow the instructions in the React Native documentation to manually link the framework or link using Cocoapods by adding this to your Podfile
:
pod 'react-native-appearance', :path => '../node_modules/react-native-appearance'
android/app/src/main/java/[...]/MainApplication.java
import io.expo.appearance.RNCAppearancePackage;
to the imports at the top of the filenew RNCAppearancePackage()
to the list returned by the getPackages()
methodandroid/settings.gradle
:include ':react-native-appearance'
project(':react-native-appearance').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-appearance/android')
android/app/build.gradle
:implementation project(':react-native-appearance')
In Expo managed projects, add ios.userInterfaceStyle
to your app.json
:
{
"expo": {
"ios": {
"userInterfaceStyle": "automatic"
}
}
}
In bare React Native apps, you can configure supported styles with the UIUserInterfaceStyle key in your app Info.plist
.
Add the uiMode
flag in AndroidManifest.xml
:
<activity
...
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode">
Implement the onConfigurationChanged
method in MainActivity.java
:
import android.content.Intent; // <--- import
import android.content.res.Configuration; // <--- import
public class MainActivity extends ReactActivity {
......
// copy these lines
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
sendBroadcast(intent);
}
......
}
First, you need to wrap your app in the AppearanceProvider
. At the root of your app, do the following:
import { AppearanceProvider } from 'react-native-appearance';
export default () => (
<AppearanceProvider>
<App />
</AppearanceProvider>
);
Now you can use Appearance
and useColorScheme
anywhere in your app.
import { Appearance, useColorScheme } from 'react-native-appearance';
/**
* Get the current color scheme
*/
Appearance.getColorScheme();
/**
* Subscribe to color scheme changes with a hook
*/
function MyComponent() {
const colorScheme = useColorScheme();
if (colorScheme === 'dark') {
// render some dark thing
} else {
// render some light thing
}
}
/**
* Subscribe to color scheme without a hook
*/
const subscription = Appearance.addChangeListener(({ colorScheme }) => {
// do something with color scheme
});
// Remove the subscription at some point
subscription.remove()
This was mostly written by Facebook for inclusion in React Native core.
FAQs
Polyfill for `Appearance` API which will be available in `react-native@0.62`.
We found that react-native-appearance demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.