react-native 實現(xiàn)漸變色背景過程
react-native 漸變色背景
使用react-native-linear-gradient插件
1.安裝
npm react-native-linear-gradient
2.鏈接
react-native link react-native-linear-gradient
3.代碼使用
<LinearGradient colors={["#57AFFF","#2A63BF","#042289"]} style={{flex:1}}> </LinearGradient>
4.效果圖
5.如果出現(xiàn)以下錯誤
解決辦法:
1.徹底退出項目重新react-native run-ios就可以了。
2.如果1沒解決,就嘗試2
react-native學習記錄
滾動條
橫向滾動:
//在ScrollView里面加上這段代碼即可 ?horizontal={true}
隱藏滾動條:
//隱藏水平 showsHorizontalScrollIndicator = {false} //隱藏垂直 showsVerticalScrollIndicator = {false}
輪播圖示例
先導入:
$ npm install react-native-swiper --save $ npm i react-timer-mixin --save
import React, {Component} from 'react'; import { ? ? StyleSheet, ? ? View, ? ? Image, } from 'react-native'; import Dimensions from 'Dimensions'; import Swiper from 'react-native-swiper'; var screenWidth = Dimensions.get('window').width; export default class SwiperScreen extends Component { ? ? render() { ? ? ? ? return ( ? ? ? ? ? ? <View style={styles.lunbotu}> ? ? ? ? ? ? ? ? <Swiper ? ? ? ? ? ? ? ? ? ? style={styles.wrapper} ? ? ? ? ? ? ? ? ? ? height={240} ? ? ? ? ? ? ? ? ? ? autoplay={true} ? ? ? ? ? ? ? ? ? ? loop={true} ? ? ? ? ? ? ? ? ? ? keyExtractor={(item, index) => index + ''} ? ? ? ? ? ? ? ? ? ? index={1} ? ? ? ? ? ? ? ? ? ? autoplayTimeout={3} ? ? ? ? ? ? ? ? ? ? horizontal={true} ? ? ? ? ? ? ? ? ? ? onMomentumScrollEnd={(e, state, context) => { ? ? ? ? ? ? ? ? ? ? }} ? ? ? ? ? ? ? ? ? ? dot={<View style={styles.dotStyle}/>} ? ? ? ? ? ? ? ? ? ? activeDot={<View style={styles.activeDotStyle}/>} ? ? ? ? ? ? ? ? ? ? paginationStyle={{ ? ? ? ? ? ? ? ? ? ? ? ? bottom: 10 ? ? ? ? ? ? ? ? ? ? }}> ? ? ? ? ? ? ? ? ? ? <View> ? ? ? ? ? ? ? ? ? ? ? ? <Image style={{width: screenWidth, height: 150}} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?resizeMode="stretch" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?source={{uri: ''}}> ? ? ? ? ? ? ? ? ? ? ? ? </Image> ? ? ? ? ? ? ? ? ? ? </View> ? ? ? ? ? ? ? ? ? ? <View> ? ? ? ? ? ? ? ? ? ? ? ? <Image style={{width: screenWidth, height: 150}} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?resizeMode="stretch" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?source={{uri: ''}}> ? ? ? ? ? ? ? ? ? ? ? ? </Image> ? ? ? ? ? ? ? ? ? ? </View> ? ? ? ? ? ? ? ? ? ? <View> ? ? ? ? ? ? ? ? ? ? ? ? <Image style={{width: screenWidth, height: 150}} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?resizeMode="stretch" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?source={{uri: ''}}> ? ? ? ? ? ? ? ? ? ? ? ? </Image> ? ? ? ? ? ? ? ? ? ? </View> ? ? ? ? ? ? ? ? </Swiper> ? ? ? ? ? ? </View> ? ? ? ? ); ? ? } } const styles = StyleSheet.create({ ? ? dotStyle: { ? ? ? ? width: 22, ? ? ? ? height: 3, ? ? ? ? backgroundColor: '#fff', ? ? ? ? opacity: 0.4, ? ? ? ? borderRadius: 0, ? ? }, ? ? activeDotStyle: { ? ? ? ? width: 22, ? ? ? ? height: 3, ? ? ? ? backgroundColor: '#fff', ? ? ? ? borderRadius: 0, ? ? }, ? ? lunbotu: { ? ? ? ? height: 120, ? ? ? ? backgroundColor: '#222222' ? ? }, });
漸變色
先安裝:
?yarn add react-native-linear-gradient ?react-native link react-native-linear-gradient
import React, {Component} from 'react'; import { ? ? Image, ? ? View, ? ? Text, ? ? StyleSheet } from 'react-native'; import LinearGradient from "react-native-linear-gradient"; export default class LinearGradientScreen extends Component { ? ? render() { ? ? ? ? return ( ? ? ? ? ? ? <View style={{height: '100%'}}> ? ? ? ? ? ? ? ? <LinearGradient colors={['red', 'green', 'blue']} style={styles.container}> ? ? ? ? ? ? ? ? </LinearGradient> ? ? ? ? ? ? </View> ? ? ? ? ); ? ? } } const styles = StyleSheet.create({ ? ? container: { ? ? ? ? height: '100%' ? ? } })
ScrollableTabView默認頁面
標簽內(nèi)加上initialPage并賦值下標即可
render() { ? ? return ( ? ? ? ? <ScrollableTabView ? ? ? ? ? ? initialPage={1}> ? ? ? ? ? ? <Text tabLabel='Tab 1'>Tab 1</Text> ? ? ? ? ? ? <Text tabLabel='Tab 2'>Tab 2</Text> ? ? ? ? ? ? <Text tabLabel='Tab 3'>Tab 3</Text> ? ? ? ? </ScrollableTabView> ? ? ); }
ScrollableTabView背景顏色
標簽內(nèi)加上tabBarBackgroundColor并賦值即可
render() { ? ? return ( ? ? ? ? <ScrollableTabView ? ? ? ? ? ? tabBarBackgroundColor='#FFFFFF'> ? ? ? ? ? ? <Text tabLabel='Tab 1'>Tab 1</Text> ? ? ? ? ? ? <Text tabLabel='Tab 2'>Tab 2</Text> ? ? ? ? ? ? <Text tabLabel='Tab 3'>Tab 3</Text> ? ? ? ? </ScrollableTabView> ? ? ); }
ScrollableTabView選中顏色
標簽內(nèi)加上tabBarActiveTextColor并賦值即可
render() { ? ? return ( ? ? ? ? <ScrollableTabView ? ? ? ? ? ? tabBarActiveTextColor='#FFFFFF'> ? ? ? ? ? ? <Text tabLabel='Tab 1'>Tab 1</Text> ? ? ? ? ? ? <Text tabLabel='Tab 2'>Tab 2</Text> ? ? ? ? ? ? <Text tabLabel='Tab 3'>Tab 3</Text> ? ? ? ? </ScrollableTabView> ? ? ); }
ScrollableTabView未選中顏色
標簽內(nèi)加上tabBarInactiveTextColor并賦值即可
render() { ? ? return ( ? ? ? ? <ScrollableTabView ? ? ? ? ? ? tabBarInactiveTextColor ='#FFFFFF'> ? ? ? ? ? ? <Text tabLabel='Tab 1'>Tab 1</Text> ? ? ? ? ? ? <Text tabLabel='Tab 2'>Tab 2</Text> ? ? ? ? ? ? <Text tabLabel='Tab 3'>Tab 3</Text> ? ? ? ? </ScrollableTabView> ? ? ); }
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
深入理解React中es6創(chuàng)建組件this的方法
this的本質(zhì)可以這樣說,this跟作用域無關(guān)的,只跟執(zhí)行上下文有關(guān)。接下來通過本文給大家介紹React中es6創(chuàng)建組件this的方法,非常不錯,感興趣的朋友一起看看吧2016-08-08React之如何在Suspense中優(yōu)雅地請求數(shù)據(jù)
Suspense 是 React 中的一個組件,直譯過來有懸掛的意思,能夠?qū)⑵浒漠惒浇M件掛起,直到組件加載完成后再渲染,本文詳細介紹了如何在Suspense中請求數(shù)據(jù),感興趣的小伙伴可以參考閱讀本文2023-04-04解決React報錯No duplicate props allowed
這篇文章主要為大家介紹了React報錯No duplicate props allowed解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12react同構(gòu)實踐之實現(xiàn)自己的同構(gòu)模板
這篇文章主要介紹了react同構(gòu)實踐之實現(xiàn)自己的同構(gòu)模板,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-03-03