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

onLayout not triggered or even crash the app #478

Closed
F4b1n0u opened this issue Aug 9, 2017 · 8 comments
Closed

onLayout not triggered or even crash the app #478

F4b1n0u opened this issue Aug 9, 2017 · 8 comments
Assignees
Labels
needs more info To be used when awaiting reporter response

Comments

@F4b1n0u
Copy link

F4b1n0u commented Aug 9, 2017

Hi guys,
I just create a project from expo XDE
and added

onLayout={(event) => {console.log('event:', event)}}

on the View, it is never triggered ...

I added as well on the Text, it crashed Expo client app

is someone have an idea ?

here is the App.js

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

export default class App extends React.Component {
  render() {
    return (
      <View
        style={styles.container}
        onLayout={(event) => {console.log('event:', event)}}
      >
        <Text
          onLayout={(event) => {console.log('event:', event)}}
        >Open up App.js to start working on your app!</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

and the generated package.json

{
  "name": "my-new-project",
  "version": "0.0.0",
  "description": "Hello Expo!",
  "author": null,
  "private": true,
  "main": "node_modules/expo/AppEntry.js",
  "dependencies": {
    "expo": "^19.0.0",
    "react": "16.0.0-alpha.12",
    "react-native": "https://github.com/expo/react-native/archive/sdk-19.0.0.tar.gz"
  }
}
@ide
Copy link
Member

ide commented Aug 9, 2017

The problem may be that the event object has fields that are cyclic or otherwise unserializable. Try logging event.nativeEvent (which is the ViewLayout object) instead.

@w-
Copy link

w- commented Aug 15, 2017

I also ran into this also and spent a lot of time trying to uncover the root cause.
https://forums.expo.io/t/genymotion-suddenly-constantly-crashing/2312/

@ide is this issue specific to xde? i.e. does xde implement a custom console.log?

@ide
Copy link
Member

ide commented Aug 15, 2017

XDE does implement custom.console log since it has to move data from your phone to your computer. It uses pretty-format (https://github.com/facebook/jest/tree/master/packages/pretty-format) to serialize the data.

@w-
Copy link

w- commented Aug 15, 2017

@ide Does it make sense that XDE's custom console.log should handle this case more gracefully?

@Fr33maan
Copy link

Fr33maan commented Sep 21, 2017

If object is circular, it would be nice to automatically decycle it instead of crashing.
This do the trick for me
https://github.com/douglascrockford/JSON-js/blob/master/cycle.js

@nicknovitski nicknovitski self-assigned this Mar 27, 2018
@nicknovitski
Copy link
Member

@ide @w- @L1br3 It looks like pretty-format works with object cycles.

Are you all still having the problem?

@nicknovitski nicknovitski added the needs more info To be used when awaiting reporter response label Mar 27, 2018
@w-
Copy link

w- commented Mar 28, 2018

@nicknovitski i am. From what you linked, pretty-format is part of jest? The recommendation is we use that inside of console.log?

@FezVrasta
Copy link

For anyone running into this issue, you can use something like json-decycle and do:

import { decycle } from 'json-decycle';

onLayout={evt => console.log(decycle(evt))}

@lock lock bot added the outdated label Jun 21, 2019
@lock lock bot locked and limited conversation to collaborators Jun 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs more info To be used when awaiting reporter response
Projects
None yet
Development

No branches or pull requests

8 participants