React Native 如何实现容器上下等距裁切 保留中间完整显示区
项目需求与现存问题
- 正在开发Reels类短视频应用,交互设计方向为引导用户注意力聚焦在界面中间的水平显示区域
- 当前容器裁切效果不对称:仅能对底部卷轴面板实现符合预期的部分裁切,但顶部面板完整裸露、未被裁切
- 期望效果:实现上下边缘等距裁切,仅让中间显示区域完整、清晰地展示内容
- 调试卡点:调整
slotsContainer的flex值时,仅会带动底部元素向上收缩,无法实现上下对称裁切的效果
相关实现代码
import React, {useRef} from 'react'; import {View, StyleSheet, Button, Text} from 'react-native'; import ReelGroup from '../Slots/ReelGroup'; // 在函数组件中借助ReelGroup的Spin能力实现滚动功能 export default function RandomStockScreen(props) { const reelGroup = useRef(); return ( <View style={styles.container}> <Text style={styles.titleText}>Myster Stock</Text> <View style={styles.slotsContainer}> <ReelGroup ref={reelGroup} /> </View> <View style={styles.buttonContainer}> <Button title="New Stock" onPress={() => reelGroup.current.spin()} /> </View> </View> ); } const styles = StyleSheet.create({ titleText: { color: 'white', fontSize: 20, fontWeight: 'bold', marginTop: '10%', textAlign: 'center', }, container: { flex: 1, backgroundColor: 'black', }, slotsContainer: { flex: 0.9, marginHorizontal: '3%', justifyContent: 'center', backgroundColor: 'grey', }, buttonContainer: { flex: 0.1, backgroundColor: 'blue', marginTop: '1%', marginHorizontal: '3%', textAlign: 'center', justifyContent: 'center', }, });
内容的提问来源于stack exchange,提问作者Andrew
相关产品推荐
相关产品推荐

