简体   繁体   English

如何在React Native中实现像CoordinatorLayout这样的东西?

[英]How to achieve something like CoordinatorLayout in React Native?

I want to achieve a behavior like android's CoordinatorLayout enter always for my ToolBar i tried too many solutions some did work but not fully like https://github.com/maolion/mao-rn-android-kit which is really cool but with one setback as it doesn't work with ListView i also tried Animated but the scroll event throttle on android is just not working most of the times it does not even work. 我想实现像android的CoordinatorLayout这样的行为总是为我的ToolBar输入我试过太多的解决方案一些确实有效但不完全像https://github.com/maolion/mao-rn-android-kit这真的很酷但是有一个因为它不能与ListView一起使用我也尝试过Animated但是android上的滚动事件限制只是在大多数情况下都不起作用它甚至都不起作用。

Using mao-rn-android-kit 使用mao-rn-android-kit

<CoordinatorLayoutAndroid ref={(component) => this.coordinatorLayout = component} fitsSystemWindows={false}>
    <AppBarLayoutAndroid
        layoutParams={{
                            width: 'match_parent',
                            height: 112
                        }}
        style={{ backgroundColor:"#528eff" }}>
        <View layoutParams={{height: 56, width: this.windowWidth, scrollFlags: (
                                    AppBarLayoutAndroid.SCROLL_FLAG_SCROLL |
                                    AppBarLayoutAndroid.SCROLL_FLAG_ENTRY_ALWAYS)}} style={{height: 56}}>
            <ToolbarAndroid
                titleColor={'#FFF'}
                title={this.props.title}
                navIcon={images.arrowBack}
                onIconClicked={() => this._goBack()}
                onActionSelected={() => {}}
                actions={[{title: 'Search', icon: images.search, show: 'always'}]}
                style={[{backgroundColor: '#528eff', width: this.windowWidth, height: 56}]}/>
        </View>
        <View layoutParams={{height: 56, width: this.windowWidth}}
              style={{flex: 0, flexDirection: 'row', justifyContent: 'center', width: this.windowWidth, backgroundColor: '#528eff'}}>
            <TouchableOpacity onPress={() => this.getDocuments('high')}
                              style={[styles.highNormalLowDocListHeaderStateTextContainer, highSelected.borderStyle]}>
                <Text
                    style={[styles.highNormalLowDocListHeaderStateText, highSelected.textStyle]}>HIGH</Text>
            </TouchableOpacity>
            <TouchableOpacity onPress={() => this.getDocuments('normal')}
                              style={[styles.highNormalLowDocListHeaderStateTextContainer, normalSelected.borderStyle]}>
                <Text
                    style={[styles.highNormalLowDocListHeaderStateText, normalSelected.textStyle]}>NORMAL</Text>
            </TouchableOpacity>
            <TouchableOpacity onPress={() => this.getDocuments('low')}
                              style={[styles.highNormalLowDocListHeaderStateTextContainer, lowSelected.borderStyle]}>
                <Text
                    style={[styles.highNormalLowDocListHeaderStateText, lowSelected.textStyle]}>LOW</Text>
            </TouchableOpacity>
        </View>
    </AppBarLayoutAndroid>
    <View
        ref={(component) => this.contentLayout = component}
        style={{flex: 1, backgroundColor: 'transparent', height: this.windowHeight - 150}}>
        <ListView
            style={{height: this.windowHeight - 150, overflow: 'hidden'}}
            dataSource={this.state.documents}
            enableEmptySections={true}
            renderRow={(rowData) => this._renderRow(rowData)}
        />
    </View>
</CoordinatorLayoutAndroid>

The key to reacting to the scroll position fluidly is using Animated.event along with the onScroll to update an Animated.value 流畅地onScroll滚动位置的关键是使用Animated.eventonScroll来更新Animated.value

getInitialState: function() {
    return {
        scrollY: new Animated.Value(0)
    }
},
render() {
    return (
         <ScrollView
             scrollEventThrottle={16}
             onScroll={Animated.event(
                            [{nativeEvent: 
                               {contentOffset: 
                                 {y: this.state.scrollY}
                               }
                            }]
              )}>
    // etc ...
}

I could then call interpolate on this.state.scrollY and feed this value into a transform style on another component that I wanted to update as the ScrollView scrolled. 然后,我可以在this.state.scrollY上调用interpolate ,并将此值提供给另一个组件上的transform样式,我想在ScrollView滚动时更新该组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在CoordinatorLayout中实现重叠? - How to achieve overlapping in CoordinatorLayout? 如何使用React Native实现这种效果? - How to achieve this effect with React Native? iOS上的RCTBridge React Native有没有像Android上的React Native那样? - Is there something like the RCTBridge React Native on iOS has but for React Native on Android? 如何在React Native中实现&#39;FrameLayout&#39;组件? - How to achieve 'FrameLayout' component in React Native? 我如何在 Android 中实现类似垂直 ViewPager 的功能? - How can i achieve something like a vertical ViewPager in Android? 如何在android中实现类似on_hover的css? - How to achieve in android something like on_hover in css? 如何在android中的非活动类中实现类似“完成”的东西? - how to achieve something like “finish” in a non-activity class in android? CoordinatorLayout和BottomSheetBehavior的react-native包装器 - react-native wrapper for CoordinatorLayout and BottomSheetBehavior React Native:如何实现诸如高度:自动之类的东西,以便图像在宽度上覆盖视图但不拉伸 - React Native: How to implement something like height: auto so that the image covers the view in width but doesn't stretch 如何在if语句中呈现内容React Native - How to render something in an if statement React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM