react-native 實(shí)現(xiàn)漸變色背景過(guò)程
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沒(méi)解決,就嘗試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)頁(yè)面
標(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í)間戳計(jì)算得到開(kāi)始和結(jié)束時(shí)間戳
這篇文章主要介紹了React 如何拿時(shí)間戳計(jì)算得到開(kāi)始和結(jié)束時(shí)間戳,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09
React中 Zustand狀態(tài)管理庫(kù)的使用詳解
Zustand?是一個(gè)非常輕量、簡(jiǎn)潔的狀態(tài)管理庫(kù),旨在為 React 提供簡(jiǎn)便且高效的狀態(tài)管理,相比于 Redux 或 Context API,Zustand 具有更簡(jiǎn)潔、靈活和易于理解的優(yōu)點(diǎn),感興趣的朋友一起看看吧2024-12-12
React Native react-navigation 導(dǎo)航使用詳解
本篇文章主要介紹了React Native react-navigation 導(dǎo)航使用詳解,詳解的介紹了react-navigation導(dǎo)航的使用,具有一定的參考價(jià)值,有興趣的可以了解一下2017-12-12
基于React-Dropzone開(kāi)發(fā)上傳組件功能(實(shí)例演示)
這篇文章主要介紹了基于React-Dropzone開(kāi)發(fā)上傳組件,主要講述的是在React-Flask框架上開(kāi)發(fā)上傳組件的技巧,需要的朋友可以參考下2021-08-08
淺談React-router v6 實(shí)現(xiàn)登錄驗(yàn)證流程
本文主要介紹了React-router v6 實(shí)現(xiàn)登錄驗(yàn)證流程,主要介紹了公共頁(yè)面、受保護(hù)頁(yè)面和登錄頁(yè)面,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
詳解React setState數(shù)據(jù)更新機(jī)制
這篇文章主要介紹了React setState數(shù)據(jù)更新機(jī)制的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用React框架,感興趣的朋友可以了解下2021-04-04
React?中如何將CSS?visibility?屬性設(shè)置為?hidden
這篇文章主要介紹了React中如何將CSS?visibility屬性設(shè)置為?hidden,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-05-05
可定制react18 input otp 一次性密碼輸入組件
這篇文章主要為大家介紹了可定制react18 input otp 一次性密碼輸入組件,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10

