android - 如何在 React Native 应用程序中添加圆形底部可折叠工具栏?

标签 android react-native

我希望在 react-native 应用程序的工具栏中添加一个圆形底部,如下图所示。

enter image description here

我如何在应用程序中实现它?

最佳答案

这是工作示例。希望这有帮助

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  Dimensions,
  Image,
  FlatList,
  AsyncStorage
} from 'react-native';

const window = Dimensions.get('window');

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

var localizedString;

type Props = {};
export default class App extends Component<Props> {

constructor(Props){
    super(Props);
    this.state={
      collapse: false
    };
  this.collapseEnable =this.collapseEnable.bind(this);
  this.collapseDisable =this.collapseDisable.bind(this);
  }

collapseEnable(){
  this.setState({
    collapse:true
  })
}

collapseDisable(){
  this.setState({
    collapse:false
  })
}

render() {
    return (
      <View style={{ flex: 1 }}>
        {(this.state.collapse==false)?
          <TouchableOpacity style={{height:40, backgroundColor:'pink', alignItems:'center', justifyContent:'center'}} onPress={()=>{this.collapseEnable()}}>
            <Text style={{fontSize:20}}>Click here</Text>
          </TouchableOpacity>
           :
          <TouchableOpacity style={styles.container} onPress={()=>{this.collapseDisable()}}>
            <View style={styles.background} >

            </View>
          </TouchableOpacity>
        } 
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  container: {
    alignSelf: 'center',
    justifyContent:'center',
    width: '100%',
    overflow: 'hidden', // for hide the not important parts from circle
    height: 100
  },
  background: { // this shape is a circle 
    borderRadius: 800, // border borderRadius same as width and height
    width: '200%',
    height: 800,
    marginLeft: -200, // reposition the circle inside parent view
    position: 'absolute',
    bottom: 0, // show the bottom part of circle
    overflow: 'hidden',
    backgroundColor:'pink' // hide not important part of image
  },
});

关于android - 如何在 React Native 应用程序中添加圆形底部可折叠工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50576588/

相关文章:

java - 我无法创建 JSONObject 的实例

javascript - React Native 最新版本 0.61.4 出现导航错误

javascript - 如何在React Native中获取圆弧的质心?

android - 使用 Android Studio 的 React-Native

java - 如何从 java 或 Android 中的字符串制作 XML 文档?

android - Android模拟器调试报错: black screen

ios - 已选择和未选择状态的 react 导航中的不同 tabBar 图标?

javascript - React Native 使用钩子(Hook)从 API 加载数据

android - 在 android 中为 NanoHttpd 设置 CORS

java - 自动顺序显示图像