Skip to content

Commit 49b241c

Browse files
committed
chore: cleanup examples
1 parent f6937dd commit 49b241c

18 files changed

Lines changed: 300 additions & 116 deletions

File tree

‎README.md‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1+
# StackBlitz Examples
12

3+
The examples are managed on the `main` branch only - the individual flavor branches are automatically updated when pushing to `main`
24

3-
# StackBlitz Templates
5+
Each example is split into it's own folder within apps, for example:
46

5-
The templates are managed on the `main` branch only - the individual flavor branches are automatically updated when pushing to `main`
7+
```
8+
apps/{example}/{flavor}
9+
```
10+
11+
Each example can utilize shared `libs` for their examples to reuse across flavors, for example:
12+
13+
```
14+
libs/nativescript-battery
15+
```
16+
17+
^ is used across all `apps/battery` examples.
18+
19+
## Test them out locally
20+
21+
Since each flavor utilizes it's own node_modules dependencies you want to clean each example before running it, for example:
22+
23+
```
24+
npx nx run battery-angular:clean
25+
```
26+
27+
You can now try out the example:
28+
29+
```
30+
npx nx run battery-angular:ios
31+
```
632

733
> **Warning:** Do not edit the individual flavor branches manually!.
834

‎apps/battery/react/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"dependencies": {
77
"@nativescript/core": "~8.3.0",
88
"@react-navigation/core": "^5.15.3",
9+
"@stackblitz/nativescript-battery": "file:../../../libs/nativescript-battery/src",
910
"react": "~16.13.1",
1011
"react-nativescript": "^3.0.0-beta.1",
1112
"react-nativescript-navigation": "3.0.0-beta.2"
1213
},
1314
"devDependencies": {
15+
"@nativescript/ios": "8.3.3",
1416
"@nativescript/preview-cli": "1.0.0-beta.18",
1517
"@nativescript/stackblitz": "0.0.5",
1618
"@nativescript/types-minimal": "~8.3.0",

‎apps/battery/react/src/app.css‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
11
ActionBar {
22
background-color: #65adf1;
33
color: white;
4+
}
5+
6+
.p-20 {
7+
padding: 20;
8+
}
9+
10+
.m-t-20 {
11+
margin-top: 20;
12+
}
13+
14+
.text-center {
15+
text-align: center;
16+
}
17+
18+
.h1, .h2 {
19+
margin-bottom: 6;
20+
font-weight: normal;
21+
}
22+
23+
.h1 {
24+
font-size: 32;
25+
}
26+
27+
.h2 {
28+
font-size: 22;
29+
}
30+
31+
Button.action-btn {
32+
border-radius: 25;
33+
background-color: rgb(0, 162, 255);
34+
color: white;
35+
font-size: 18;
36+
padding: 5;
437
}

‎apps/battery/react/src/components/HomeScreen.tsx‎

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from "react";
22
import { RouteProp } from '@react-navigation/core';
3-
import { Dialogs } from '@nativescript/core';
43
import { FrameNavigationProp } from "react-nativescript-navigation";
54
import { StyleSheet } from "react-nativescript";
5+
import { checkBatteryLevel, listenForBatteryChanges } from '@stackblitz/nativescript-battery';
66
import { MainStackParamList } from "./NavigationParamList";
77

88
type HomeScreenProps = {
@@ -11,26 +11,45 @@ type HomeScreenProps = {
1111
}
1212

1313
export function HomeScreen({ navigation }: HomeScreenProps) {
14+
15+
const formatMessage = (level: number) => `The Battery Level is: ${level}%`;
16+
17+
let level = 0;
18+
let isListening = false;
19+
20+
async function updateBatteryLevel() {
21+
const value = await checkBatteryLevel();
22+
updateLevel(value);
23+
alert(formatMessage(value));
24+
}
25+
26+
async function toggleListenForChanges() {
27+
isListening = listenForBatteryChanges((value) => {
28+
updateLevel(value);
29+
});
30+
if (isListening) {
31+
// update view binding right away
32+
const value = await checkBatteryLevel();
33+
updateLevel(value);
34+
}
35+
}
36+
37+
function updateLevel(value: number) {
38+
level = value;
39+
}
40+
41+
updateBatteryLevel();
42+
1443
return (
15-
<flexboxLayout style={styles.container}>
16-
<label
17-
style={styles.text}
18-
>
19-
Hello World!
20-
</label>
21-
<button
22-
style={styles.button}
23-
onTap={() => Dialogs.alert("Tapped!")}
24-
>
25-
Tap me for an alert
26-
</button>
27-
<button
28-
style={styles.button}
29-
onTap={() => navigation.navigate('Secondary')}
30-
>
31-
Go to next screen
32-
</button>
33-
</flexboxLayout>
44+
<>
45+
<actionBar title="NativeScript is pretty cool!" />
46+
<stackLayout className="p-20">
47+
<label className="h1 text-center">The Battery Level is:</label>
48+
<label className="h2 text-center">{level ? level + '%' : '---'}</label>
49+
<button className="action-btn" onTap={() => toggleListenForChanges()} text={isListening ? 'Stop Listening to Battery Changes' : 'Listen for battery changes'}></button>
50+
<image src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/React-icon.svg/2300px-React-icon.svg.png" width="200" class="m-t-20"/>
51+
</stackLayout>
52+
</>
3453
);
3554
}
3655

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export type MainStackParamList = {
22
Home: {}
3-
Secondary: {}
43
}

‎apps/battery/react/src/components/Navigator.tsx‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from "react";
22
import { BaseNavigationContainer } from '@react-navigation/core';
33
import { stackNavigatorFactory } from "react-nativescript-navigation";
44
import { HomeScreen } from "./HomeScreen";
5-
import { SecondaryScreen } from "./SecondaryScreen";
65

76
const StackNavigator = stackNavigatorFactory();
87

@@ -21,10 +20,6 @@ export const mainStackNavigator = () => (
2120
name="Home"
2221
component={HomeScreen}
2322
/>
24-
<StackNavigator.Screen
25-
name="Secondary"
26-
component={SecondaryScreen}
27-
/>
2823
</StackNavigator.Navigator>
2924
</BaseNavigationContainer>
3025
);

‎apps/battery/react/src/components/SecondaryScreen.tsx‎

Lines changed: 0 additions & 44 deletions
This file was deleted.

‎apps/battery/react/tsconfig.json‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
"baseUrl": ".",
1313
"paths": {
1414
"~/*": ["src/*"],
15-
"@/*": ["src/*"]
15+
"@/*": ["src/*"],
16+
"@stackblitz/nativescript-battery": [
17+
"../../../libs/nativescript-battery/src/index.ts"
18+
]
1619
}
1720
},
18-
"include": ["./src/**/*.tsx?"],
21+
"include": ["./src/**/*.tsx?", "../../../libs/nativescript-battery/**/*.ios.ts", "../../../libs/nativescript-battery/**/*.android.ts"],
1922
"files": ["./references.d.ts"],
2023
"exclude": ["node_modules", "platforms"]
2124
}

