Screen Component
The Screen component is a utility designed to provide the current screen name to WOVN-related functions via React's Context API. This allows developers to dynamically manage and retrieve the screen name within their applications, enhancing WOVN's translation and reporting functionalities.
Usage
The Screen component wraps your application or specific screens, automatically providing the screen name to WOVN components and hooks.
import { Text, Screen, TextInput } from '@wovnio/react-native';
import * as Wovn from '@wovnio/react-native';
import {
Text as RNText,
Button as RNButton,
} from 'react-native';
const CustomComponent = () => {
return (
<>
{/** Wovn.useTranslate will also automatically pick up the screen name from the Screen component */}
<RNText>{Wovn.useTranslate('こんにちは、世界')}</RNText>
<RNButton title={Wovn.useTranslate('こんにちは、世界!') as string}/>
</>
);
};
<Screen name="ScreenName">
{/** WOVN's components will automatically pick up the screen name from the Screen component */}
<Text>こんにちは、世界</Text>
<Button title="こんにちは、世界!"/>
<CustomComponent />
</Screen>
Props
| Prop Name | Type | Default Value | Description |
|---|---|---|---|
name | string | _Default | Specifies the name of the screen for translation and reporting purposes. |
Notes
- Default Screen Name: If the screen name cannot be retrieved from the
Screencomponent, the default screen name_Defaultwill be used. - Function Limitations:
Wovn.translateTextandWovn.translatedo not use theScreencomponent context to determine the screen name.- If no
screenNameis explicitly specified when using these functions, the reported screen name will always default to_Default.
Best Practices
-
Wrap Each Screen with the
ScreenComponent: Ensure every screen in your app is wrapped with aScreencomponent to provide an accuratescreenNamefor WOVN's translation and reporting features.<Screen name="Home">
<Text>Welcome to the Home Screen</Text>
</Screen> -
Explicitly Specify the
screenNameWhen UsingtranslateTextortranslate: Avoid relying on the default_Defaultscreen by providing ascreenNamein these functions.Wovn.translateText('Hello World', 'Home'); -
Consistent Screen Naming: Use meaningful and consistent names for your screens to ensure clarity in translations and reporting.