[RN] React Native 自定義導航欄隨滾動漸變

?React Native 自定義導航欄隨滾動漸變

?

實現效果預覽:

?

?

代碼實現:

1、定義導航欄 NavPage.js

import React, {Component} from 'react';
import {View, Text, Image, StyleSheet, TouchableOpacity, Platform, Dimensions} from 'react-native';/*** 自定義導航欄*/
let height = (Platform.OS === 'ios' ? 20 : 0) + 90export default class NavPage extends Component {static defaultProps = {title: 'title',};render() {let {title} = this.props;return (<View style={styles.container}><TouchableOpacity style={styles.item} onPress={() => {alert('返回')}}><Image style={styles.icon} source={require('./arrow.png')}/></TouchableOpacity><View style={{alignItems: 'center', flex: 1}}><Text style={{color: '#FFF', fontSize: 17}}>{title}</Text></View><TouchableOpacity style={styles.item} onPress={() => {alert('更多')}}><Image style={[styles.icon, {width: 25, height: 5}]} source={require('./more.png')}/></TouchableOpacity></View>);}
}const styles = StyleSheet.create({container: {width: Dimensions.get('window').width,height: height,flexDirection: 'row',alignItems: 'center',justifyContent: 'space-between',paddingTop: Platform.OS === 'ios' ? 20 : 0,paddingHorizontal: 10,position: 'absolute',},icon: {width: 21,height: 21,color: "white",},item: {height: 30,width: 30,justifyContent: 'center',alignItems: 'center'}
});

?

調用實現:

import React, {Component} from 'react'
import {StyleSheet,Text,View,ListView,Image,Dimensions,TextInput
} from 'react-native'
import NavPage from "./NavPage";const {width} = Dimensions.get('window')export default class TestMyNav extends Component<{}> {constructor(props) {super(props)this.navBar = nullthis.renderRow = this.renderRow.bind(this)this.renderHeader = this.renderHeader.bind(this)this.state = {dataSource: new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})}}renderRow(rowData, sectionId, rowId) {return (<Viewstyle={{height: 100, justifyContent: 'center', borderWidth: 1, borderColor: 'red'}}key={rowId}><Text style={{marginHorizontal: 10}}>{`這時第:${rowId}行`}</Text></View>)}renderHeader() {return (<View><Image style={{height: 200, width: width}}source={{uri: 'https://upload.jianshu.io/users/upload_avatars/2174847/35584aef-dcac-46c0-9280-67a3b1ebb2c9.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/96/h/96'}}resizeMode={'cover'}/></View>)}_onScroll(event) {let y = event.nativeEvent.contentOffset.ylet opacityPercent = y / 200if (y < 200) {this.navBar.setNativeProps({style: {opacity: opacityPercent}})} else {this.navBar.setNativeProps({style: {opacity: 1}})}}render() {let dataSource = this.state.dataSource.cloneWithRows([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])return (<View style={styles.container}><ListViewonScroll={this._onScroll.bind(this)}bounces={false}dataSource={dataSource}renderRow={this.renderRow}renderHeader={this.renderHeader}/><Viewref={ref => this.navBar = ref}style={[styles.navBar, {opacity: 0}]}><NavPage title={'詳情頁'}/></View></View>)}
}const styles = StyleSheet.create({container: {flex: 1,backgroundColor: '#F5FCFF',},navBar: {height: 64,width: width,position: 'absolute',justifyContent: 'center',alignItems: 'center',backgroundColor: '#FA0016',},navContent: {marginTop: 20,height: 44,width: width,flexDirection: 'row',alignItems: 'center',justifyContent: 'space-between',paddingHorizontal: 15},searchBar: {justifyContent: 'center',paddingHorizontal: 10,borderTopLeftRadius: 12,borderBottomLeftRadius: 12,borderTopRightRadius: 12,borderBottomRightRadius: 12,flex: 1,height: 25,backgroundColor: 'white',marginHorizontal: 15}
})

?

紅色部分為核心代碼

?

參考:

https://github.com/guangqiang-liu/react-native-gradientNavigationBarDemo

?

本博客地址: wukong1688

本文原文地址:https://www.cnblogs.com/wukong1688/p/11020748.html

