项目作者: MariusMonkam

项目描述 :
Add animated background on your react-native component
高级语言: JavaScript
项目地址: git://github.com/MariusMonkam/react-native-animated-background.git


react-native-animated-background

Getting started

$ npm install react-native-animated-background --save

Mostly automatic installation

$ react-native link react-native-animated-background

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-animated-background and add RNAnimatedBackground.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNAnimatedBackground.a to your project’s Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.reactlibrary.RNAnimatedBackgroundPackage; to the imports at the top of the file
  • Add new RNAnimatedBackgroundPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    1. include ':react-native-animated-background'
    2. project(':react-native-animated-background').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-animated-background/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
    1. compile project(':react-native-animated-background')

Usage

  1. //Note that each component can be imported separately
  2. import RNAnimatedBackground from "react-native-animated-background";
  3. import {
  4. RNAnimatedBgColor,
  5. RNAnimatedBgSeq,
  6. RNAnimatedShapeBgColor,
  7. RNAnimatedCircleBgSeq,
  8. RNAnimatedTriangleBgSeq,
  9. } from "react-native-animated-background";
  10. // TODO: What to do with the module?
  11. export default function App() {
  12. return (
  13. <ScrollView style={styles.container}>
  14. <StatusBar style="auto" ></StatusBar>
  15. <RNAnimatedBgColor
  16. firstColor="red"
  17. secondColor="green"
  18. borderWidth={5}
  19. elevation={8}
  20. width={200}
  21. height={200}
  22. >
  23. <Text>Open up App.js to start working on your app!</Text>
  24. </RNAnimatedBgColor>
  25. <RNAnimatedShapeBgColor
  26. firstColor="blue"
  27. secondColor="yellow"
  28. borderWidth={5}
  29. borderRadius={20}
  30. elevation={8}
  31. margin={5}
  32. width={200}
  33. height={200}
  34. >
  35. <Button
  36. onPress={() => Alert.alert("I love RNAnimatedBorder!")}
  37. title="press me"
  38. />
  39. </RNAnimatedShapeBgColor>
  40. <RNAnimatedBgColor
  41. firstColor="pink"
  42. secondColor="orange"
  43. borderWidth={20}
  44. elevation={8}
  45. margin={5}
  46. width={300}
  47. height={200}
  48. >
  49. <View
  50. style={{ width: 100, height: 100, backgroundColor: "black" }}
  51. ></View>
  52. </RNAnimatedBgColor>
  53. <RNAnimatedBgSeq
  54. numbShapes={100}
  55. backgroundColor="purple"
  56. width={40}
  57. height={40}
  58. elevation={5}
  59. >
  60. <Text
  61. style={{
  62. alignSelf: "center",
  63. position: "absolute",
  64. backgroundColor: "green",
  65. fontSize: 20,
  66. fontWeight: "bold",
  67. color: "white",
  68. textAlign: "center",
  69. elevation: 8,
  70. }}
  71. >
  72. react-native-animated-background
  73. </Text>
  74. </RNAnimatedBgSeq>
  75. <RNAnimatedCircleBgSeq
  76. numbShapes={100}
  77. backgroundColor="yellow"
  78. width={40}
  79. elevation={5}
  80. >
  81. <Text
  82. style={{
  83. alignSelf: "center",
  84. position: "absolute",
  85. backgroundColor: "green",
  86. fontSize: 20,
  87. fontWeight: "bold",
  88. color: "white",
  89. textAlign: "center",
  90. elevation: 8,
  91. }}
  92. >
  93. react-native-animated-background
  94. </Text>
  95. </RNAnimatedCircleBgSeq>
  96. <RNAnimatedTriangleBgSeq
  97. numbShapes={100}
  98. backgroundColor="red"
  99. color="skyblue"
  100. borderLeftWidth={26}
  101. elevation={5}
  102. >
  103. <Text
  104. style={{
  105. alignSelf: "center",
  106. position: "absolute",
  107. backgroundColor: "green",
  108. fontSize: 20,
  109. fontWeight: "bold",
  110. color: "white",
  111. textAlign: "center",
  112. elevation: 8,
  113. }}
  114. >
  115. react-native-animated-background
  116. </Text>
  117. </RNAnimatedTriangleBgSeq>
  118. </ScrollView>
  119. );
  120. }
  121. const styles = StyleSheet.create({
  122. container: {
  123. flex: 1,
  124. backgroundColor: "#fff",
  125. },
  126. });

Play de video to see react-native-animated-background in action

react-native-animated-background