@boneframework/native-components 1.0.45 → 1.0.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- import {create} from 'apisauce';
1
+ import {ApisauceInstance, create} from 'apisauce';
2
2
 
3
3
  import cache from '../utilities/cache';
4
4
  import settings from '../../../../config/settings';
5
5
  import cacheSettings from '../../../../config/cache';
6
6
 
7
- const apiClient = create({
7
+ const apiClient: ApisauceInstance = create({
8
8
  baseURL: settings.apiUrl
9
9
  });
10
10
 
@@ -1,10 +1,16 @@
1
- import React, {useEffect, useRef} from 'react';
2
- import {View, StyleSheet} from "react-native";
1
+ import React from 'react';
2
+ import { StyleSheet, View } from "react-native";
3
3
 
4
+ import useStyle from "@boneframework/native-components/hooks/useStyle";
4
5
  import Animation from "./Animation";
5
- import useStyle from "../hooks/useStyle";
6
6
 
7
- function ActivityIndicator({ visible = false , type="default", animationSource}) {
7
+ interface ActivityIndicatorProps {
8
+ visible?: boolean;
9
+ type?: 'default' | 'overlay';
10
+ animationSource: string | undefined;
11
+ }
12
+
13
+ function ActivityIndicator({ visible = false , type ="default", animationSource}: ActivityIndicatorProps) {
8
14
  const defaultStyles = useStyle();
9
15
 
10
16
  if (!animationSource) {
@@ -0,0 +1,10 @@
1
+ import ColorContext from "@boneframework/native-components/contexts/colors";
2
+ import { defaultTheme, ThemeColors } from "@boneframework/native-components/contexts/theme";
3
+
4
+ const ColorProvider = ({value, children}: {value?: ThemeColors; children: React.ReactNode}) => {
5
+ return <ColorContext value={value ?? defaultTheme}>
6
+ {children}
7
+ </ColorContext>;
8
+ };
9
+
10
+ export default ColorProvider;
@@ -1,8 +1,9 @@
1
- import React from 'react';
2
- import {SafeAreaView, StyleSheet, View} from "react-native";
3
1
  import Constants from "expo-constants";
2
+ import React from 'react';
3
+ import { StyleSheet, View } from "react-native";
4
+ import { SafeAreaView } from 'react-native-safe-area-context';
4
5
 
5
- function Screen({children, style}) {
6
+ function Screen({children, style}: {children: any, style: any}) {
6
7
  return (
7
8
  <SafeAreaView style={[style, styles.screen]}>
8
9
  <View style={[style, styles.view]}>
@@ -0,0 +1,11 @@
1
+ import { ThemeColors, defaultTheme } from "@boneframework/native-components/contexts/theme";
2
+ import { createContext } from "react";
3
+
4
+ const ColorContext = createContext<ThemeColors>(defaultTheme);
5
+
6
+ type ColorsProviderProps = {
7
+ children: React.ReactNode;
8
+ value: ThemeColors;
9
+ };
10
+
11
+ export default ColorContext;
@@ -0,0 +1,35 @@
1
+ import { createContext } from 'react';
2
+
3
+ type ThemeColors = {
4
+ primary: string;
5
+ secondary: string;
6
+ black: string;
7
+ white: string;
8
+ light: string;
9
+ whitish: string;
10
+ medium: string;
11
+ darkish: string;
12
+ dark: string;
13
+ danger: string;
14
+ bgGradient: string[];
15
+ };
16
+
17
+ const defaultTheme: ThemeColors = {
18
+ primary: '#fc5c65',
19
+ secondary: '#4ecdc4',
20
+ black: '#000',
21
+ white: '#fff',
22
+ light: '#f0f4f4',
23
+ whitish: '#ddd',
24
+ medium: '#999',
25
+ darkish: '#333',
26
+ dark: '#222',
27
+ danger: '#ff5200',
28
+ bgGradient: ['#001C50', '#003698']
29
+ };
30
+
31
+ const ThemeContext = createContext<ThemeColors>(defaultTheme);
32
+
33
+ export default ThemeContext;
34
+ export { defaultTheme, ThemeColors };
35
+
@@ -1,19 +1,19 @@
1
- import {useState} from "react";
1
+ import { useState } from "react";
2
2
 
3
- export default useApi = (apiFunc) => {
3
+ const useApi = (apiFunc: any) => {
4
4
  const [error, setError] = useState(false);
5
5
  const [headers, setHeaders] = useState([]);
6
6
  const [data, setData] = useState([]);
7
7
  const [loading, setLoading] = useState(false);
8
8
 
9
- const request = async (...args) => {
9
+ const request = async (...args: any[]) => {
10
10
  setLoading(true);
11
11
  const response = await apiFunc(...args)
12
- .then(result => {
12
+ .then((result: any) => {
13
13
  setError(!result.ok);
14
14
 
15
15
  return result;
16
- }, reason => {
16
+ }, (reason: any) => {
17
17
  setError(true);
18
18
 
19
19
  return {headers: [], data: reason};
@@ -29,3 +29,5 @@ export default useApi = (apiFunc) => {
29
29
 
30
30
  return {data, error, headers, loading, request}
31
31
  }
32
+
33
+ export default useApi;
package/hooks/useAuth.ts CHANGED
@@ -1,11 +1,8 @@
1
- import {useContext, useState} from "react";
1
+ import { useContext } from "react";
2
2
 
3
3
  import AuthContext from "../contexts/auth";
4
- import authStorage from "../utilities/authStorage";
5
- import useApi from "./useApi";
6
- import usersApi from "../api/users";
7
4
 
8
- export default useAuth = () => {
5
+ const useAuth = () => {
9
6
  const value = useContext(AuthContext);
10
7
 
11
8
  if (process.env.NODE_ENV !== 'production') {
@@ -16,3 +13,5 @@ export default useAuth = () => {
16
13
 
17
14
  return value;
18
15
  }
16
+
17
+ export default useAuth;
@@ -0,0 +1,7 @@
1
+ import cache from '../utilities/cache'
2
+
3
+ const useCache = () => {
4
+ return cache;
5
+ };
6
+
7
+ export default useCache;
@@ -1,8 +1,9 @@
1
1
  import {useEffect} from "react";
2
2
  import { Camera } from 'expo-camera';
3
3
  import * as ImagePicker from "expo-image-picker";
4
+ import {Alert} from "react-native";
4
5
 
5
- export default useCamera = () => {
6
+ const useCamera = () => {
6
7
 
7
8
  const requestPermission = async () => {
8
9
  const { granted } = await Camera.requestCameraPermissionsAsync();
@@ -27,3 +28,5 @@ export default useCamera = () => {
27
28
 
28
29
  return {takePhoto};
29
30
  };
31
+
32
+ export default useCamera;
@@ -0,0 +1,9 @@
1
+ import { useContext } from "react";
2
+
3
+ import ColorContext from "../contexts/colors";
4
+
5
+ const useColors = () => {
6
+ return useContext(ColorContext);
7
+ }
8
+
9
+ export default useColors;
@@ -1,8 +1,8 @@
1
1
  import {useEffect, useState} from "react";
2
2
  import * as Location from "expo-location";
3
3
 
4
- export default useLocation = () => {
5
- const [location, setLocation] = useState();
4
+ const useLocation = () => {
5
+ const [location, setLocation] = useState({});
6
6
 
7
7
  const getLocation = async () => {
8
8
  try {
@@ -27,3 +27,5 @@ export default useLocation = () => {
27
27
 
28
28
  return location;
29
29
  };
30
+
31
+ export default useLocation;
@@ -1,9 +1,8 @@
1
- import {DarkTheme, DefaultTheme} from "@react-navigation/native";
1
+ import { DarkTheme, DefaultTheme } from "@react-navigation/native";
2
2
 
3
- import useStyle from "./useStyle";
4
- import colors from "../../../../config/colors";
3
+ import useStyle from "@boneframework/native-components/hooks/useStyle";
5
4
 
6
- export default useNavigationTheme = () => {
5
+ const useNavigationTheme = () => {
7
6
  const style = useStyle();
8
7
  const theme = style.dark ? DarkTheme : DefaultTheme
9
8
  return {
@@ -17,3 +16,5 @@ export default useNavigationTheme = () => {
17
16
  dark: style.dark
18
17
  }
19
18
  };
19
+
20
+ export default useNavigationTheme
@@ -7,7 +7,7 @@ import Constants from "expo-constants";
7
7
  import expoPushTokensApi from "../api/notifications";
8
8
  import {useStorageState} from "./useStorageState";
9
9
 
10
- export default useNotifications = (notificationReceivedListener = notification => {}) => {
10
+ const useNotifications = (notificationReceivedListener = notification => {}) => {
11
11
  const [[isPushTokenLoading, pushToken], setPushToken] = useStorageState('pushToken');
12
12
 
13
13
  useEffect(() => {
@@ -65,3 +65,5 @@ export default useNotifications = (notificationReceivedListener = notification =
65
65
  }
66
66
  };
67
67
  }
68
+
69
+ export default useNotifications;
@@ -1,10 +1,11 @@
1
1
  import {useEffect} from "react";
2
2
  import * as ImagePicker from "expo-image-picker";
3
+ import {Alert} from "react-native";
3
4
 
4
- export default usePhotos = () => {
5
+ const usePhotos = () => {
5
6
 
6
7
  const requestPermission = async () => {
7
- const { granted} = await ImagePicker.requestMediaLibraryPermissionsAsync();
8
+ const { granted } = await ImagePicker.requestMediaLibraryPermissionsAsync();
8
9
 
9
10
  if (!granted) {
10
11
  Alert.alert(
@@ -26,3 +27,5 @@ export default usePhotos = () => {
26
27
 
27
28
  return {selectImage};
28
29
  };
30
+
31
+ export default usePhotos;
@@ -0,0 +1,54 @@
1
+ import { useState } from "react";
2
+ import { Platform, useColorScheme } from "react-native";
3
+
4
+ import useColors from "./useColors";
5
+
6
+ const useStyle = () => {
7
+ const colorScheme = useColorScheme();
8
+ const [mode, setMode] = useState();
9
+ const dark = colorScheme == 'dark';
10
+ const colors = useColors();
11
+ console.log(colors);
12
+ console.log('xxxxxxx');
13
+
14
+ const style = {
15
+ dark: dark,
16
+ text: {
17
+ color: dark ? colors.light : colors.dark,
18
+ ...Platform.select({
19
+ ios: {
20
+ fontSize: 20,
21
+ fontFamily: "Helvetica",
22
+ },
23
+ android: {
24
+ fontSize: 18,
25
+ fontFamily: "Roboto",
26
+ },
27
+ })
28
+ },
29
+ box: {
30
+ backgroundColor: dark ? colors.darkish : colors.white
31
+ },
32
+ errorText: {
33
+ color: dark ? colors.secondary : colors.primary
34
+ },
35
+ flipswitch: {
36
+ onColor: dark ? colors.secondary : colors.secondary,
37
+ offColor: dark ? colors.darkish : colors.white
38
+ },
39
+ navButton: {
40
+ color: dark ? colors.light : colors.white
41
+ },
42
+ formInput: {
43
+ backgroundColor: dark ? colors.darkish : colors.white,
44
+ text: dark ? colors.light : colors.dark,
45
+ placeholderTextColor: dark ? colors.medium : colors.medium
46
+ },
47
+ backgroundColor: dark ? colors.dark : colors.light,
48
+ colors: colors
49
+ };
50
+
51
+ return style;
52
+ };
53
+
54
+ export default useStyle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boneframework/native-components",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
4
4
  "description": "Expo React Native Components for Bone Framework",
5
5
  "main": "src/Bone.ts",
6
6
  "scripts": {
@@ -31,25 +31,25 @@
31
31
  "dependencies": {
32
32
  "@react-native-async-storage/async-storage": "^2.0.0",
33
33
  "@react-native-community/datetimepicker": "^8.2.0",
34
- "@react-native-community/netinfo": "^11.3.2",
35
- "apisauce": "^3.0.1",
34
+ "@react-native-community/netinfo": "^11.4.1",
35
+ "apisauce": "^3.1.0",
36
36
  "dayjs": "^1.11.13",
37
- "expo-auth-session": "^5.5.2",
38
- "expo-camera": "^15.0.13",
39
- "expo-constants": "^16.0",
40
- "expo-device": "^6.0.2",
41
- "expo-image": "^1.12.13",
42
- "expo-image-picker": "^15.0.7",
43
- "expo-linear-gradient": "~13.0.2",
44
- "expo-location": "~17.0.1",
45
- "expo-notifications": "^0.28.19",
46
- "expo-router": "^3.5.23",
47
- "expo-secure-store": "^13.0.2",
37
+ "expo-auth-session": "^6.0.0",
38
+ "expo-camera": "^16.0.5",
39
+ "expo-constants": "^17.0.3",
40
+ "expo-device": "^7.0.1",
41
+ "expo-image": "^2.0.0",
42
+ "expo-image-picker": "^16.0.2",
43
+ "expo-linear-gradient": "~14.0.1",
44
+ "expo-location": "~18.0.1",
45
+ "expo-notifications": "^0.29.8",
46
+ "expo-router": "^4.0.5",
47
+ "expo-secure-store": "^14.0.0",
48
48
  "formik": "^2.4.6",
49
49
  "jwt-decode": "^4.0.0",
50
- "lottie-react-native": "^7.1.0",
50
+ "lottie-react-native": "^7.3.4",
51
51
  "react": "18.3.1",
52
- "react-native-gesture-handler": "^2.20.2",
52
+ "react-native-gesture-handler": "^2.21.0",
53
53
  "react-native-maps": "^1.20.0",
54
54
  "react-native-progress": "^5.0.1",
55
55
  "toggle-switch-react-native": "^3.3.0",
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "compilerOptions": {},
3
+ "extends": "expo/tsconfig.base"
4
+ }
@@ -1,6 +1,5 @@
1
1
  import * as SecureStore from 'expo-secure-store';
2
2
  import AsyncStorage from "@react-native-async-storage/async-storage";
3
- import jwtDecode from 'jwt-decode';
4
3
 
5
4
  const userKey = 'user';
6
5
  const tokenKey = 'authToken';
@@ -17,19 +16,19 @@ const storeAuthToken = async token => {
17
16
  await storeSecure(tokenKey, token, 'error storing the auth token');
18
17
  };
19
18
 
20
- const getAuthToken = async () => {
19
+ const getAuthToken = async (): Promise<any> => {
21
20
  return await fetchSecure(tokenKey);
22
21
  };
23
22
 
24
- const removeAuthToken = () => {
23
+ const removeAuthToken: () => void = (): void => {
25
24
  removeSecure(tokenKey);
26
25
  }
27
26
 
28
- const removeUser = () => {
27
+ const removeUser: () => void = (): void => {
29
28
  remove(userKey);
30
29
  }
31
30
 
32
- const removeSecure = async key => {
31
+ const removeSecure : (key: string) => Promise<void> = async (key: string): Promise<void> => {
33
32
  try {
34
33
  await SecureStore.deleteItemAsync(key);
35
34
  } catch (error) {
@@ -37,7 +36,7 @@ const removeSecure = async key => {
37
36
  }
38
37
  }
39
38
 
40
- const storeSecure = async (key, value, errorMessage = 'error storing value') => {
39
+ const storeSecure = async (key: string, value, errorMessage = 'error storing value') => {
41
40
  try {
42
41
  await SecureStore.setItemAsync(key, JSON.stringify(value));
43
42
  } catch (error) {
@@ -45,7 +44,7 @@ const storeSecure = async (key, value, errorMessage = 'error storing value') =>
45
44
  }
46
45
  }
47
46
 
48
- const fetchSecure = async key => {
47
+ const fetchSecure = async (key: string): Promise<any> => {
49
48
  try {
50
49
  return JSON.parse(await SecureStore.getItemAsync(key));
51
50
  } catch (error) {
@@ -53,7 +52,7 @@ const fetchSecure = async key => {
53
52
  }
54
53
  }
55
54
 
56
- const store = async (key, value, errorMessage = 'error storing value') => {
55
+ const store = async (key: string, value: any, errorMessage: string = 'error storing value'): Promise<void> => {
57
56
  try {
58
57
  await AsyncStorage.setItem(key, JSON.stringify(value));
59
58
  } catch (error) {
@@ -61,7 +60,7 @@ const store = async (key, value, errorMessage = 'error storing value') => {
61
60
  }
62
61
  }
63
62
 
64
- const fetch = async key => {
63
+ const fetch: (key: string) => Promise<any> = async (key: string): Promise<any> => {
65
64
  try {
66
65
  return JSON.parse(await AsyncStorage.getItem(key));
67
66
  } catch (error) {
@@ -69,7 +68,7 @@ const fetch = async key => {
69
68
  }
70
69
  }
71
70
 
72
- const remove = async key => {
71
+ const remove: (key: string) => Promise<void> = async (key: string): Promise<void> => {
73
72
  try {
74
73
  await AsyncStorage.removeItem(key);
75
74
  } catch (error) {
package/hooks/useCache.js DELETED
@@ -1,7 +0,0 @@
1
- import {useEffect} from "react";
2
-
3
- import cache from '../utility/cache'
4
-
5
- export default useCache = () => {
6
- return cache;
7
- };
package/hooks/useStyle.js DELETED
@@ -1,44 +0,0 @@
1
- import {useEffect, useState} from "react";
2
- import {Platform, useColorScheme} from "react-native";
3
-
4
- import colors from "../../../../config/colors";
5
- import logger from "../utilities/logger";
6
-
7
- export default useStyle = () => {
8
- const colorScheme = useColorScheme();
9
- const [mode, setMode] = useState();
10
- const dark = colorScheme == 'dark'
11
- const style = {
12
- dark: dark,
13
- text: {
14
- color: dark ? colors.light : colors.dark,
15
- ...Platform.select({
16
- ios: {
17
- fontSize: 20,
18
- fontFamily: "Helvetica",
19
- },
20
- android: {
21
- fontSize: 18,
22
- fontFamily: "Roboto",
23
- },
24
- })
25
- },
26
- box: {},
27
- errorText: {},
28
- flipswitch: {},
29
- navButton: {},
30
- formInput: {},
31
- backgroundColor: dark ? colors.dark : colors.light,
32
- colors: colors
33
- };
34
-
35
- style.box.backgroundColor = dark ? style.colors.darkish : style.colors.white;
36
- style.flipswitch.onColor = dark ? style.colors.secondary : style.colors.secondary;
37
- style.flipswitch.offColor = dark ? style.colors.darkish : style.colors.medium;
38
- style.formInput.backgroundColor = dark ? style.colors.darkish : style.colors.white;
39
- style.formInput.text = dark ? style.colors.medium : style.colors.dark;
40
- style.errorText.color = dark ? style.colors.secondary : style.colors.primary;
41
- style.navButton.color = dark ? style.colors.light : style.colors.white;
42
-
43
- return style;
44
- };