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

Upgrade to expo 52 #380

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ android {
minSdkVersion 16
targetSdkVersion 31
versionCode 1
versionName '3.20.0'
versionName '3.20.1-beta.1'
consumerProguardFiles 'proguard-rules.pro'
}
lintOptions {
abortOnError false
Expand Down
4 changes: 4 additions & 0 deletions android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-dontwarn com.huawei.**

-dontwarn com.google.android.play.integrity.**
-dontwarn com.google.android.play.core.integrity.**
2 changes: 1 addition & 1 deletion android/src/main/java/io/radar/react/RNRadarModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void initialize(String publishableKey, boolean fraud) {
this.fraud = fraud;
SharedPreferences.Editor editor = getReactApplicationContext().getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit();
editor.putString("x_platform_sdk_type", "ReactNative");
editor.putString("x_platform_sdk_version", "3.20.0");
editor.putString("x_platform_sdk_version", "3.20.1-beta.1");
editor.apply();
if (fraud) {
Radar.initialize(getReactApplicationContext(), publishableKey, receiver, Radar.RadarLocationServicesProvider.GOOGLE, fraud);
Expand Down
17 changes: 14 additions & 3 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Radar, {
} from "react-native-radar";
import MapLibreGL from "@maplibre/maplibre-react-native";
import ExampleButton from "./components/exampleButton";
import * as Location from 'expo-location';
import PermissionsComponent from "./components/PermissionsComponent";

// The current version of MapLibre does not support the new react native architecture
MapLibreGL.setAccessToken(null);
Expand Down Expand Up @@ -38,6 +40,7 @@ Radar.on("log", (result: string) => {
export default function App() {
// add in your test code here!
const [displayText, setDisplayText] = useState("");
const [showPermissionsComponent, setShowPermissionsComponent] = useState(false);

const handlePopulateText = (displayText: string) => {
setDisplayText(displayText);
Expand All @@ -59,9 +62,15 @@ export default function App() {
baz: true,
qux: 1,
});
Location.getForegroundPermissionsAsync().then((status)=> {
if(!status.granted) {
setShowPermissionsComponent(true)
}
})
}, []);

return (
return <>
{showPermissionsComponent ? <PermissionsComponent setShowPermissionsComponent={setShowPermissionsComponent} /> :
<View style={styles.container}>
{/* The current version of MapLibre does not support the new react native architecture */}
{Platform.OS !== "web" && (
Expand Down Expand Up @@ -627,8 +636,10 @@ export default function App() {
/>
</ScrollView>
</View>
</View>
);
</View>}
</>

;
}

const styles = StyleSheet.create({
Expand Down
29 changes: 22 additions & 7 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@
"assetBundlePatterns": [
"**/*"
],
"owner": "radarlabs",
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.radar.example",
"bundleIdentifier": "com.radar.reactnative.example"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"package": "com.radar.example"
"package": "com.radar.reactnative.example",
"permissions": [
"android.permission.ACCESS_BACKGROUND_LOCATION",
"android.permission.FOREGROUND_SERVICE",
"android.permission.FOREGROUND_SERVICE_LOCATION",
"android.permission.ACTIVITY_RECOGNITION"
]
},
"web": {
"favicon": "./assets/favicon.png"
Expand All @@ -35,10 +42,11 @@
"iosFraud": true,
"iosNSLocationAlwaysAndWhenInUseUsageDescription": "test value",
"iosBackgroundMode": true,
"androidFraud": true,
"androidFraud": false,
"androidBackgroundPermission": true,
"androidFineLocationPermission": true,
"addRadarSDKMotion": true
"addRadarSDKMotion": true,
"androidActivityRecognition": true,
"androidForegroundService": true
}
],
[
Expand All @@ -51,10 +59,17 @@
"newArchEnabled": false
},
"android": {
"newArchEnabled": false
"newArchEnabled": false,
"enableProguardInReleaseBuilds": true,
"enableShrinkResourcesInReleaseBuilds": true
}
}
]
]
],
"extra": {
"eas": {
"projectId": "caf6acc9-b3c5-4d95-af29-fd017a05abb8"
}
}
}
}
116 changes: 116 additions & 0 deletions example/components/PermissionsComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, { useState, useEffect } from "react";
import { Text, View, AppState, AppStateStatus } from "react-native";
import * as Location from "expo-location";
import ExampleButton from "./exampleButton";

interface PermissionsComponentProps {
setShowPermissionsComponent: (show: boolean) => void;
}

export default function PermissionsComponent({
setShowPermissionsComponent,
}: PermissionsComponentProps) {
useEffect(() => {
setPermissions();
const subscription = AppState.addEventListener(
"change",
(nextAppState: AppStateStatus) => {
if (nextAppState === "active") {
setPermissions();
}
}
);

// Cleanup function - will be called when component unmounts
return () => {
subscription.remove();
};
}, []);

const [canRequestForegroundPermissions, setCanRequestForegroundPermissions] =
useState(false);
const [canRequestBackgroundPermissions, setCanRequestBackgroundPermissions] =
useState(false);
const [hasForegroundPermissions, setHasForegroundPermissions] =
useState(false);
const [hasBackgroundPermissions, setHasBackgroundPermissions] =
useState(false);

const setPermissions = () => {
(async () => {
const status = await Location.getForegroundPermissionsAsync();
setCanRequestForegroundPermissions(status.canAskAgain);
setHasForegroundPermissions(status.granted);
})();
(async () => {
const status = await Location.getBackgroundPermissionsAsync();
setCanRequestBackgroundPermissions(status.canAskAgain);
setHasBackgroundPermissions(status.granted);
})();
};

return (
<View
style={{
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
}}
>
<ExampleButton
title={"back to main page"}
onPress={() => {
setShowPermissionsComponent(false);
}}
/>

{!hasForegroundPermissions && !canRequestForegroundPermissions && (
<Text>please allow location permissions from the settings screen</Text>
)}
{!hasForegroundPermissions && canRequestForegroundPermissions && (
<ExampleButton
onPress={() => {
Location.requestForegroundPermissionsAsync()
.then((status) => {
setCanRequestForegroundPermissions(status.canAskAgain);
setHasForegroundPermissions(status.granted);
})
.catch((err) => {
console.log(err);
});
}}
title={"request foreground permissions"}
/>
)}
{hasForegroundPermissions &&
!hasBackgroundPermissions &&
!canRequestBackgroundPermissions && (
<Text>
please allow background location permissions from the settings
screen
</Text>
)}
{hasForegroundPermissions &&
!hasBackgroundPermissions &&
canRequestBackgroundPermissions && (
<ExampleButton
onPress={() => {
Location.requestBackgroundPermissionsAsync()
.then((status) => {
setCanRequestBackgroundPermissions(status.canAskAgain);
setHasBackgroundPermissions(status.granted);
})
.catch((err) => {
console.log(err);
});
}}
title={"request background permissions"}
/>
)}
{hasBackgroundPermissions && (
<Text>have background location permissions</Text>
)}
</View>
);
}
18 changes: 18 additions & 0 deletions example/eas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"cli": {
"version": ">= 7.2.0"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal"
},
"preview": {
"distribution": "internal"
},
"production": {}
},
"submit": {
"production": {}
}
}
8 changes: 8 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { registerRootComponent } from 'expo';

import App from './App';

// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
// the environment is set up appropriately
registerRootComponent(App);
7 changes: 7 additions & 0 deletions example/metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');

/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);

module.exports = config;
Loading