react-native 滚动头部置顶

前端之家收集整理的这篇文章主要介绍了react-native 滚动头部置顶前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

/**
* Create by lutn on 2018-04-17
*
*/
'use strict';

import React,{ Component } from 'react'
import {
Text,
View,
BackHandler,
ScrollView,
StyleSheet,
AlertIOS,
RefreshControl,
TouchableOpacity,
Image,
TextInput,
Platform,
Dimensions,
ActivityIndicator,
Animated
} from 'react-native'
import px2dp from '../../utils/Px2dp'

const isIOS = Platform. OS == "ios"
const { width,height } = Dimensions. get( 'window')
const headH = px2dp( isIOS? @H_404_148@140: @H_404_148@120)
const InputHeight = px2dp( @H_404_148@28)

export default class HomePage3 extends Component {
constructor( props){
super( props)
this. state = {
location: "三里屯SOHO",
scrollY: new Animated. Value( @H_404_148@0),
searchView: new Animated. Value( @H_404_148@0),
modalVisible: false,
searchBtnShow: true,
isRefreshing: false
}

this. SEARCH_Box_Y = px2dp( isIOS? @H_404_148@48: @H_404_148@43)
this. SEARCH_FIX_Y = headH- px2dp( isIOS? @H_404_148@64: @H_404_148@44)
this. SEARCH_KEY_P = px2dp( @H_404_148@58)
this. SEARCH_DIFF_Y = this. SEARCH_FIX_Y- this. SEARCH_Box_Y
}
componentDidMount(){

BackHandler. addEventListener( 'hardwareBackPress',function () {
BackHandler. exitApp( @H_404_148@0)
return true
})
}
_renderHeader(){
let searchY = this. state. scrollY. interpolate({
inputRange: [ @H_404_148@0,this. SEARCH_Box_Y,this. SEARCH_FIX_Y,this. SEARCH_FIX_Y],
outputRange: [ @H_404_148@0,@H_404_148@0,this. SEARCH_DIFF_Y,this. SEARCH_DIFF_Y]
})
let lbsOpaticy = this. state. scrollY. interpolate({
inputRange: [ @H_404_148@0,this. SEARCH_Box_Y],
outputRange: [ @H_404_148@1,@H_404_148@0]
})
let keyOpaticy = this. state. scrollY. interpolate({
inputRange: [ @H_404_148@0,this. SEARCH_KEY_P],@H_404_148@1,@H_404_148@0]
})
return (
< View style= { styles. header } >
< Animated.View style= {[ styles. lbsWeather,{ opacity: lbsOpaticy}] } >
< Text ></ Text >
</ Animated.View >
< Animated.View style= {{
marginTop: px2dp( @H_404_148@15),
transform: [{
translateY: searchY
}]} } >
< Text ></ Text >
</ Animated.View >
< Animated.View style= {[ styles. keywords,{ opacity: keyOpaticy}] } >
< Text ></ Text >
</ Animated.View >
</ View >
)
}
_renderFixHeader(){
let showY = this. state. scrollY. interpolate({
inputRange: [ @H_404_148@0,
outputRange: [- @H_404_148@9999,- @H_404_148@9999,@H_404_148@0]
})
return (
< Animated.View style= {[ styles. header,{
position: "absolute",
left: @H_404_148@0,
right: @H_404_148@0,
top: @H_404_148@0,
bottom: @H_404_148@0,
height: px2dp( isIOS? @H_404_148@64: @H_404_148@44),
paddingTop: px2dp( isIOS? @H_404_148@25: @H_404_148@10),
transform: [
{ translateY: showY}
]
}] } >
< Text ></ Text >
</ Animated.View >
)
}

_onRefresh(){
this. setState({ isRefreshing: true});
setTimeout(() => {
this. setState({ isRefreshing: false});
},@H_404_148@2000)
}
render(){
return (
< View style= {{ flex: @H_404_148@1,backgroundColor: "#f3f3f3"} } >
< ScrollView
onScroll= { Animated. event(
[{ nativeEvent: { contentOffset: { y: this. state. scrollY}}}]
) }
scrollEventThrottle= { @H_404_148@16 }
refreshControl= {
< RefreshControl
refreshing= {this. state. isRefreshing }
onRefresh= {this. _onRefresh. bind( this) }
colors= {[ '#ddd','#0398ff'] }
progressBackgroundColor= "#ffffff"
/>
}
>
{this. _renderHeader() }
< View style= {{ backgroundColor: "#fff",paddingBottom: @H_404_148@10} } >
< Text ></ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >

< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >

< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >

< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >

< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >sdlkfsdklsfkldflskdsdlkkds </ Text >
< Text >底部 </ Text >
</ View >
</ ScrollView >
{this. _renderFixHeader() }
</ View >
)
}
}

const styles = StyleSheet. create({
header: {
backgroundColor: "#0398ff",
height: headH,
paddingTop: px2dp( isIOS? @H_404_148@30: @H_404_148@10),
paddingHorizontal: @H_404_148@16
},

lbsWeather: {
height: InputHeight,
overflow: "hidden",
flexDirection: "row",
justifyContent: "space-between"
},



keywords: {
marginTop: px2dp( @H_404_148@14),
flexDirection: "row"
},
})


'use strict';
import { Dimensions} from 'react-native'
const deviceH = Dimensions. get( 'window'). height
const deviceW = Dimensions. get( 'window'). width
const basePx = @H_404_148@375
export default function px2dp( px) {
return px * deviceW / basePx
}
原文链接:https://www.f2er.com/react/301460.html

猜你在找的React相关文章