Skip to content

Commit a4bdff8

Browse files
authored
Merge pull request #38 from RonasIT/PRD-1608-js-doc-ui-and-utils
PRD-1608 - JSDoc - Ui and Utils
2 parents 95021f0 + a28e7ac commit a4bdff8

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

src/lib/src/ui/safe-area-view/component.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,36 @@ import { ReactElement, useMemo } from 'react';
33
import { StyleSheet, View, ViewProps } from 'react-native';
44
import { Edge, useSafeAreaInsets } from 'react-native-safe-area-context';
55

6+
/**
7+
* Props for {@link AppSafeAreaView}.
8+
*
9+
* @property children Elements rendered inside the padded container.
10+
* @property edges An array indicating which edges of the screen to respect. Possible values are 'top', 'right', 'bottom', 'left'. Defaults to all edges.
11+
* @property style Custom styles to apply to the view. Note that padding values will be adjusted to respect safe area insets.
12+
* @property ...rest All other {@link https://reactnative.dev/docs/view#props | ViewProps} are forwarded.
13+
*/
614
export interface AppSafeAreaViewProps extends ViewProps {
715
edges?: Array<Edge>;
816
}
917

1018
const defaultEdges: Array<Edge> = ['top', 'right', 'bottom', 'left'];
1119

12-
export function AppSafeAreaView({ children, edges = defaultEdges, style = {}, ...props }: AppSafeAreaViewProps): ReactElement {
20+
/**
21+
* A component for granular control of safe area edges on each screen.
22+
* The difference from `SafeAreaView` in [react-native-safe-area-context](https://www.npmjs.com/package/react-native-safe-area-context) is that the container adds padding to the elements inside it,
23+
* rather than to the entire screen, making it more flexible for use.
24+
*
25+
* > Requires the `react-native-safe-area-context`.
26+
*
27+
* @param props Component props. See {@link AppSafeAreaViewProps} for a detailed list.
28+
* @returns ReactElement
29+
*/
30+
export function AppSafeAreaView({
31+
children,
32+
edges = defaultEdges,
33+
style = {},
34+
...props
35+
}: AppSafeAreaViewProps): ReactElement {
1336
const insets = useSafeAreaInsets();
1437

1538
const containerStyle = useMemo(() => {
@@ -21,9 +44,13 @@ export function AppSafeAreaView({ children, edges = defaultEdges, style = {}, ..
2144

2245
return [...acc, { [paddingName]: Number(paddings[paddingName] ?? 0) + insets[edge] }];
2346
},
24-
[style]
47+
[style],
2548
);
2649
}, [style, insets, edges]);
2750

28-
return <View style={containerStyle} {...props}>{children}</View>;
51+
return (
52+
<View style={containerStyle} {...props}>
53+
{children}
54+
</View>
55+
);
2956
}

src/lib/src/utils/i18n/i18n.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import { I18n } from 'i18n-js';
22

3+
/**
4+
* Global {@link I18n} instance.
5+
*
6+
* Import this singleton anywhere you need direct access to `i18n.t()`
7+
* or other i18n‑js APIs.
8+
*/
39
export const i18n = new I18n();

src/lib/src/utils/i18n/set-language.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import * as Localization from 'expo-localization';
22
import { i18n } from './i18n';
33

4+
/**
5+
* Register translation tables **once** and receive a helper to change the active language.
6+
*
7+
* > Requires `i18n-js` and `expo-localization`.
8+
*
9+
* @typeParam T Map of language codes (`en`, `fr`, `ru`, …) to their translation dictionaries.
10+
*
11+
* @param translations Object containing translation tables keyed by language code.
12+
* @param defaultLanguage Language that will be used when the requested language is missing.
13+
*
14+
* @returns Function that sets `i18n.locale`.
15+
* When called **without** arguments, the device locale from `expo-localization` is used.
16+
*/
417
export function setLanguage<T extends (typeof i18n)['translations']>(
518
translations: T,
6-
defaultLanguage: keyof typeof translations
19+
defaultLanguage: keyof typeof translations,
720
): (language?: keyof typeof translations) => void {
821
i18n.translations = translations;
922

src/lib/src/utils/i18n/use-translation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { TranslateOptions } from 'i18n-js';
22
import { i18n } from './i18n';
33

4+
/**
5+
* Returns a function bound to a **base namespace** so you can translate keys without repetition.
6+
*
7+
* > Requires `i18n-js`.
8+
*
9+
* @param basePath Translation namespace, e.g. `'ACCOUNT.WELCOME'`.
10+
* @returns Translator function `(key, options?) => string`.
11+
*/
412
export function useTranslation(basePath: string) {
513
return (key: string, options?: TranslateOptions): string => {
614
return i18n.t(`${basePath}.${key}`, options);

0 commit comments

Comments
 (0)