Nativebase: The issue with Thumbnail in TouchableHighlight

Created on 26 Feb 2017  路  19Comments  路  Source: GeekyAnts/NativeBase

Hello,

There is an issue with Thumbnail wrapped by TouchableHighlight. I am using Exponent XDE v14.0.0 and running the project on Genymotion emulator for Google Nexus 5 4.4.4 API 19.

Versions used

  • node.js 7.6.0
  • exponent 14.0.0
  • react 15.4.0
  • react-native 0.41.0
  • native-base 2.0.10

Expected behaviour

I am able to tap Thumbnail wrapped by TouchableHighlight.

Actual behaviour

When I tap Thumbnail, I get "undefined is not an object (evaluating 'this.wrappedInstance.setNativeProps')".

The project code

import Exponent from 'exponent';
import React from 'react';
import {
  Platform,
  Alert,
  TouchableHighlight
} from 'react-native';
import {
  Container,
  Header,
  Body,
  Title,
  Content,
  Thumbnail
} from 'native-base';

class App extends React.Component {
  constructor (props) {
    super(props);

    this.state = {
      isReady: false
    };
  }

  async componentWillMount() {
    if (Platform.OS === 'android') {
      await Exponent.Font.loadAsync({
        'Roboto': require('native-base/Fonts/Roboto.ttf'),
        'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf')
      });

      this.setState({
        isReady: true
      });
    }
  }

  render() {
    if (!this.state.isReady) {
      return <Exponent.Components.AppLoading />;
    }

    return (
      <Container style={{ flex: 1 }}>
        <Header>
          <Body>
            <Title style={{ alignSelf: 'stretch' }}>Test</Title>
          </Body>
        </Header>
        <Content>
          <TouchableHighlight onPress={ () => Alert.alert('Info', 'Image tapped') }>
            <Thumbnail style={{ width: 50, height: 50 }} source={{ uri: 'http://www.apdconsumo.pt/person.png' }} />
          </TouchableHighlight>
        </Content>
      </Container>
    );
  }
}

Exponent.registerRootComponent(App);

The screenshots

screenshot1
screenshot2

The device

I have tested the project only on Android.

The additional information

I think, you do not define the setNativeProps method in the Thumbnail component. Please, check Composite components and setNativeProps.

bug

Most helpful comment

I get the same error even if I use native-base Text in react-native TouchableHighlight:

import {
  Alert,
  TouchableHighlight
} from 'react-native';
import {
  Text
} from 'native-base';

<TouchableHighlight onPress={ () => Alert.alert('Info', 'Text touched') }>
  <Text>Click here</Text>
</TouchableHighlight>

However, if I use react-native Text, it works without issues:

import {
  Alert,
  TouchableHighlight,
  Text
} from 'react-native';

<TouchableHighlight onPress={ () => Alert.alert('Info', 'Text touched') }>
  <Text>Click here</Text>
</TouchableHighlight>

All 19 comments

+1

I just tested it on iOS and android both and it works. Maybe exponent is causing this?

I also get this error with an icon in a TouchableHighlight, when the container is wrapped in a style provider

styleprovider
Strange!

This is the code in my case:

  render() {
    return (
      <View style={{...this.props.style.container, height: this.state.height}}>
        <View onLayout={this.setHeaderHeight}>
          <TouchableHighlight onPress={this.toggle}>
            <Text>click here</Text>
          </TouchableHighlight>
        </View>
        <View onLayout={this.setContentHeight}>
          {this.props.children}
        </View>
      </View>
    );
  }
}

export default connectStyle('zoraTheme.Accordion', styles)(Accordion);

And I'm getting the same error

I have just updated native-base to the latest version 2.0.11 and it started working. It did not work with native-base 2.0.10.

It worked with me as well after install 2.0.11

+1 to the 2.0.11 fix

Great! Closing it then.

@sankhadeeproy007
I'm already using 2.0.12, but the issue still comes up. Is it related to react native 0.42? Exactly having the Thumbnail in TouchableHighlight. Anyone?

The issue is back again in native-base 2.0.12.

I get the same error even if I use native-base Text in react-native TouchableHighlight:

import {
  Alert,
  TouchableHighlight
} from 'react-native';
import {
  Text
} from 'native-base';

<TouchableHighlight onPress={ () => Alert.alert('Info', 'Text touched') }>
  <Text>Click here</Text>
</TouchableHighlight>

However, if I use react-native Text, it works without issues:

import {
  Alert,
  TouchableHighlight,
  Text
} from 'react-native';

<TouchableHighlight onPress={ () => Alert.alert('Info', 'Text touched') }>
  <Text>Click here</Text>
</TouchableHighlight>

@sankhadeeproy007 , can you reopen the issue? The error comes up again for Thumbnail inside TouchableHighlight in 2.0.12.

Same as @stonecold123 , error comes up with Icon inside TouchableHighlight in 2.0.13.

@sankhadeeproy007 the issue was never resolved and it is breaking our projects. please reopen and fix it. click on the image to enlarge.

nbe

We are looking into the issue. As a workaround for now, you can wrap the child component of TouchableHighlight into a RN <View>.

To expand on @shivrajkumar 's workaround, you need to import the View component from React Native: using Native Base's View component still causes the error.

Fixed with 2.1.5

facing same issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eggybot picture eggybot  路  3Comments

aloifolia picture aloifolia  路  3Comments

elnygren picture elnygren  路  3Comments

agersoncgps picture agersoncgps  路  3Comments

bsiddiqui picture bsiddiqui  路  3Comments