基于 react-native-transitiongroup 的 OpenHarmony 适配版,过渡动画组组件(组件进出场动画)
| Files | Last commit | Last update |
|---|---|---|
| 1 month ago | ||
| 1 month ago | ||
| 9 years ago | ||
| 1 month ago | ||
| 1 year ago | ||
| 6 months ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 9 years ago | ||
| 1 month ago |
Document Template: v0.4.2
react-native-transitiongroup
This project is based on react-native-transitiongroup.
This third-party library has been migrated to GitCode and is now available for direct download from npm, the new package name is: @react-native-ohos/react-native-transitiongroup, the version correspondence details are as follows:
| Name | Version(Npm Address) | Release Information | Supported RN Version | Supported Autolink | Compile API Version | Community Baseline Version | Source code address |
|---|---|---|---|---|---|---|---|
| @react-native-ohos/react-native-transitiongroup | ~1.3.0 | GitCode Releases | 0.72.* / 0.77.* / 0.82.* | No | API12+ | 1.2.0 | master |
| @react-native-oh-tpl/react-native-transitiongroup | <= 1.2.1@deprecated | Github Releases(deprecated) | 0.72.* | No | API12+ | 1.2.0 | sig |
Introduction
react-native-transitiongroup is a transition animation library that provides the TransitionGroup container component and the FadeInOutTransition component. Mount/unmount transitions are triggered by conditional rendering of child components, and the animation effects can be customized through properties such as easing function, delay, and duration.
Installation
Go to the project directory and execute the following instruction:
npm
npm install @react-native-ohos/react-native-transitiongroup@~1.3.0
yarn
yarn add @react-native-ohos/react-native-transitiongroup@~1.3.0
Constraints
Compatibility
This document is verified based on the following versions:
- RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.868; ROM: 6.0.0.112;
Permission Requirements
No special permission is required.
Example
The following code shows the basic use scenario of the repository:
The library name imported during use remains unchanged.
import React, { useState } from "react";
import { StyleSheet, Text, View, TouchableOpacity, Easing } from "react-native";
import TransitionGroup, {
FadeInOutTransition,
} from "react-native-transitiongroup";
export function TransitiongroupExample() {
const [showText, setShowText] = useState(false);
const handleToggle = () => {
setShowText(!showText);
};
return (
<View style={styles.container}>
<View style={styles.relativeContainer}>
<TouchableOpacity onPress={handleToggle} style={styles.button}>
<Text style={styles.buttonText}>{showText ? "Hide" : "Show"}</Text>
</TouchableOpacity>
<TransitionGroup style={styles.absoluteContainer}>
{showText && (
<FadeInOutTransition>
<Text style={styles.text}>Hello, Transition Group!!</Text>
</FadeInOutTransition>
)}
</TransitionGroup>
<TransitionGroup style={styles.absoluteContainerTwo}>
{showText && (
<FadeInOutTransition inDuration={3000}>
<Text style={styles.text}>I'm Later</Text>
</FadeInOutTransition>
)}
</TransitionGroup>
<TransitionGroup style={styles.absoluteContainerThree}>
{showText && (
<FadeInOutTransition
inDuration={1000}
outDuration={500}
easing={Easing.ease}
inDelay={200}
outDelay={0}
pointerEvents="box-only"
style={{ backgroundColor: "pink" }}
>
<Text style={styles.text}>I'm Pink</Text>
</FadeInOutTransition>
)}
</TransitionGroup>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
relativeContainer: {
position: "relative",
},
button: {
backgroundColor: "#3f51b5",
padding: 10,
borderRadius: 5,
marginBottom: 20,
},
buttonText: {
color: "#fff",
fontWeight: "bold",
fontSize: 16,
},
absoluteContainer: {
position: "absolute",
bottom: -50,
left: -100,
},
absoluteContainerTwo: {
position: "absolute",
bottom: -150,
left: -100,
},
absoluteContainerThree: {
position: "absolute",
bottom: -250,
left: -100,
},
text: {
fontSize: 24,
fontWeight: "bold",
},
});
Available APIs
The **Platform** column indicates the platform where the properties are supported in the original third-party library.
If the value of **OpenHarmony Support** is **yes**, it means that the OpenHarmony 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.
Components
| Name | Parameter Type | Required | Platform | OpenHarmony Platform Support | Description |
|---|---|---|---|---|---|
| TransitionGroup | ViewProps | no | All | Yes | Transition container component that triggers enter/exit transition animations when child components are mounted/unmounted |
| FadeInOutTransition | FadeInOutTransitionProps | no | All | Yes | Fade in/out transition component, used inside TransitionGroup to implement fade in/out effects of child components |
Properties
FadeInOutTransitionProps
| Name | Parameter Type | Default Value | Required | Platform | OpenHarmony Platform Support | Description |
|---|---|---|---|---|---|---|
| easing | Function | Easing.linear() | no | All | Yes | Easing function |
| inDelay | Integer | 0 | no | All | Yes | Delay before the animation starts when the component is loaded (ms) |
| inDuration | Integer | 250 | no | All | Yes | Duration of the animation when the component is loaded (ms) |
| outDelay | Integer | 0 | no | All | Yes | Delay before the animation starts when the component is unmounted (ms) |
| outDuration | Integer | 150 | no | All | Yes | Duration of the animation when the component is unmounted (ms) |
| pointerEvents | String | 'box-none' | no | All | Yes | Controls whether the View can be the target of touch events |
| style | ViewPropTypes.style | null | no | All | Yes | Component style |
Known Issues
- The original library uses refs, which is replaced by react.createRef #1
- ViewPropTypes used in the original library is replaced by PropTypes #2
Other
None
Directory Structure
/rntpc_react-native-transitiongroup # Project root directory
├── index.js # Library entry file
├── lib # Component source code
│ ├── TransitionGroup.js # Transition container component
│ └── FadeInOutTransition.js # Fade in/out transition component
├── CHANGELOG.md # Changelog
├── LICENSE # Open source license file
├── README.md # Chinese document
├── README_en.md # English document
└── package.json # Package configuration
How to Contribute
If you find any problem when using react-native-transitiongroup, submit an issue or a PR.
License
This project is licensed under The MIT License (MIT).