After loading React Component present modally from Native, how to dismiss modal from React Native and back to previous in ios -


in current ios project i'm loading react component contains navigation bar navigation item 'cancel' native 'viewcontroller'.

when user tap on 'cancel' bar button should previous viewcontroller i.e native.

it becomes blocker me. can 1 please me overcome this.

native view screenshot

react component screenshot

below code

// viewcontroller.h

#import "viewcontroller.h"  #import "reactnativeobjcviewcontroller.h"  @interface viewcontroller ()  @end  @implementation viewcontroller  - (void)viewdidload {     [super viewdidload]; }  - (void)didreceivememorywarning {     [super didreceivememorywarning]; }  -(ibaction)movetonext:(id)sender {   reactnativeobjcviewcontroller *rootviewcontroller = (reactnativeobjcviewcontroller *)[[uistoryboard storyboardwithname:@"main" bundle:null] instantiateviewcontrollerwithidentifier:@"reactnativevc"];    [[self navigationcontroller] pushviewcontroller:rootviewcontroller animated:yes]; } 

// reactnativeobjcviewcontroller.h

#import "reactnativeobjcviewcontroller.h"  #import "reactnativeviewobjc.h"  @interface reactnativeobjcviewcontroller () @property (weak, nonatomic) iboutlet reactnativeviewobjc *reactviewwrapper;  @end  @implementation reactnativeobjcviewcontroller  - (void)viewdidload {   [super viewdidload];   self.title = @"react wrapper (obj c)";     self.reactviewwrapper.data = [@{                                   @"content": @"welcome react native"                                   } mutablecopy];    [self.reactviewwrapper initializereactview];   } - (void)didreceivememorywarning {     [super didreceivememorywarning]; } 

// reactnativeviewobjc.h

#import <uikit/uikit.h>  @interface reactnativeviewobjc : uiview  @property (nonatomic, strong) nsmutabledictionary *data; - (void) initializereactview; @end 

//reactnativeviewobjc.m

#import "reactnativeviewobjc.h"  #import "rctbundleurlprovider.h" #import "rctrootview.h"   @implementation reactnativeviewobjc  -(void) initializereactview {     nsurl *jscodelocation;    jscodelocation = [[rctbundleurlprovider sharedsettings] jsbundleurlforbundleroot:@"index.ios" fallbackresource:nil];    rctrootview *rootview = [[rctrootview alloc] initwithbundleurl:jscodelocation modulename:@"devdactic_tabs" initialproperties:nil       launchoptions:nil];   rootview.backgroundcolor = [[uicolor alloc] initwithred:1.0f green:1.0f blue:1.0f alpha:1];    rootview.translatesautoresizingmaskintoconstraints = no;   [self addsubview:rootview];    nsdictionary *views = @{@"rootview": rootview};   nsarray *constraints = @[];   constraints = [constraints arraybyaddingobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"v:|-0-[rootview]-0-|" options:0 metrics:nil views:views]];   constraints = [constraints arraybyaddingobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"h:|-0-[rootview]-0-|" options:0 metrics:nil views:views]];    [self addconstraints:constraints];   [self layoutifneeded]; } @end 

/* js files */

// index.ios.js

import react, { component } 'react'; import {   appregistry,   stylesheet,   text,   view,   tabbarios,  } 'react-native';   var welcome = require('./welcome');  var featured = require('./featured');  class devdactic_tabs extends component {      constructor(props) {     super(props);     this.state = {       selectedtab: 'featured'     };   }      render() {     return (       <tabbarios          unselectedtintcolor="white"                 tintcolor={'#c1d82f'}          bartintcolor="darkslateblue"         selectedtab={this.state.selectedtab}>         <tabbarios.item         title= "featured"           selected={this.state.selectedtab === 'featured'} //          icon={{uri:'featured'}}           onpress={() => {               this.setstate({                   selectedtab: 'featured',               });           }}>             <featured/>         </tabbarios.item>         <tabbarios.item           title="more"           selected={this.state.selectedtab === 'more'} //          icon={{uri:'contacts'}}           onpress={() => {                 this.setstate({                     selectedtab: 'more',                 });           }}>           <welcome/>         </tabbarios.item>       </tabbarios>     );   } }  const styles = stylesheet.create({   container: {     flex: 1,     justifycontent: 'center',     alignitems: 'center',     backgroundcolor: '#f5fcff',   },   welcome: {     fontsize: 20,     textalign: 'center',     margin: 10,   },   instructions: {     textalign: 'center',     color: '#333333',     marginbottom: 5,   }, });  appregistry.registercomponent('devdactic_tabs', () => devdactic_tabs); 

// welcome.js

'use strict';  import react, { component } 'react'; import {   appregistry,   stylesheet,   text,   view,   tabbarios,   navigatorios     } 'react-native';  var welcomeview = require('./welcomeview');  var styles = stylesheet.create({   description: {     fontsize: 20,     textalign: 'center',     color: '#ffffff'   },   container: {     flex: 1,     justifycontent: 'center',     alignitems: 'center',     backgroundcolor: '#123456',   } });  class welcome extends component {   render() {     return (       <navigatorios          initialroute={{         component:welcomeview,         leftbuttontitle: 'cancel',         title:'more',         }}         style={{flex:1}}         />     );   } }  module.exports = welcome; 

// welcomeview.js

'use strict';  import react, {component} 'react';  import  {     image,     stylesheet,     text,     view,     listview,     tabbarios,     navigatorios,     activityindicatorios,     touchablehighlight  } 'react-native';  var bookdetails = require('./bookdetails');        var fake_book_data = [     {volumeinfo: {title: 'the catcher in rye', authors: "j. d. salinger", update: "coming soon!", description: "une édition de référence des contes de ma mère l’oye de charles perrault, spécialement conçue pour la lecture sur les supports numériques. « cependant les fées commencèrent à faire leurs dons à la princesse. la plus jeune lui donna pour don qu’elle serait la plus belle personne du monde ; celle d’après, qu’elle aurait de l’esprit comme un ange ; la troisième, qu’elle aurait une grâce admirable à tout ce qu’elle ferait ; la quatrième, qu’elle danserait parfaitement bien ; la cinquième, qu’elle chanterait comme un rossignol ; la sixième, qu’elle jouerait de toutes sortes d’instruments dans la dernière perfection. le rang de la vieille fée étant venu, elle dit, en branlant la tête encore plus de dépit que de vieillesse, que la princesse se percerait la main d’un fuseau, et qu’elle en mourrait. » (extrait de la belle au bois dormant.)", imagelinks: {thumbnail: 'https://books.google.com/books/content?id=pcdengeacaaj&printsec=frontcover&img=1&zoom=1&source=gbs_api'}}}, {volumeinfo: {title: 'the finisher', authors: "k. l. rotery", update: "coming soon!", imagelinks: {thumbnail: 'https://i.imgur.com/uepbdph.jpg'}}}, {volumeinfo: {title: 'the catcher in rye', authors: "j. d. salinger", update: "coming soon!", imagelinks: {thumbnail: 'https://resizing.flixster.com/m7g-webzpyfnoqsif59lippyoum=/44x81/dkpu1ddg7pbsk.cloudfront.net/movie/10/97/47/10974721_ori.jpg'}}}, {volumeinfo: {title: 'the finisher', authors: "k. l. rotery", update: "coming soon!", imagelinks: {thumbnail: 'https://resizing.flixster.com/q8ibqx3b-nheaeyokj_ah6jo6le=/54x78/dkpu1ddg7pbsk.cloudfront.net/movie/10/94/13/10941373_ori.jpg'}}}, {volumeinfo: {title: 'the catcher in rye', authors: "j. d. salinger", update: "coming soon!", imagelinks: {thumbnail: 'https://resizing.flixster.com/e3akmywuh1wr4qmam_vq0vtn9aa=/54x77/dkpu1ddg7pbsk.cloudfront.net/movie/10/94/13/10941368_ori.jpg'}}}, {volumeinfo: {title: 'the finisher', authors: "k. l. rotery", update: "coming soon!", imagelinks: {thumbnail: 'https://resizing.flixster.com/1fxtmlxcqrb0epdhfrfdgpz45ce=/54x75/dkpu1ddg7pbsk.cloudfront.net/movie/31/16/311623_ori.jpg'}}}, {volumeinfo: {title: 'the catcher in rye', authors: "j. d. salinger", update: "coming soon!", imagelinks: {thumbnail: 'https://resizing.flixster.com/yfgywviboaadhg99eof3vuleblc=/54x74/dkpu1ddg7pbsk.cloudfront.net/movie/10/97/67/10976773_ori.jpg'}}}, {volumeinfo: {title: 'the finisher', authors: "k. l. rotery", update: "coming soon!", imagelinks: {thumbnail: 'https://resizing.flixster.com/d7zwfbxpcaqxboj-w57_b8b2tr0=/54x80/dkpu1ddg7pbsk.cloudfront.net/movie/10/92/85/10928519_ori.jpg'}}}, {volumeinfo: {title: 'the catcher in rye', authors: "j. d. salinger", update: "coming soon!", imagelinks: {thumbnail: 'https://resizing.flixster.com/d7zwfbxpcaqxboj-w57_b8b2tr0=/54x80/dkpu1ddg7pbsk.cloudfront.net/movie/10/92/85/10928519_ori.jpg'}}}, {volumeinfo: {title: 'the finisher', authors: "k. l. rotery", update: "coming soon!", imagelinks: {thumbnail: 'https://resizing.flixster.com/yttvb_8gxph4s7ijcilqfbz2s7q=/54x74/dkpu1ddg7pbsk.cloudfront.net/movie/11/00/22/11002233_ori.jpg'}}} ];      var styles = stylesheet.create({  });   var styles = stylesheet.create({     container: {         flex: 1,         flexdirection: 'row',         justifycontent: 'center',         alignitems: 'center',         backgroundcolor: '#f5fcff',         padding: 10     },     thumbnail: {         width: 53,         height: 81,         marginright: 10     },     rightcontainer: {         flex: 1     },     title: {         fontsize: 20,         marginbottom: 8     },     author: {         color: '#656565'     },     separator: {         height: 1,         backgroundcolor: '#dddddd'     },     listview: {         backgroundcolor: '#f5fcff'     },     loading: {         flex: 1,         alignitems: 'center',         justifycontent: 'center'     } });  class welcomeview extends component{      constructor(props){          super(props);         this.state = {             datasource: new listview.datasource({                rowhaschanged: (row1, row2) => row1 !== row2            })         };     }       componentdidmount() {          var books = fake_book_data;     this.setstate({         datasource: this.state.datasource.clonewithrows(books)     });      }      render(){         return(         <listview                  datasource={this.state.datasource}                 renderrow={this.renderbook.bind(this)}                 style={styles.listview}              ></listview>         );     }       renderbook(book){         return(          <touchablehighlight onpress= {() => this.showdetails(book)}             underlaycolor='#dddddd'>             <view>                 <view style={styles.container}>                 <image source={{uri: book.volumeinfo.imagelinks.thumbnail}}                 style={styles.thumbnail}/>                <view style={styles.rightcontainer}>                             <text style={styles.title}>{book.volumeinfo.title}</text>                             <text style={styles.author}>{book.volumeinfo.authors}</text>                             <text style={styles.author}>{book.volumeinfo.publisher}</text>                             <text style={styles.title}>{book.volumeinfo.publisheddate}</text>                          </view>                </view>              <view style={styles.separator} />              </view>             </touchablehighlight>         );     }     showdetails(book){         this.props.navigator.push({             title: book.volumeinfo.title,             component: bookdetails,             passprops: {book}         });    }  }  module.exports = welcomeview; 

// featured.js

'use strict';  import react, { component } 'react'; import {   appregistry,   stylesheet,   text,   view,   tabbarios,   navigatorios,   nativemodules  } 'react-native';    var featuredlist = require('./featuredlist');  let dismissviewcontrollermanager = nativemodules.dismissviewcontrollermanager;  var styles = stylesheet.create({   description: {     fontsize: 20,     textalign: 'center',     color: '#ffffff'   },   container: {     flex: 1,     justifycontent: 'center',     alignitems: 'center',     backgroundcolor: 'red',   } });  class featured extends component {   render() {     return (       <navigatorios         initialroute={{           component: featuredlist,           title: 'featured',           leftbuttontitle: 'cancel',         onleftbuttonpress: () => this._handlenavigationrequest(),         }}         style={{flex: 1}}       />     );   }       _handlenavigationrequest() {     dismissviewcontrollermanager.goback();   } }  module.exports = featured; 

// featuredlistview

'use strict';  import react, { component } 'react'; var request_url = 'https://www.googleapis.com/books/v1/volumes?q=subject:fiction';  var bookdetails = require('./bookdetails');  import {     image,     stylesheet,     text,     view,     listview,     tabbarios,     navigatorios,     activityindicatorios,     touchablehighlight     } 'react-native';    var styles = stylesheet.create({     container: {         flex: 1,         flexdirection: 'row',         justifycontent: 'center',         alignitems: 'center',         backgroundcolor: '#f5fcff',         padding: 10     },     thumbnail: {         width: 53,         height: 81,         marginright: 10     },     rightcontainer: {         flex: 1     },     title: {         fontsize: 20,         marginbottom: 8     },     author: {         color: '#656565'     },     separator: {         height: 1,         backgroundcolor: '#dddddd'     },     listview: {         backgroundcolor: '#f5fcff'     },     loading: {         flex: 1,         alignitems: 'center',         justifycontent: 'center'     } });  class moreview extends component{       constructor(props) {        super(props);        this.state = {            datasource: new listview.datasource({                rowhaschanged: (row1, row2) => row1 !== row2            })        };    }      componentdidmount() {           this.fetchdata();     }       fetchdata() {          fetch(request_url)             .then((response) => response.json())             .then((responsedata) => {                 this.setstate({                     datasource: this.state.datasource.clonewithrows(responsedata.items),                     isloading: false                 });             })             .done();     }       render(){           if (this.state.isloading) {             return this.renderloadingview();         }          return (             <listview                 datasource={this.state.datasource}                 renderrow={this.renderbook.bind(this)}                 style={styles.listview}                 />         );       }      renderloadingview() {         return (             <view style={styles.loading}>                 <activityindicatorios                     size='large'/>                 <text>                     loading books...                 </text>             </view>         );     }      renderbook(book) {        return (             <touchablehighlight onpress ={() => this.showbookdetails(book)} underlaycolor='#dddddd'>                 <view>                     <view style={styles.container}>                         <image                             source={{uri: book.volumeinfo.imagelinks.thumbnail}}                             style={styles.thumbnail} />                         <view style={styles.rightcontainer}>                             <text style={styles.title}>{book.volumeinfo.title}</text>                             <text style={styles.author}>{book.volumeinfo.authors}</text>                             <text style={styles.author}>{book.volumeinfo.publisher}</text>                             <text style={styles.title}>{book.volumeinfo.publisheddate}</text>                          </view>                     </view>                     <view style={styles.separator} />                 </view>             </touchablehighlight>        );    }      showbookdetails(book){        this.props.navigator.push({             title: book.volumeinfo.title,             component: bookdetails,             passprops: {book}         });    }  }   module.exports = moreview; 

// bookdetails.js

'use strict';  import react, {component} 'react';  import {     stylesheet,     text,     view,     image,     scrollview     } 'react-native';  var styles = stylesheet.create({     container: {         margintop: 75,         alignitems: 'center'     },     image: {         width: 107,         height: 165,         padding: 10     },     description: {         padding: 10,         fontsize: 15,         color: '#656565'     },     scrollcontainer: {         margintop: 20,         marginbottom: 20,         padding: 10     }, });  class bookdetails extends component {     render() {         var book = this.props.book;         var imageuri = (typeof book.volumeinfo.imagelinks !==   'undefined') ? book.volumeinfo.imagelinks.thumbnail : '';         var description = (typeof book.volumeinfo.description !== 'undefined') ? book.volumeinfo.description : '';         return (             <view style={styles.container}>                 <image style={styles.image} source={{uri: imageuri}} />             <scrollview style={styles.scrollcontainer}>                 <text style={styles.description}>{description}</text>             </scrollview>             </view>         );     } }  module.exports = bookdetails; 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -