How can I do two overlapped rounded buttons on react native?

react native elements overlay example
react native overlay z-index
react-native-modal-overlay
react-native-elements overlay not working
react native overlay animation
react native slider
react-native overlay npm
react native text

How can I create this kind of buttons on react native? I know that I can create buttons with rounded corners but using the border radius, but what about the overlap?

You should use absolute positioning. Have a look at the snap I prepared for you:

https://snack.expo.io/r1tw8M6iQ

Be careful, the absolute positioning in RNT isn't the same it is in CSS. Have a look at the documentation here: https://facebook.github.io/react-native/docs/layout-props#position

Managing Z-Index In A Component-Based Web Application , to handle user's events. Two use either TouchableHighlight or TouchableNativeFeedback or TouchableOpacity or TouchableWithoutFeedback . In this post, I will show you how to place two buttons side by side in react native. We will create one new component for button. React native project : Let’s create one starter react native project. Create one new file CButton.js with the below code :

Another approach to @Lukasz's answer would be using relative positioning. Since absolute positioning is hard to set for all different screen sizes I prefer using relative positioning with negative left/right value. This let me set my container with flex like the rest of the app.

Sample (Modfied from the @Lukasz's snack) https://snack.expo.io/@bennygenel/cm91bm

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <TouchableOpacity style={[styles.round, styles.red]}>
          <Text>BTN1</Text>
        </TouchableOpacity>
        <TouchableOpacity style={[styles.round, styles.green]}>
          <Text>BTN1</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
  },
  red: {
    backgroundColor: 'red',
    zIndex: 2
  },

  green: {
    backgroundColor: 'green',
    position: 'relative',
    borderTopLeftRadius: 0,
    borderBottomLeftRadius: 0,
    left: -22
  },

  round: {
    justifyContent: 'center',
    alignItems: 'center',
    width: 100,
    height: 50,
    borderRadius: 50
  }
});

How do I make an image round in react native? By default buttons created in react native application is in rectangle shape and dose not support rounded corners. So in this tutorial we would going to make a Rounded Corners Button in react native app using TouchableOpacity . TouchableOpacity component is used to wrap a view which can respond on button click events. So let’s get started .

Based on the other answers, you can also get the selection login here: https://snack.expo.io/@xavier96/rounded-ovelaying-buttons

export default class App extends React.Component {

  state = {
    btn1Selected: true,
    btn2Selected: false,
  }

  render() {
    const { btn1Selected, btn2Selected } = this.state;
    return (
      <View style={styles.container}>
          <TouchableOpacity
            style={[styles.round, styles.first, styles.inferiorIndex, btn1Selected && styles.superiorIndex, btn2Selected && styles.borderRightRadius]}
            onPress={() => this.setState({btn1Selected: true, btn2Selected: false})}
           >
             <Text>BTN1</Text>
           </TouchableOpacity>
           <TouchableOpacity 
             style={[styles.round, styles.second, styles.inferiorIndex, btn2Selected && styles.superiorIndex]}
             onPress={() => this.setState({btn1Selected: false, btn2Selected: true})}
           >
             <Text>BTN2</Text>
           </TouchableOpacity>
      </View>
   );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
  },
  first: {
    backgroundColor: 'grey',
    zIndex: 1
  },

  second: {
    backgroundColor: 'grey',
    position: 'relative',
    borderTopLeftRadius: 0,
    borderBottomLeftRadius: 0,
    left: -22,
    zIndex: 0
  },

  round: {
    justifyContent: 'center',
    alignItems: 'center',
    width: 100,
    height: 50,
    borderRadius: 50
  },

  superiorIndex: {
    zIndex: 2,
    borderTopLeftRadius: 50,
    borderBottomLeftRadius: 50,
    backgroundColor: 'red'
  },

  inferiorIndex: {
    zIndex: 1,
  },

  borderRightRadius: {
    borderTopRightRadius: 0,
    borderBottomRightRadius: 0,
  }
});

coordinate of an element (also called its “stacking order”): the larger the value, the closer the element is to the observer. The round shape also known as Circle is used to create Round buttons in react native application if you create creating any type of animation in your app. So in this example we would going to create Circle Round Oval Shape View in React native android iOS application using custom Style.CSS classes.

The Overlay is a view that floats above an app's content. import React, { useState } from 'react'; import { Button, Overlay } from 'react-native-elements'; const  This defines how far your touch can start away from the button. This is added to pressRetentionOffset when moving off of the button. ** NOTE ** The touch area never extends past the parent view bounds and the Z-index of sibling views always takes precedence if a touch hits two overlapping views.

I built a simple React Native application that includes round buttons. The design includes 1 large round button and 2 smaller ones nested in the corners. This is fine in smaller buttons where the entire element is a This overlap will register big button clicks, when small button clicks are intended. A basic button component that should render nicely on any platform. Supports a minimal level of customization. If this button doesn't look right for your app, you can build your own button using TouchableOpacity or TouchableNativeFeedback. For inspiration, look at the source code for this button component.

Here is a post on how to create a round button: Round Buttons in React Native React Native circular button with gradient border We will create 2 circles, one on top of the other. The circle in the foreground will be a solid color that will overlap the gradient one, except for on the edges, allowing the  React Native provides a Button component that has a nice look on all platforms and provides touch events for common gestures like tapping.. In case, the Button component is not enough for your app in terms of look and customizations, you can also build your own custom button using any the base components (TouchableOpacity, TouchableHighlight and TouchableNativeFeedback) provided by React Native.

Comments
  • did you try absolute positioning?