Read the original article:About the issue of keyboard crash when popping up
Problem Description
Needed to implement a functional scenario. Page A has a RichEditor input box. Page A pushes page B through navPathStack. Then, after page B is popped, the input box of page A enters the editing state.
Implemented it through this.getUIContext().getFocusController().requestFocus('editor');
but when executed the latter operation, a crash occurred.
Solution
There is no better way at present. RequestFocus needs to be executed after the component is loaded. There are currently the following workarounds that can be tried:
1.Add parameters to the index page (A) and use watch to monitor;
@State @Watch ( "changeStr" ) str : string = "index" ;
changeStr (){
if(this.str === "pop"){
console.log("===》changeStr()")
setTimeout(()=>{
this.getUIContext().getFocusController().requestFocus("RichEditor")
},100)
this.str = "index";
}
}Copy codeCopy code
2.When the page returns from page B via pop, listen to the parameters callback from page B and assign them to this.str to trigger the watch listening, and call back requestFocus to trigger focus control;
this.pageStack.pushPathByName ( " testPage " , tmp , ( popInfo ) => {
this.message =
' [ pushPathByName]last page is: ' + popInfo.info.name + ' , result : ' + JSON.stringify ( popInfo.result )
; this.str = ( popInfo.result as resultClass ) .str
});Copy codeCopy code
3.The reason for adding the setTimeout function in changeStr ; the watch listener callback may occur before the component is rendered, thus causing a crash; and the 100ms delay will not affect the usage.
Top comments (0)