Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onSearch not firing #30

Closed
bvoelz19 opened this issue Sep 18, 2017 · 4 comments
Closed

onSearch not firing #30

bvoelz19 opened this issue Sep 18, 2017 · 4 comments

Comments

@bvoelz19
Copy link

bvoelz19 commented Sep 18, 2017

Here's my code:
`import Search from "react-native-search-box";

export default class App extends Component {
onSearch = () => {
alert("!");
}

onCancel = () => {
    alert("????");
}

render() {
    return (
        <View style={styles.container}>
            {/* Hide status bar */}
            <StatusBar hidden={true} />

            {/* Header */}
            <View style={styles.headerContainer}>
                <Text style={styles.text}>
                    NeuralNews
                </Text>
            </View>

            {/* Search field */}
            <View style={styles.searchBar}>
                <Search
                    ref={"search_box"}
                    onSearch={this.onSearch}
                    onCancel={this.onCancel}
                 />
            </View>
        </View>
    );
}

}`

For some reason, the onSearch method isn't firing even though the onCancel one is. What exactly causes the onSearch to fire? I am testing on a simulator, and pressing the 'Search' button on the iPhone keyboard isn't seeming to work.

@anhtuank7c
Copy link
Contributor

/**
     * onSearch
     * return a Promise
     */

@bvoelz19
Copy link
Author

onSearch = () => { const thePromise = new Promise((resolve) => { alert("PLZ"); resolve(); }); return thePromise; }

I changed it to this and it's still not firing - any ideas?

@bvoelz19
Copy link
Author

I'm doing this in TypeScript, by the way. Could you show me an example of what a proper function would look like?

@FRizzonelli
Copy link

onSearch={text => new Promise((resolve, reject) => { console.log(text); resolve(); }) }

@bvoelz19 I'm doing this in TS and it works properly 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants