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

[Bug] tx.setCurrentLocal loading state [React Native] #222

Open
nazmeln opened this issue Apr 12, 2024 · 0 comments
Open

[Bug] tx.setCurrentLocal loading state [React Native] #222

nazmeln opened this issue Apr 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nazmeln
Copy link

nazmeln commented Apr 12, 2024

Current Behavior
When I call tx.setCurrentLocal the UI freezes(button stays as pressed, please see the video recording) until the translations are fetched, also I can't get a proper loading state. The loading state returns true when doing console.log but the loader doesn't appear on the screen.

Expected Behavior
The UI doesn't freeze when the locale changes and the loading indicator value is displayed on the screen.

Steps to Reproduce

export const useTranslation = () => {
    const t: (key: string, replacements?: Record<string, string | number | undefined | null | JSX.Element>) => string =
        useT()
    const dispatch = useAppDispatch()

    const [isTranslationsLoading, setIsTranslationsLoading] = useState(false)

    const { showCommonErrorToast } = useToast()

    const changeLanguage = useCallback(
        async (locale: string) => {
            try {
                setIsTranslationsLoading(true)

                await tx.setCurrentLocale(locale)

                dispatch(addLocaleCode(locale))
            } catch (err) {
                showCommonErrorToast()
            } finally {
                setIsTranslationsLoading(false)
            }
        },
        [dispatch, showCommonErrorToast],
    )

    return {
        t,
        isTranslationsLoading,
        changeLanguage,
    }
}

const DemoComponent = () => {
    const { t, changeLanguage, isTranslationsLoading } = useTranslation()

   return (
       {isTranslationsLoading && <ActivityIndicator />}
            <Button title='Change locale' onPress={() => changeLanguage('en')} />
  )
}

Here's the demo

Screen.Recording.2024-04-12.at.18.57.06.mov
@nazmeln nazmeln added the bug Something isn't working label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant