Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-app inspector throws error when assigning percentage strings to padding(like this --> padding: '10%'), although it works in the UI. #17496

Closed
shubhnik opened this issue Jan 9, 2018 · 14 comments
Labels
Bug Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Resolution: Locked This issue was locked by the bot. Resolution: PR Submitted A pull request with a fix has been provided.

Comments

@shubhnik
Copy link

shubhnik commented Jan 9, 2018

Is this a bug report?

YES

Have you read the Contributing Guidelines?

YES

Environment

Environment:
OS: macOS Sierra 10.12
Node: 7.5.0
Yarn: 0.20.3
npm: 5.4.2
Watchman: 4.7.0
Xcode: Xcode 8.3.1 Build version 8E1000a
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: 0.52.0 => 0.52.0

Target Platform: iOS (10.3)

Steps to Reproduce

  1. Use padding with percentage string as: padding: '10%'.
  2. Now open the inspector using in-app developer menu and tap on the element with the given padding
  3. The inspector will error out saying that padding should be a number instead of a string, although padding as a string works in the UI.

Expected Behavior

The inspector shouldn't have thrown an error. It should have work the same way if I have given a padding as a number.

Actual Behavior

React-Native supports padding using percentage strings but the inspector is throwing error that the padding should be a number rather than a string.
simulator screen shot jan 9 2018 10 23 25 am

Reproducible Demo

I have added a padding as a string in this app.js file. Just replace the default app.js file with this one.

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View
} from 'react-native';

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',
});

export default class App extends Component<{}> {
  render() {
    return (
      <View style={styles.container}>
        <View style={{backgroundColor: 'red', flex: 1}}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding:'10%',
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

PR opportunity

I think it is a good first bug. I would love to send a PR for this.

Thank You 😄

@dereknelson
Copy link

+1 this issue occurs when using StyleSheet and ExtendedStyleSheet

@react-native-bot

This comment has been minimized.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon. labels Feb 24, 2018
@hramos
Copy link
Contributor

hramos commented Feb 24, 2018

Re-opening because 0.52 was the latest on Jan 9.

@hramos hramos reopened this Feb 24, 2018
@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 24, 2018
@hramos hramos removed the Ran Commands One of our bots successfully processed a command. label Mar 5, 2018
@WoodyWoodsta
Copy link

How has this not received any attention? I've read multiple issues describing the same behaviour, yet they keep on being closed because they become 'stale'.

@FlaviooLima
Copy link

Can confirm this happening in React Native version 0.53.3 and 0.55.3

@react-native-bot

This comment has been minimized.

@hramos hramos added Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. and removed ⏪Old Version labels Jul 18, 2018
@ggtmtmgg
Copy link
Contributor

I confirmed this is NOT happened in iOS with React Native version 0.56.0.
screen shot 2018-07-28 at 14 42 26

@shubhnik
Copy link
Author

shubhnik commented Aug 3, 2018

@ggtmtmgg the layout is rendered correctly but error is thrown when you inspect through the react-native inspector.

@micimize
Copy link

Ran into this issue with margin: 'auto'. In a nutshell, Libraries/Inspector/ElementBox.js can't handle string values like % and auto for padding and margin. More specifically:
Libraries/Inspector/resolveBoxStyle.js does not handle string values
ElementBox passes the results to BorderBox.js to be rendered as borderWidth${x} styles and thus throw an error
ElementBox also computes width/height of content with them, which would also throw an error

Digging deeper, getting the actual content size actually seems fairly involved. Still, I think this should be a much higher priority issue than it is being treated as.

@micimize
Copy link

for now I monkey patched the offending code to avoid the errors

@gandreadis
Copy link

@hramos I'm interested in helping out with fixing this, but I'm a bit stuck on how to debug the inspector. I'd like to run the CLI with the modified version of the library. I've tried copying over the relevant parts (resulting in package declaration clashes), and I've also tried importing the Inspector.js file from the modified RN codebase from within a test project (resulting in a module not resolved error). Do you have any suggestions?

@ericlewis
Copy link
Contributor

@gandreadis the easiest way to debug this would be to use the RNTester app, and edit in the repo directly.

@gandreadis
Copy link

@ericlewis Thanks for the suggestion, that's exactly what I needed! I'll have a look.

@gandreadis
Copy link

I've submitted a fix for this at #23804, let me know if you have any feedback!

@hramos hramos added the Resolution: PR Submitted A pull request with a fix has been provided. label Mar 7, 2019
grabbou pushed a commit that referenced this issue May 6, 2019
Summary:
Currently, when relative sizes are given in margin or padding stylings (be it a percentage or an auto measure), the inspector crashes, due to frame rendering not properly handling those kinds of measurements. This PR adds a resolution step for them:

* Percentages are evaluated relative to the window size.
* I decided to simply not render `auto` margins/paddings, due to the complexities involved (e.g. when the margin is between multiple elements with relative sizes).

Since the inspector does not crash anymore on relative sizes on paddings or margins, I believe that this addresses #17496.

Fixes #17496

[General] [Fixed] - Fix inspector rendering of relative margins and paddings
Pull Request resolved: #23804

Differential Revision: D14437273

Pulled By: cpojer

fbshipit-source-id: c9f0f71a2e1b2399a2b2148cef2124787703ead3
@facebook facebook locked as resolved and limited conversation to collaborators Mar 13, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Resolution: Locked This issue was locked by the bot. Resolution: PR Submitted A pull request with a fix has been provided.
Projects
None yet
Development

No branches or pull requests

10 participants