轉載請著名出處!謝謝~~

?

轉載于:https://www.cnblogs.com/wukong1688/p/11020748.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/393260.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393260.shtml
英文地址,請注明出處:http://en.pswp.cn/news/393260.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【CSS 技能提升】 :before和:after的使用

前幾天的晚上較全面的去看了下css的一些文檔和資料&#xff0c;大部分的樣式運用都沒什么大問題了&#xff0c;只是有些許較陌生&#xff0c;但是也知道他們的存在和實現的是什么樣式。今天主要想在這篇學習筆記中寫的也不多&#xff0c;主要是針對:before和:after寫一些內容&a…

c語言模擬java面向對象_純c語言實現面向對象分析與示例分享

#include #include //接口#ifndef Interface#define Interface struct#endif//類#ifndef Class#define Class struct#endif//抽象形狀類Class Shape;typedef Class Shape shape;//抽象形狀類的方法聲明shape* Shape(int edges);int shape_getEdges(shape *);int shape_getArea(…

leetcode152. 乘積最大子數組

給你一個整數數組 nums &#xff0c;請你找出數組中乘積最大的連續子數組&#xff08;該子數組中至少包含一個數字&#xff09;&#xff0c;并返回該子數組所對應的乘積。 示例 1: 輸入: [2,3,-2,4] 輸出: 6 解釋: 子數組 [2,3] 有最大乘積 6。 代碼 class Solution {publi…

成功試驗基于C#/.NET的Android開發

今天最開心事情莫過于摸索驗證了一個事情&#xff0c;C#也能進行Android和IOS開發&#xff0c;白天安裝了開發環境&#xff0c;晚上進行測試&#xff0c;直到此時此刻&#xff0c;已經成功的導出一款基于C#/.NET的安卓APK&#xff0c;并且能夠成功的導入到安卓手機運行&#xf…

使用機器學習預測天氣_如何使用機器學習根據文章標題預測喜歡和分享

使用機器學習預測天氣by Flavio H. FreitasFlavio H.Freitas著 如何使用機器學習根據文章標題預測喜歡和分享 (How to predict likes and shares based on your article’s title using Machine Learning) Choosing a good title for an article is an important step in the …

深入理解了MySQL,你才能說熟悉數據庫

先拋出幾個問題 1.為什么不建議使用訂單號作為主鍵?2.為什么要在需要排序的字段上加索引?3.for update 的記錄不存在會導致鎖住全表?4.redolog 和 binlog 有什么區別?5.MySQL 如何回滾一條 sql ?6.char(50) 和 varchar(50) 效果是一樣的么?索引知識回顧 對于 MySQL 數據庫…

ibatis mysql 自增_mybatis自增主鍵

簡單介紹&#xff1a;在使用mybats插入數據是&#xff0c;有很多需要和id關聯的其他數據&#xff0c;所以在插入一條信息時獲取其主鍵信息是很常見的操作。一 mysql數據庫的主鍵自增(int類型的主鍵)1 創建一個表&#xff0c;設置表的id(此id必須是int類型)&#xff0c;設置為au…

DataGridView控件用法二:常用屬性

通常會設置的DataGridView的屬性如下&#xff1a; AllowUserToAddRows - False指示是否向用戶顯示用于添加行的選項&#xff0c;列標題下面的一行空行將消失。一般讓其消失。AllowUserToDeleteRows - False指示是否允許用戶從DataGridView刪除行。一般不允許。AllowUserToOrder…

leetcode面試題 16.21. 交換和(二分查找)

給定兩個整數數組&#xff0c;請交換一對數值&#xff08;每個數組中取一個數值&#xff09;&#xff0c;使得兩個數組所有元素的和相等。 返回一個數組&#xff0c;第一個元素是第一個數組中要交換的元素&#xff0c;第二個元素是第二個數組中要交換的元素。若有多個答案&…

談談IP和MAC捆綁的破解之道

來源:[url]http://l-y.vicp.net[/url]我們學校最近將MAC和IP進行了捆綁&#xff0c;又在服務器&#xff08;2K&#xff09;上進行了上網時間的限制&#xff0c;真是煩死人了&#xff0c;我想我可是一個從不受限制的人啊&#xff0c;怎么可以就這樣束手就擒呢&#xff01;古話說…

