11// @flow
22import React , { Component } from 'react' ;
33import PropTypes from 'prop-types' ;
4- import { Animated , ScrollView , StyleSheet , View , Platform } from 'react-native' ;
4+ import { Animated , ScrollView , StyleSheet , View , Image , Dimensions } from 'react-native' ;
55import type { ViewProps } from 'ViewPropTypes' ;
66import type { FlatList , SectionList , ListView } from 'react-native' ;
77
@@ -12,6 +12,19 @@ type ScrollViewProps = {
1212 scrollEventThrottle : number ,
1313} ;
1414
15+ type SourceObjectProps = {
16+ uri ?: ?string ,
17+ bundle ?: ?string ,
18+ method ?: ?string ,
19+ headers ?: ?{ [ string ] : string } ,
20+ body ?: ?string ,
21+ cache ?: ?( 'default' | 'reload' | 'force-cache' | 'only-if-cached' ) ,
22+ width ?: ?number ,
23+ height ?: ?number ,
24+ scale ?: ?number ,
25+ } ;
26+ type SourceProps = number | SourceObjectProps | SourceObjectProps [ ] ;
27+
1528export type Props = ScrollViewProps & {
1629 children ?: ?React$Element < any > ,
1730 childrenStyle ?: ?any ,
@@ -28,6 +41,7 @@ export type Props = ScrollViewProps & {
2841 renderTouchableFixedForeground ?: ?( ) => React$Element < any > ,
2942 ScrollViewComponent : React$ComponentType < ScrollViewProps > ,
3043 scrollViewBackgroundColor : string ,
44+ headerImage ?: ?SourceProps ,
3145} ;
3246
3347export type DefaultProps = {
@@ -94,6 +108,21 @@ class ImageHeaderScrollView extends Component<Props, State> {
94108 } ) ;
95109 }
96110
111+ renderHeaderProps ( ) {
112+ if ( this . props . headerImage ) {
113+ return (
114+ < Image
115+ source = { this . props . headerImage }
116+ style = { {
117+ height : this . props . maxHeight ,
118+ width : Dimensions . get ( 'window' ) . width ,
119+ } }
120+ />
121+ ) ;
122+ }
123+ return this . props . renderHeader ( ) ;
124+ }
125+
97126 renderHeader ( ) {
98127 const overlayOpacity = this . interpolateOnImageHeight ( [
99128 this . props . minOverlayOpacity ,
@@ -118,7 +147,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
118147
119148 return (
120149 < Animated . View style = { [ styles . header , headerTransformStyle ] } >
121- { this . props . renderHeader ( ) }
150+ { this . renderHeaderProps ( ) }
122151 < Animated . View style = { overlayStyle } />
123152 < View style = { styles . fixedForeground } > { this . props . renderFixedForeground ( ) } </ View >
124153 </ Animated . View >
0 commit comments