Repository navigation
Expand file tree
/
Copy pathContainer.js
More file actions
executable file
·145 lines (132 loc) · 3.86 KB
/
Copy pathContainer.js
File metadata and controls
executable file
·145 lines (132 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Copyright © SuperMap. All rights reserved.
Author: Yang Shanglong
E-mail: yangshanglong@supermap.com
*/
import React, { PureComponent } from 'react'
import { View, ScrollView, Animated, StatusBar } from 'react-native'
import Header from '../Header'
import Loading from './Loading'
import { scaleSize } from '../../utils'
import { Const } from '../../constants'
import styles from './styles'
const AnimatedView = Animated.View
export default class Container extends PureComponent {
props: {
style?: StyleSheet,
titleStyle?: StyleSheet,
children: any,
title: string,
header: any,
bottomBar: any,
withoutHeader: boolean,
headerProps: Object,
bottomProps: Object,
navigation: Object,
initWithLoading: boolean,
dialogInfo: boolean,
scrollable: boolean,
}
static defaultProps = {
withoutHeader: false,
sideMenu: false,
initWithLoading: false,
scrollable: false,
}
constructor(props) {
super(props)
this.state = {
top: new Animated.Value(0),
bottom: new Animated.Value(0),
}
this.headerVisible = true
this.bottomVisible = true
}
setHeaderVisible = (visible, immediately = false) => {
if (this.props.header) {
if (this.headerVisible === visible) return
Animated.timing(this.state.top, {
toValue: visible ? 0 : scaleSize(-200),
duration: immediately ? 0 : Const.ANIMATED_DURATION,
}).start()
this.headerVisible = visible
} else {
this.containerHeader && this.containerHeader.setVisible(visible)
}
}
setBottomVisible = (visible, immediately = false) => {
if (this.bottomVisible === visible) return
Animated.timing(this.state.bottom, {
toValue: visible ? 0 : scaleSize(-200),
duration: immediately ? 0 : Const.ANIMATED_DURATION,
}).start()
this.bottomVisible = visible
}
componentDidMount() {
this.props.initWithLoading && this.setLoading(true)
}
setLoading = (loading, info, extra = {}) => {
this.loading.setLoading(loading, info, extra)
}
renderHeader = fixHeader => {
return this.props.withoutHeader ? (
<View style={styles.iOSPadding} />
) : this.props.header ? (
<AnimatedView
style={[fixHeader && styles.fixHeader, { top: this.state.top }]}
>
{this.props.header}
</AnimatedView>
) : (
<Header
ref={ref => (this.containerHeader = ref)}
navigation={this.props.navigation}
{...this.props.headerProps}
/>
)
}
renderBottom = () => {
if (!this.props.bottomBar) return null
let style = []
if (this.props.bottomProps) {
if (this.props.bottomProps.type === 'fix') {
style.push(styles.fixBottomBar)
} else {
style.push(styles.flexBottomBar)
}
if (this.props.bottomProps.style) {
style.push(this.props.bottomProps.style)
}
} else {
style.push(styles.flexBottomBar)
}
return (
<AnimatedView style={[style, { bottom: this.state.bottom }]}>
{this.props.bottomBar}
</AnimatedView>
)
}
render() {
let ContainerView = this.props.scrollable ? ScrollView : View
// 是否为flex布局的header
let fixHeader =
this.props.headerProps && this.props.headerProps.type === 'fix'
return (
<View style={{ flex: 1 }}>
<StatusBar animated={true} hidden={false} />
<ContainerView style={[styles.container, this.props.style]}>
{!fixHeader && this.renderHeader(fixHeader)}
{/*<View style={{ flex: 1 }}>{this.props.children}</View>*/}
{this.props.children}
{fixHeader && this.renderHeader(fixHeader)}
{this.renderBottom()}
<Loading
ref={ref => (this.loading = ref)}
info={this.props.dialogInfo}
initLoading={this.props.initWithLoading}
/>
</ContainerView>
</View>
)
}
}