Template version: v0.2.2
[!TIP] GitHub address
Find the matching version information in the release address of a third-party library: @react-native-oh-tpl/react-native-bars Releases.For older versions that are not published to npm, please refer to the installation guide to install the tgz package.
Go to the project directory and execute the following instruction:
npm install @react-native-oh-tpl/react-native-barsyarn add @react-native-oh-tpl/react-native-barsThe following code shows the basic use scenario of the repository:
[!WARNING] The name of the imported repository remains unchanged.
import * as React from "react";
import { Switch, Text, View } from "react-native";
import { StatusBar } from "react-native-bars";
export function BarExample() {
const [isEnabled, setIsEnabled] = React.useState(false);
const toggleSwitch = () => setIsEnabled((previousState) => !previousState);
return (
<View>
<StatusBar barStyle={isEnabled ? "light-content" : "dark-content"} />
<Text style={{ color: "white" }}>close dark-content/ open light-content</Text>
<Switch
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={isEnabled ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={isEnabled}
/>
</View>
);
}If this repository has been adapted to Codegen, generate the bridge code of the third-party library by using the Codegen. For details, see Codegen Usage Guide.
Currently, HarmonyOS does not support AutoLink. Therefore, you need to manually configure the linking.
Open the harmony directory of the HarmonyOS project in DevEco Studio.
{
...
"overrides": {
"@rnoh/react-native-openharmony" : "file:./react_native_openharmony"
}
}Currently, two methods are available:
Method 1 (recommended): Use the HAR file.
[!TIP] The HAR file is stored in the
harmonydirectory in the installation path of the third-party library.
Open entry/oh-package.json5 file and add the following dependencies:
"dependencies": {
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
"@react-native-oh-tpl/react-native-bars": "file:../../node_modules/@react-native-oh-tpl/react-native-bars/harmony/bars.har"
}Click the sync button in the upper right corner.
Alternatively, run the following instruction on the terminal:
cd entry
ohpm installMethod 2: Directly link to the source code.
[!TIP] For details, see Directly Linking Source Code.
Open the entry/src/main/ets/RNPackagesFactory.ts file and add the following code:
...
+ import {RNBarsPackage} from '@react-native-oh-tpl/react-native-bars/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
new SamplePackage(ctx),
+ new RNBarsPackage(ctx)
];
}Click the sync button in the upper right corner.
Alternatively, run the following instruction on the terminal:
cd entry
ohpm installThen build and run the code.
To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone.
Check the release version information in the release address of the third-party library: @react-native-oh-tpl/react-native-bars Releases
[!TIP] The Platform column indicates the platform where the properties are supported in the original third-party library.
[!TIP] If the value of HarmonyOS Support is yes, it means that the HarmonyOS platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|---|---|---|---|---|---|
| barStyle | Status Bar Style | string | yes | all | yes |
| animated | Should transition between status bar property changes be animated? (has no effect on Android) | boolean | no | all | no |
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|---|---|---|---|---|---|
| barStyle | Navigation Bar Style | string | yes | all | no |
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|---|---|---|---|---|---|
| barStyle | System Style | string | yes | all | no |
| animated | Should transition between status bar property changes be animated? (has no effect on Android) | boolean | no | all | no |
[!TIP] The Platform column indicates the platform where the properties are supported in the original third-party library.
[!TIP] If the value of HarmonyOS Support is yes, it means that the HarmonyOS platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|---|---|---|---|---|---|
| pushStackEntry | Add an instance to the heap queue | StatusBar.pushStackEntry(props) | no | all | yes |
| popStackEntry | Delete an instance from the heap queue | StatusBar.popStackEntry(entry/: StatusBarProps/): void; | no | all | yes |
| replaceStackEntry | Replace an instance of the heap queue | const entry: StatusBarProps = StatusBar.replaceStackEntry(entry ,props ) | no | all | yes |
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|---|---|---|---|---|---|
| pushStackEntry | Add an instance to the heap queue | NavigationBar.pushStackEntry(props) | no | all | no |
| popStackEntry | Delete an instance from the heap queue | NavigationBar.popStackEntry(entry/: NavigationBarProps/): void; | no | all | no |
| replaceStackEntry | Replace an instance of the heap queue | const entry: NavigationBarProps = NavigationBar.replaceStackEntry(entry ,props ) | no | all | no |
This project is licensed under The MIT License (MIT).