Skip to content

Phantom instance of views being instantiated #151

@jaygarcia

Description

@jaygarcia

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions