0

I'm new on this topic. Having a class called BarkodOkuycu. In this class when barcodeReceived(e) is called I need to change text value in { < Tv/>}. I want to change score value but don't know how to do that.

Since being a newbie on subject it would be great to know If something is messy or can be made better in code.

Note: styles were deleted before posting question.

   import React, {
      AppRegistry,
      Component,
      StyleSheet,
      Text,
      ListView,
      TouchableOpacity,
      ScrollView,
      View,
    } from 'react-native';
    import BarcodeScanner from 'react-native-barcodescanner-master';


    class barkodOkuyucu extends Component {

      constructor(props) {
        super(props);

        this.state = {
          torchMode: 'off',
          cameraType: 'back',
         barkodNo: '123123',
          loaded: false,  
        };

      }
    barcodeReceived(e) {
        console.log('Barcode: ' + e.data);
        console.log('Type: ' + e.type);

      }
      render() {
        return (
         <View style={styles.container}>
           <View style={styles.kameraContainer}>
            <BarcodeScanner onBarCodeRead={this.barcodeReceived}
            style={styles.kamera}
            torchMode={this.state.torchMode}
            cameraType={this.state.cameraType}

             />
           </View>
            {<Tv/>}


           <ScrollView 
              ref={(scrollView) => { _scrollView = scrollView; }}
              automaticallyAdjustContentInsets={false}
              onScroll={() => { console.log('onScroll!'); }}
              scrollEventThrottle={200}
              style={styles.scroolViewStyle}>
              {THUMBS.map(createThumbRow)}
            </ScrollView>
           <TouchableOpacity
              style={styles.button}
              onPress={this.butonClick}>
              <Text>Scroll to top</Text>
            </TouchableOpacity>

         </View>

        );

      }

      butonClick(){
       console.log('butonpressed!');
        _scrollView.scrollTo({y: 0});
        }

    }
    var Tv = React.createClass({
        getInitialState() {
            return {
                score: 0
            }
        },

        componentDidMount() {

            this.setState({
                score: 6
            })

        },
       btnClick(){
         this.setState({ score: 16 });
       console.log('view clicsa!');

        },
        render() {
            return (
               <View  style={styles.container2}>
               <Text style={styles.instructions} >
                 {this.state.score}
              </Text>
           </View>


            );
        }
    });
    AppRegistry.registerComponent('barcodOku', () => barcodOku);
     var THUMBS = ['a','b','c'];
        THUMBS = THUMBS.concat(THUMBS); // double length of THUMBS
        var createThumbRow = (uri, i) => <Thumb key={i} uri={uri} />;
        var Thumb = React.createClass({
      shouldComponentUpdate: function(nextProps, nextState) {
        return false;
      },
      render: function() {
        return (
           <View style={styles.barkodStyle}>

              <Text style={styles.barkodTextStyle} >{this.props.uri}</Text>

          </View>
        );
      }
    });



    AppRegistry.registerComponent('barkodOkuyucu', () => barkodOkuyucu);
Burak Karasoy
  • 1,682
  • 2
  • 21
  • 33

1 Answers1

0

React Native is completely state driven

this.state = {
Add this--->  data: "",
Add this--->  Type: ""
       };

And update State on function call

   barcodeReceived(e) {
        this.setState({
            data: e.data,
            Type: e.type
        })
       console.log('Barcode: ' + e.data);
       console.log('Type: ' + e.type);
     }

This Will update the state and Component re-renders updating the value. (ReactJS - Does render get called any time "setState" is called?)

Community
  • 1
  • 1
Vikram Belde
  • 979
  • 8
  • 16