An uncaught Exception occurred on "main" thread. when using custom search bar

114 views Asked by At

I have migrating my native script angular application. Having issue in the custom searchBar after migration. Before migration which was working fine. It shows like having issue in the "nativeView.setOnQueryTextListener(queryTextListener);"

my custom searchbar:

import { SearchBar } from '@nativescript/core';

let QueryTextListener: QueryTextListener;
function initializeNativeClasses(): void {
    if (QueryTextListener) {
        return;
    }
@Interfaces([androidx.appcompat.widget.SearchView.OnQueryTextListener])
class CustomSearchBarImplementation extends java.lang.Object implements androidx.appcompat.widget.SearchView.OnQueryTextListener
{
    public thenewText="";
    constructor(private owner: CustomSearchBar) {
        super();
        return global.__native(this);
    }
    public onQueryTextChange(text: string): boolean {
        return true;
    }    
    public onQueryTextSubmit(text: string): boolean {
        console.log("onQueryTextSubmit onsubmit called")
        const owner = this.owner;
        this.thenewText = text;
        owner.notify({
            object: owner,
            eventName: "DoneIt",
            textSequences: text,
        });
        // owner._emit("onsubMit");        
        return true;

    }


}
QueryTextListener = CustomSearchBarImplementation;

}


export class CustomSearchBar extends SearchBar
{
    nativeViewProtected: androidx.appcompat.widget.SearchView;
    public createNativeView() {
        const nativeView = new androidx.appcompat.widget.SearchView(this._context);
        nativeView.setIconified(false);
        return nativeView;
    }
    
    //Comment by naveen//
    public initNativeView(): void {
        super.initNativeView();
        const nativeView = this.nativeViewProtected;
        initializeNativeClasses();
        const queryTextListener = new QueryTextListener(this);
        nativeView.setOnQueryTextListener(queryTextListener);
        (<any>nativeView).queryTextListener = queryTextListener;
    }


}
interface QueryTextListener {
    new(owner: SearchBar): androidx.appcompat.widget.SearchView.OnQueryTextListener;
}
interface CloseListener {
    new(owner: SearchBar): androidx.appcompat.widget.SearchView.OnQueryTextListener;
}

my error message:

how to fix this issue?

0

There are 0 answers