Skip to content

Commit

Permalink
chore: Update example app (#105)
Browse files Browse the repository at this point in the history
Co-authored-by: Elias Lecomte <elias.lecomte@inthepocket.com>
  • Loading branch information
eliaslecomte and Elias Lecomte authored Aug 25, 2020
1 parent b5668a7 commit f4f8444
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 89 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ build/
.gradle
local.properties
*.iml
.classpath
.project
org.eclipse.buildship.core.prefs

# BUCK
buck-out/
Expand Down
57 changes: 47 additions & 10 deletions example/RNWifiReborn/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import React, {useState, useEffect} from 'react';
import { PermissionsAndroid, Button } from 'react-native';
import {
SafeAreaView,
StyleSheet,
Expand All @@ -23,33 +24,68 @@ const App = () => {
const [connected, setConnected] = useState({connected: false, ssid: 'S4N'});
const [ssid, setSsid] = useState('');
const password ="tanenbaum-1981";
const isWep = false;

const wifi = async () => {
const initWifi = async () => {
try {
const ssid = await WifiManager.getCurrentWifiSSID();
setSsid(ssid);
console.log('Your current connected wifi SSID is ' + ssid);
} catch (error) {
setSsid('Cannot get current SSID!' + error.message);
console.log('Cannot get current SSID!', {error});
}
}

const requestLocationPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "React Native Wifi Reborn App Permission",
message:
"Location permission is required to connect with or scan for Wifi networks. ",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
initWifi();
} else {
console.log("Location permission denied");
}
} catch (err) {
console.warn(err);
}
};

const connectWithWifi = async () => {
try {
const data = await WifiManager.connectToProtectedSSID(
ssid,
password,
isWep,
false,
);
console.log('Connected successfully!', {data});
setConnected({connected: true, ssid});
} catch (error) {
setConnected({connected: false, error: error.message});
console.log('Connection failed!', {error});
}
};

const scanExample = async () => {
try {
const ssid = await WifiManager.getCurrentWifiSSID();
setSsid(ssid);
console.log('Your current connected wifi SSID is ' + ssid);
const data = await WifiManager.reScanAndLoadWifiList()
console.log(data);
} catch (error) {
setSsid('Cannot get current SSID!' + error.message);
console.log('Cannot get current SSID!', {error});
console.log(error);
}
};
}


useEffect(() => {
wifi();
requestLocationPermission();
}, []);

return (
Expand All @@ -72,6 +108,7 @@ const App = () => {
{JSON.stringify(connected)}
</Text>
</View>
<Button onPress={connectWithWifi} title="Connect" />
<View style={styles.body}></View>
</ScrollView>
</SafeAreaView>
Expand Down
73 changes: 0 additions & 73 deletions example/RNWifiReborn/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,6 @@ apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
* bundleCommand: "ram-bundle",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/

project.ext.react = [
entryFile: "index.js",
enableHermes: false, // clean and rebuild if changing
Expand Down
6 changes: 3 additions & 3 deletions example/RNWifiReborn/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

buildscript {
ext {
buildToolsVersion = "28.0.3"
buildToolsVersion = "29.0.0"
minSdkVersion = 21
compileSdkVersion = 28
targetSdkVersion = 28
compileSdkVersion = 29
targetSdkVersion = 29
}
repositories {
google()
Expand Down
5 changes: 3 additions & 2 deletions example/RNWifiReborn/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/RNWifiReborn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"react": "16.9.0",
"react-native": "0.61.3",
"react-native-wifi-reborn": "^2.1.2"
"react-native-wifi-reborn": "^4.2.0"
},
"devDependencies": {
"@babel/core": "^7.6.4",
Expand Down

0 comments on commit f4f8444

Please sign in to comment.