1
1
// @flow
2
2
import React , { Component } from 'react' ;
3
3
import 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' ;
5
5
import type { ViewProps } from 'ViewPropTypes' ;
6
6
import type { FlatList , SectionList , ListView } from 'react-native' ;
7
7
@@ -12,6 +12,19 @@ type ScrollViewProps = {
12
12
scrollEventThrottle : number ,
13
13
} ;
14
14
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
+
15
28
export type Props = ScrollViewProps & {
16
29
children ?: ?React$Element < any > ,
17
30
childrenStyle ?: ?any ,
@@ -28,6 +41,7 @@ export type Props = ScrollViewProps & {
28
41
renderTouchableFixedForeground ?: ?( ) => React$Element < any > ,
29
42
ScrollViewComponent : React$ComponentType < ScrollViewProps > ,
30
43
scrollViewBackgroundColor : string ,
44
+ headerImage ?: ?SourceProps ,
31
45
} ;
32
46
33
47
export type DefaultProps = {
@@ -94,6 +108,21 @@ class ImageHeaderScrollView extends Component<Props, State> {
94
108
} ) ;
95
109
}
96
110
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
+
97
126
renderHeader ( ) {
98
127
const overlayOpacity = this . interpolateOnImageHeight ( [
99
128
this . props . minOverlayOpacity ,
@@ -118,7 +147,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
118
147
119
148
return (
120
149
< Animated . View style = { [ styles . header , headerTransformStyle ] } >
121
- { this . props . renderHeader ( ) }
150
+ { this . renderHeaderProps ( ) }
122
151
< Animated . View style = { overlayStyle } />
123
152
< View style = { styles . fixedForeground } > { this . props . renderFixedForeground ( ) } </ View >
124
153
</ Animated . View >
0 commit comments