如何在JavaScript中區分深層副本和淺層副本

by Lukas Gisder-Dub盧卡斯吉斯杜比(LukasGisder-Dub) 如何在JavaScript中區分深層副本和淺層副本 (How to differentiate between deep and shallow copies in JavaScript) New is always better!新總是更好&#xff01; You have most certainly dealt with copies in Java…

網站QQ全屏PHP代碼,QQ技術導航升級版 超級導航美化版帶后臺版 PHP源碼

QQ技術導航升級版 超級導航美化版帶后臺版改進F2樣式&#xff0c;主針對QQ教程網、卡盟、博客、提供更好收錄的位置。改進QQ技術導航背景&#xff0c;增加整體美觀效果。去掉死鏈頁面&#xff0c;站長操作使用更加有擴大空間。優化后臺登陸界面&#xff0c;去掉織夢后臺攜帶的廣…

MySQL基礎操作(一)

MySQL操作 一、創建數據庫 # utf-8 CREATE DATABASE 數據庫名稱 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;# gbk CREATE DATABASE 數據庫名稱 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; 二、用戶管理 創建用戶create user 用戶名IP地址 identified by 密碼; 刪…

集合框架05

一、HashSet集合 1 public class Demo01 {2 /*3 * Set接口&#xff0c;特點不重復元素&#xff0c;沒索引4 * Set接口的實現類&#xff0c;HashSet(哈希表)5 * 特點&#xff1a;無序集合&#xff0c;存儲和取出的順序不同&#xff0c;沒有索引&#xff0c;不…

leetcode1233. 刪除子文件夾

你是一位系統管理員&#xff0c;手里有一份文件夾列表 folder&#xff0c;你的任務是要刪除該列表中的所有 子文件夾&#xff0c;并以 任意順序 返回剩下的文件夾。 我們這樣定義「子文件夾」&#xff1a; 如果文件夾 folder[i] 位于另一個文件夾 folder[j] 下&#xff0c;那…

HIVE-分桶表的詳解和創建實例

我們學習一下分桶表&#xff0c;其實分區和分桶這兩個概念對于初學者來說是比較難理解的。但對于理解了的人來說&#xff0c;發現又是如此簡單。 我們先建立一個分桶表&#xff0c;并嘗試直接上傳一個數據 create table student4(sno int,sname string,sex string,sage int, sd…

51nod1270(dp)

題目鏈接&#xff1a;http://www.51nod.com/onlineJudge/questionCode.html#!problemId1270 題意&#xff1a;中文題誒&#xff5e; 思路&#xff1a;dp sabs(a1-a0)abs(a2-a1).... 要使s盡量大&#xff0c;需要讓abs(ai-ai-1)盡量大&#xff0c;那么可以讓其中一個盡量小&…

Windows IIS 日志分析研究(Log Parser Log Parser Lizard Log Parser Studio) update...

Windows主要有以下三類日志記錄系統事件&#xff1a;應用程序日志、系統日志和安全日志。 存放目錄&#xff1a;X:\Windows\System32\winevt\Logs\ System.evtx 系統日志 Application.evtx 應用程序日志 Security.evtx 安全日志 審核策略與事件查看器 # 管理工具 → 本地安全…

ios php ide,最好的PHP IDE for Mac? (最好免費!)

這里是PHP的Mac IDE的下降NetBeans自由&#xff01;此外&#xff0c;所有產品的最佳功能。包括內聯數據庫連接&#xff0c;代碼完成&#xff0c;語法檢查&#xff0c;顏色編碼&#xff0c;分割視圖等。下降&#xff1a;這是一個內存豬在Mac上。準備好允許一半的內存&#xff0c…

leetcode79. 24 點游戲

你有 4 張寫有 1 到 9 數字的牌。你需要判斷是否能通過 *&#xff0c;/&#xff0c;&#xff0c;-&#xff0c;(&#xff0c;) 的運算得到 24。 示例 1: 輸入: [4, 1, 8, 7] 輸出: True 解釋: (8-4) * (7-1) 24 代碼 class Solution {public boolean judgePoint24(int[] n…