Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visibility hidden on react native not working, to take space even not shown?

Tags:

react-native

I have TouchableOpacity in a space between flex container that I want to take space even not shown,

My code:

<TouchableOpacity
  style={showClear && { visibility: 'hidden' }}
  onPress={() => this.props.clearCompleted()}>
  <Text>Clear Completed</Text>
</TouchableOpacity>

display: none works but it doesn't take space, the code above dont work but does in web?

like image 568
gpbaculio Avatar asked Mar 04 '19 03:03

gpbaculio


People also ask

How do I show hidden view in react native?

Custom HideableView Component import React from 'react'; import PropTypes from 'prop-types'; import { View } from 'react-native'; const HideableView = (props) => { const { children, hide, style } = props; if (hide) { return null; } return (<View {... this. props} style={style}>{ children }</View>); }; HideableView.

How do I display none in react native?

Is there a display none equivalent in React Native? There is no direct equivalent of display none in React Native - this is because React Native shows and hides elements based on your application state. So rather than setting an elements visibility directly, you would show or hide an element based on a state value.

How do I delete a view in react native?

import React, { Component } from 'react' import { AppRegistry, View, Text, TouchAbleOpacity } from 'react-native' class Example extends Component { removeView(){ // what should I do here? } render(){ return ( <View> <View> // View to be removed <TouchAbleOpacity onPress={() => this.


2 Answers

In my case, I needed to use the element, so I did something like this:

<TextInput style={{opacity: 0, height: 0}} {...props} />

I hope this works for someone else with my problem.

like image 108
Oriana Ruiz Avatar answered Sep 16 '22 21:09

Oriana Ruiz


Update


React Native's StyleSheet now supports toggling visibility using display: 'none' and display:flex.


Not all CSS are supported in React Native, that include visibility: hidden or display:none.

To hide a component, not to render it at all, render empty View or null. Or you want to switch a component visibility, verify react's state



<View>
   { !showClear && (
      <TouchableOpacity
         onPress={() => this.props.clearCompleted()}>
         <Text>Clear Completed</Text>
      </TouchableOpacity>
   }
</View>

showClear is kept in state

like image 27
Ponleu Avatar answered Sep 18 '22 21:09

Ponleu