好吧,所以我无法单独通过造型来实现它,但我是这样做的:
- 渲染后测量页脚的高度(使用
onLayout
和measure
)
- 在
measure
回调中,我将高度(如果需要)添加到ViewA和ViewB之间的间隔视图中,以便将ViewB放置在底部.
- 为了避免向用户显示" skip ",我隐藏(不透明度)ViewB,直到其位置固定.
我的CJSX代码(精简版):
Dimensions = require('Dimensions')
windowSize = Dimensions.get('window')
MyClass = React.createClass
mixins: [TimerMixin]
render: ->
<ScrollView style={styles.container} automaticallyAdjustContentInsets={false}>
<View style={styles.mainContainer}>
... THIS IS VIEW A ...
</View>
{
if !@state.footerWasFixed
<View>
<ActivityIndicatorIOS/>
</View>
}
<View style={[styles.spacer, {height: @state.spacerSize || 0}]}></View>
<View onLayout={@measureFooterPosition} style={[styles.extras, {opacity: if @state.footerWasFixed then 1 else 0 }]} ref='extras'>
... THIS IS VIEW B ...
</View>
</ScrollView>
measureFooterPosition: ->
@refs.extras.measure(@fixFooterPosition)
fixFooterPosition: (ox, oy, width, height) ->
footerPosition = Math.round(oy + height)
diff = windowSize.height - footerPosition
if diff > 0
@setState(spacerSize: diff)
if !@state.footerWasFixed
@setTimeout (=>
@setState(footerWasFixed: true)
), 30
styles = StyleSheet.create(
container:
backgroundColor: 'grey'
flex: 1
spacer:
backgroundColor: 'white'
mainContainer:
flex: 1
backgroundColor: 'white'
extras:
backgroundColor: 'white')
这是一个非常简单的代码(我的观点要求比这更具体)但我希望它能帮助任何人.