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

Phantom instance of views being instantiated #151

Labels
Resolution: Locked This issue was locked by the bot.

Comments

@jaygarcia
Copy link
Contributor

While trying to bring in an audio plotter library, I noticed that when I ask for one instance of my view to be rendered, two are instantiated.

Fearing that I'm doing something wrong, I started to dig deeper and created a test project where I duplicated the tic-tac-toe project and rendered a single scroll view, modified the RCTCustomScrollView class accordingly:

@implementation RCTCustomScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
  NSLog(@"%@ %@()",  NSStringFromClass([self class]), NSStringFromSelector(_cmd));

  if ((self = [super initWithFrame:frame])) {
    [self.panGestureRecognizer addTarget:self action:@selector(handleCustomPan:)];
  }
  return self;
}

Implemented via:

'use strict';

var React = require('react-native');
var {
  AppRegistry,
  StyleSheet,
  Text,
  ScrollView,
} = React;


var TicTacToeApp = React.createClass({
  render() {
    return (
      <ScrollView style={styles.container}>
        <Text style={styles.title}>Test View</Text>
      </ScrollView>
    );
  }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white'
  },
  title: {
    fontFamily: 'Chalkduster',
    fontSize: 39,
    marginBottom: 20,
  }
});

AppRegistry.registerComponent('TicTacToeApp', () => TicTacToeApp);

module.exports = TicTacToeApp;

2015-03-14_19-03-01

@jaygarcia
Copy link
Contributor Author

In my own project.

2015-03-14_19-07-57_01

@sahrens
Copy link
Contributor

sahrens commented Mar 14, 2015

So in order for the react diffing algorithm to correctly reset properties back to their default state, we create a single dummy "defaultView" for every type of view so we know what value the properties should be reset to if the property of deleted or nulled out on the JS side. This is probably the second instantiation you're seeing, and your views need to be resilient to creating multiple instances (but I think there might also be a mechanism to provide the default view manually, so you could potentially use a singleton if you wanted, but that would probably break things).

If you are seeing more than one extra view than you are expecting being instantiated, let me know.

-Spencer

On Mar 14, 2015, at 4:08 PM, Jay Garcia [email protected] wrote:

In my own project.


Reply to this email directly or view it on GitHub.

@vjeux vjeux closed this as completed Mar 16, 2015
harrykiselev pushed a commit to harrykiselev/react-native that referenced this issue Aug 5, 2015
Removing unused store.  Change related to facebook#120
@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.