@boneframework/native-components 1.0.19 → 1.0.22

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,9 +1,11 @@
1
1
  import client from './client';
2
2
 
3
+ const register = pushToken => client.post('/api/notifications/register-token', {token: pushToken});
4
+
3
5
  const send = (message, data) => {
4
6
  return client.post('/api/notifications/send-notification', {message, data})
5
7
  };
6
8
 
7
9
  export default {
8
- send
10
+ register, send
9
11
  };
@@ -1,14 +1,13 @@
1
1
  import React from 'react';
2
2
  import {StyleSheet, TouchableWithoutFeedback, View} from "react-native";
3
- import {Image} from 'react-native-expo-image-cache';
3
+ import Image from './Image';
4
4
 
5
5
  import Text from './Text'
6
6
  import colors from '../../../../config/colors'
7
7
  import useStyle from "../hooks/useStyle";
8
8
 
9
- function Card({title, subtitle, imageUrl, onPress, thumbnaiilUrl}) {
9
+ function Card({title, subtitle, imageUrl, onPress, thumbnailUrl}) {
10
10
  const style = useStyle();
11
-
12
11
  const styles = StyleSheet.create({
13
12
  card: {
14
13
  borderRadius: 15,
@@ -37,7 +36,7 @@ function Card({title, subtitle, imageUrl, onPress, thumbnaiilUrl}) {
37
36
  <Image
38
37
  style={styles.image}
39
38
  uri={imageUrl}
40
- preview={{uri: thumbnaiilUrl}}
39
+ preview={{uri: thumbnailUrl}}
41
40
  tint={'light'}
42
41
  />
43
42
  <View style={styles.detailsContainer}>
@@ -1,10 +1,10 @@
1
- import React, {useContext, useEffect, useState} from 'react';
2
- import {Image as RNImage, StyleSheet, View} from "react-native";
1
+ import {StyleSheet, View} from "react-native";
2
+ import {Image as ExpoImage} from "expo-image";
3
3
 
4
4
  import useAuth from "../hooks/useAuth";
5
5
  import settings from '../../../../config/api';
6
6
 
7
- function Image({style, uri, onPress, handleError, source}) {
7
+ function Image({style, uri, onPress, handleError, source, ...rest}) {
8
8
  const {user} = useAuth();
9
9
 
10
10
  const tryAgain = async error => {
@@ -39,11 +39,12 @@ function Image({style, uri, onPress, handleError, source}) {
39
39
 
40
40
  if ((null !== user.authToken.accessToken && protectedUri == true) || protectedUri == false) {
41
41
  return (
42
- <RNImage
42
+ <ExpoImage
43
43
  source={imageSource}
44
44
  style={style}
45
45
  onError={tryAgain}
46
- ></RNImage>
46
+ {...rest}
47
+ ></ExpoImage>
47
48
  );
48
49
  }
49
50
  }
@@ -1,7 +1,6 @@
1
1
  import React, {useEffect, useState} from 'react';
2
2
 
3
3
  import AuthContext from "@boneframework/native-components/contexts/auth";
4
- import useAuth from "@boneframework/native-components/hooks/useAuth";
5
4
  import {useSecureStorageState} from "@boneframework/native-components/hooks/useSecureStorageState";
6
5
  import {useStorageState} from "@boneframework/native-components/hooks/useStorageState";
7
6
  import authStorage from "@boneframework/native-components/utilities/authStorage";
@@ -16,7 +15,7 @@ function SessionProvider(props: object) {
16
15
 
17
16
  useEffect(() => {
18
17
  setIsLoading(profileApi.loading || isAuthTokenLoading || isUserLoading);
19
- }, [profileApi.loading || isAuthTokenLoading || isUserLoading]);
18
+ }, [profileApi.loading, isAuthTokenLoading, isUserLoading]);
20
19
 
21
20
 
22
21
  return (
@@ -30,11 +29,6 @@ function SessionProvider(props: object) {
30
29
  setAuthToken(authToken)
31
30
  await setUser(userProfile.data);
32
31
  setIsLoading(false);
33
- console.log('token : ', authToken)
34
- console.log('user : ', user)
35
- console.log('profile : ', userProfile.data)
36
- console.log('user : ', user)
37
-
38
32
  });
39
33
  },
40
34
  logout: () => {
package/contexts/auth.ts CHANGED
@@ -5,7 +5,7 @@ const AuthContext = createContext<{
5
5
  logout: () => void;
6
6
  updateUser: () => void;
7
7
  user?: object | null;
8
- isLoading: bool;
8
+ isLoading: boolean;
9
9
  }>({
10
10
  login: () => null,
11
11
  logout: () => null,
@@ -1,10 +1,15 @@
1
1
  import * as Device from "expo-device";
2
2
  import * as Notifications from "expo-notifications";
3
- import expoPushTokensApi from "../api/expoPushTokens";
4
3
  import {useEffect} from "react";
5
- import router from "../navigation/rootNavigation";
4
+ import {Platform} from "react-native";
5
+ import Constants from "expo-constants";
6
+
7
+ import expoPushTokensApi from "../api/notifications";
8
+ import {useStorageState} from "./useStorageState";
6
9
 
7
10
  export default useNotifications = (notificationReceivedListener = notification => {}) => {
11
+ const [[isPushTokenLoading, pushToken], setPushToken] = useStorageState('pushToken');
12
+
8
13
  useEffect(() => {
9
14
  registerForPushNotifications();
10
15
  Notifications.addNotificationReceivedListener(notification => {
@@ -14,6 +19,17 @@ export default useNotifications = (notificationReceivedListener = notification =
14
19
 
15
20
  const registerForPushNotifications = () => registerForPushNotificationsAsync();
16
21
 
22
+ const handleRegistrationError = (errorMessage: string) => {
23
+ alert(errorMessage);
24
+ throw new Error(errorMessage);
25
+ }
26
+
27
+ const projectId = Constants?.expoConfig?.extra?.eas?.projectId ?? Constants?.easConfig?.projectId;
28
+
29
+ if (!projectId) {
30
+ handleRegistrationError('Project ID not found');
31
+ }
32
+
17
33
  const registerForPushNotificationsAsync = async () => {
18
34
  if (Device.isDevice) {
19
35
  const { status: existingStatus } = await Notifications.getPermissionsAsync();
@@ -26,8 +42,15 @@ export default useNotifications = (notificationReceivedListener = notification =
26
42
  if (finalStatus !== 'granted') {
27
43
  return;
28
44
  }
29
- const token = (await Notifications.getExpoPushTokenAsync()).data;
30
- expoPushTokensApi.register(token);
45
+ const token = (await Notifications.getExpoPushTokenAsync({
46
+ projectId,
47
+ })).data;
48
+
49
+ if (!isPushTokenLoading && pushToken !== token) {
50
+ setPushToken(token)
51
+ expoPushTokensApi.register(token);
52
+ }
53
+
31
54
  } else {
32
55
  alert('Must use physical device for Push Notifications');
33
56
  }
@@ -41,9 +41,9 @@ export function useSecureStorageState(key: string): UseStateHook<string> {
41
41
  // Public
42
42
  const [state, setState] = useAsyncState<string|object>();
43
43
 
44
- const isJson = () => {
44
+ const isJson = value => {
45
45
  try {
46
- const result = JSON.parse(str);
46
+ const result = JSON.parse(value);
47
47
  const type = Object.prototype.toString.call(result);
48
48
  return type === '[object Object]'
49
49
  || type === '[object Array]';
@@ -57,7 +57,7 @@ export function useSecureStorageState(key: string): UseStateHook<string> {
57
57
  if (Platform.OS === 'web') {
58
58
  try {
59
59
  if (typeof localStorage !== 'undefined') {
60
- value = localStorage.getItem(key);
60
+ let value = localStorage.getItem(key);
61
61
 
62
62
  if (isJson(value)) {
63
63
  value = JSON.parse(value);
@@ -69,15 +69,12 @@ export function useSecureStorageState(key: string): UseStateHook<string> {
69
69
  console.error('Local storage is unavailable:', e);
70
70
  }
71
71
  } else {
72
- console.log('fetching ' + key);
73
72
  SecureStore.getItemAsync(key).then(value => {
74
- console.log('value', value)
75
73
  if (isJson(value)) {
76
74
  value = JSON.parse(value);
77
75
  }
78
76
 
79
- setState(value);
80
- console.log('state ', state)
77
+ setState(false, value);
81
78
  });
82
79
  }
83
80
  }, [key]);
@@ -40,9 +40,9 @@ export async function setStorageItemAsync(key: string, value: object | string |
40
40
  }
41
41
 
42
42
  export function useStorageState(key: string): UseStateHook<string> {
43
- const isJson = () => {
43
+ const isJson = value => {
44
44
  try {
45
- const result = JSON.parse(str);
45
+ const result = JSON.parse(value);
46
46
  const type = Object.prototype.toString.call(result);
47
47
  return type === '[object Object]'
48
48
  || type === '[object Array]';
@@ -58,7 +58,7 @@ export function useStorageState(key: string): UseStateHook<string> {
58
58
  if (Platform.OS === 'web') {
59
59
  try {
60
60
  if (typeof localStorage !== 'undefined') {
61
- value = localStorage.getItem(key);
61
+ let value = localStorage.getItem(key);
62
62
 
63
63
  if (isJson(value)) {
64
64
  value = JSON.parse(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boneframework/native-components",
3
- "version": "1.0.19",
3
+ "version": "1.0.22",
4
4
  "description": "Expo Components for Bone Framework",
5
5
  "main": "src/Bone.ts",
6
6
  "scripts": {
@@ -35,6 +35,7 @@
35
35
  "apisauce": "^3.0.1",
36
36
  "expo-auth-session": "^5.5.2",
37
37
  "expo-camera": "^15.0.13",
38
+ "expo-constants": "^16.0",
38
39
  "expo-device": "^6.0.2",
39
40
  "expo-image": "^1.12.13",
40
41
  "expo-image-picker": "^15.0.7",
@@ -1,10 +1,10 @@
1
+ import ActivityIndicator from "@boneframework/native-components/components/ActivityIndicator";
2
+ import {exchangeCodeAsync, makeRedirectUri, useAuthRequest} from "expo-auth-session";
1
3
  import React from 'react';
2
4
  import {Image, ImageBackground, StyleSheet, Text, View} from "react-native";
3
- import {exchangeCodeAsync, makeRedirectUri, useAuthRequest} from "expo-auth-session";
4
5
 
5
6
  import Button from '../components/Button'
6
7
  import colors from '../../../../config/colors'
7
- import ActivityIndicator from "@boneframework/native-components/components/ActivityIndicator";
8
8
 
9
9
  function WelcomeScreen({loginOnPress = () => {}, registerOnPress = () => {}, title = 'BONE FRAMEWORK', isLoading = false}) {
10
10
  return (
@@ -1,8 +1,6 @@
1
1
  // import Bugsnag from '@bugsnag/expo';
2
2
  // or sentry, whatever
3
3
 
4
- import {object} from "prop-types";
5
-
6
4
  const log = (message: any) => {
7
5
  console.log(message);
8
6
  // Bugsnag.notify(error);
@@ -1,7 +0,0 @@
1
- import client from './client';
2
-
3
- const register = pushToken => client.post('/api/notifications/register-token', {token: pushToken});
4
-
5
- export default {
6
- register,
7
- }