‎apps/battery/svelte/app/app.css‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ ActionBar {
22
background-color: #65adf1;
33
color: white;
44
}
5-
Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,91 @@
11
<page>
2-
<actionBar title="Home" />
3-
<gridLayout>
4-
<label class="info" text="{message}" />
5-
</gridLayout>
6-
</page>
2+
<actionBar title="NativeScript is pretty cool!" />
73

4+
<stackLayout class="p-20">
5+
<label text="The Battery Level is:" class="h1 text-center" />
6+
<label text={level ? level + '%' : '---'} class="h2 text-center" />
7+
<button
8+
text={isListening
9+
? 'Stop Listening to Battery Changes'
10+
: 'Listen for battery changes'}
11+
class="action-btn"
12+
on:tap={toggleListenForChanges}
13+
/>
14+
<image
15+
src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Svelte_Logo.svg/1200px-Svelte_Logo.svg.png"
16+
width="200"
17+
class="m-t-20"
18+
/>
19+
</stackLayout>
20+
</page>
21+
822
<script lang="ts">
9-
let message: string = "Blank Svelte Native App"
23+
import {
24+
checkBatteryLevel,
25+
listenForBatteryChanges,
26+
} from '@stackblitz/nativescript-battery';
27+
28+
const formatMessage = (level: number) => `The Battery Level is: ${level}%`;
29+
30+
let level: number;
31+
let isListening = false;
32+
33+
async function updateBatteryLevel() {
34+
const value = await checkBatteryLevel();
35+
updateLevel(value);
36+
alert(formatMessage(value));
37+
}
38+
39+
async function toggleListenForChanges() {
40+
isListening = listenForBatteryChanges((value) => {
41+
updateLevel(value);
42+
});
43+
if (isListening) {
44+
// update view binding right away
45+
const value = await checkBatteryLevel();
46+
updateLevel(value);
47+
}
48+
}
49+
50+
function updateLevel(value: number) {
51+
level = value;
52+
}
53+
54+
updateBatteryLevel();
1055
</script>
1156

1257
<style>
13-
.info {
14-
font-size: 20;
15-
horizontal-align: center;
16-
vertical-align: center;
17-
}
58+
.p-20 {
59+
padding: 20;
60+
}
61+
62+
.m-t-20 {
63+
margin-top: 20;
64+
}
65+
66+
.text-center {
67+
text-align: center;
68+
}
69+
70+
.h1, .h2 {
71+
margin-bottom: 6;
72+
font-weight: normal;
73+
}
74+
75+
.h1 {
76+
font-size: 32;
77+
}
78+
79+
.h2 {
80+
font-size: 22;
81+
}
82+
83+
Button.action-btn {
84+
border-radius: 25;
85+
background-color: rgb(0, 162, 255);
86+
color: white;
87+
font-size: 18;
88+
padding: 5;
89+
}
90+
1891
</style>

0 commit comments

Comments
 (0)