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

onBlur doesn't work #129

Open
GrigoriyPol opened this issue Dec 22, 2023 · 2 comments
Open

onBlur doesn't work #129

GrigoriyPol opened this issue Dec 22, 2023 · 2 comments

Comments

@GrigoriyPol
Copy link

I want to dismiss keyboard when user loses focus (scroll or tap outside of the editor area) but it doesn't work.
Also I couldn't find how to use focus and blur methods to do it manually.

@BeenishHanif
Copy link

hey have u found out any way to achieve this?

@kevalkikani180
Copy link

To implement a shared editor ref for managing blur behavior, follow these steps:

Create a context for the editor ref in a new file:

`// FlowChatRefContext.js
import React, { createContext, useContext } from "react";

// Create the context
const FlowChatRefContext = createContext(null);

// Provider component to wrap around components needing access to the ref
export const FlowChatRefProvider = ({ children }: any) => {
const ref: any = React.createRef();
return (
<FlowChatRefContext.Provider value={ref}>
{children}
</FlowChatRefContext.Provider>
);
};

// Custom hook to access the ref
export const useSharedRef = () => {
const context = useContext(FlowChatRefContext);
if (!context) {
throw new Error("useSharedRef must be used within a FlowChatRefProvider");
}
return context;
};
`

Use the shared ref in your component:

const _editor = useSharedRef();

Add blur functionality to your main view by attaching it to SafeAreaView:

<SafeAreaView onTouchStart={() => _editor?.current?.blur()}> {/* Your main view content */} </SafeAreaView>

This solution ensures that the editor blurs properly by calling blur on _editor when the SafeAreaView is touched.

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