@@ -86,6 +86,18 @@ export default class Stack extends React.Component<Props, State> {
8686 this . setState ( { layout : { width, height } } ) ;
8787 } ;
8888
89+ private getBackTitle = ( { route } : { route : Route } ) => {
90+ const { routes, getTitle } = this . props ;
91+
92+ const i = routes . findIndex ( r => r . key === route . key ) ;
93+
94+ if ( routes [ i - 1 ] ) {
95+ return getTitle ( { route : routes [ i - 1 ] } ) ;
96+ }
97+
98+ return undefined ;
99+ } ;
100+
89101 render ( ) {
90102 const {
91103 routes,
@@ -143,6 +155,7 @@ export default class Stack extends React.Component<Props, State> {
143155 } ) ,
144156 onGoBack,
145157 getTitle,
158+ getBackTitle : this . getBackTitle ,
146159 styleInterpolator : headerStyleInterpolator ,
147160 } )
148161 : null }
@@ -152,14 +165,15 @@ export default class Stack extends React.Component<Props, State> {
152165 pointerEvents = { layout . height && layout . width ? 'box-none' : 'none' }
153166 >
154167 { routes . map ( ( route , index , self ) => {
168+ const previousRoute = self [ index - 1 ] ;
169+ const nextRoute = self [ index - 1 ] ;
170+
155171 const focused = focusedRoute . key === route . key ;
156172 const current = progress [ route . key ] ;
157- const previous = self [ index - 1 ]
158- ? progress [ self [ index - 1 ] . key ]
159- : undefined ;
160- const next = self [ index + 1 ]
161- ? progress [ self [ index + 1 ] . key ]
173+ const previous = previousRoute
174+ ? progress [ previousRoute . key ]
162175 : undefined ;
176+ const next = nextRoute ? progress [ nextRoute . key ] : undefined ;
163177
164178 return (
165179 < Card
@@ -199,18 +213,21 @@ export default class Stack extends React.Component<Props, State> {
199213 ? renderHeader ( {
200214 mode : 'screen' ,
201215 layout,
202- scene : {
203- route,
204- progress : {
205- current,
206- next,
207- previous,
216+ scenes : [
217+ {
218+ route,
219+ progress : {
220+ current,
221+ next,
222+ previous,
223+ } ,
224+ focused,
225+ descriptor : getDescriptor ( { route } ) ,
208226 } ,
209- focused,
210- descriptor : getDescriptor ( { route } ) ,
211- } ,
227+ ] ,
212228 onGoBack,
213229 getTitle,
230+ getBackTitle : this . getBackTitle ,
214231 styleInterpolator : headerStyleInterpolator ,
215232 } )
216233 : null }
0 commit comments