react-native 實(shí)現(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)以下錯(cuò)誤
解決辦法:
1.徹底退出項(xiàng)目重新react-native run-ios就可以了。
2.如果1沒解決,就嘗試2
react-native學(xué)習(xí)記錄
滾動(dòng)條
橫向滾動(dòng):
//在ScrollView里面加上這段代碼即可 ?horizontal={true}
隱藏滾動(dòng)條:
//隱藏水平 showsHorizontalScrollIndicator = {false} //隱藏垂直 showsVerticalScrollIndicator = {false}
輪播圖示例
先導(dǎo)入:
$ 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默認(rèn)頁面
標(biāo)簽內(nèi)加上initialPage并賦值下標(biāo)即可
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背景顏色
標(biāo)簽內(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選中顏色
標(biāo)簽內(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未選中顏色
標(biāo)簽內(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> ? ? ); }
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
React實(shí)現(xiàn)類似于Vue中的插槽的項(xiàng)目實(shí)踐
本文主要介紹了React實(shí)現(xiàn)類似于Vue中的插槽的項(xiàng)目實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05深入理解React中es6創(chuàng)建組件this的方法
this的本質(zhì)可以這樣說,this跟作用域無關(guān)的,只跟執(zhí)行上下文有關(guān)。接下來通過本文給大家介紹React中es6創(chuàng)建組件this的方法,非常不錯(cuò),感興趣的朋友一起看看吧2016-08-08在React項(xiàng)目中使用Eslint代碼檢查工具及常見問題
這篇文章主要介紹了在React項(xiàng)目中使用Eslint代碼檢查工具及常見問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-10-10React之如何在Suspense中優(yōu)雅地請(qǐng)求數(shù)據(jù)
Suspense 是 React 中的一個(gè)組件,直譯過來有懸掛的意思,能夠?qū)⑵浒漠惒浇M件掛起,直到組件加載完成后再渲染,本文詳細(xì)介紹了如何在Suspense中請(qǐng)求數(shù)據(jù),感興趣的小伙伴可以參考閱讀本文2023-04-04基于React實(shí)現(xiàn)搜索GitHub用戶功能
在本篇博客中,我們將介紹如何在 React 應(yīng)用中搜索 GitHub 用戶并顯示他們的信息,文中通過代碼示例給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-02-02react學(xué)習(xí)筆記之state以及setState的使用
這篇文章主要介紹了react學(xué)習(xí)筆記之state以及setState的使用,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12解決React報(bào)錯(cuò)No duplicate props allowed
這篇文章主要為大家介紹了React報(bào)錯(cuò)No duplicate props allowed解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12react同構(gòu)實(shí)踐之實(shí)現(xiàn)自己的同構(gòu)模板
這篇文章主要介紹了react同構(gòu)實(shí)踐之實(shí)現(xiàn)自己的同構(gòu)模板,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03