android - React-Native How to update text value -


i'm new on topic. having class called barkodokuycu. in class when barcodereceived(e) called need change text value in { < tv/>}. want change score value don't know how that.

since being newbie on subject great know if messy or can made better in code.

note: styles deleted before posting question.

   import react, {       appregistry,       component,       stylesheet,       text,       listview,       touchableopacity,       scrollview,       view,     } 'react-native';     import barcodescanner '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 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); 

react native 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 update state , component re-renders updating value. (reactjs - render called time "setstate" called?)


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -