-
Notifications
You must be signed in to change notification settings - Fork 84
/
index.js
72 lines (59 loc) · 2.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* @file Magic Weather screen.
* @author Vadim Savin
*/
import React, { useState } from 'react';
import { View, Text, Pressable, Alert } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
import { useNavigation } from '@react-navigation/native';
import { testCold, generateSampleData, Environment } from '../../helpers/SampleData';
import styles from './styles.js';
import Purchases from 'react-native-purchases';
import { ENTITLEMENT_ID } from '../../constants';
/*
The app's weather tab that displays our pretend weather data.
*/
const WeatherScreen = () => {
const [weatherData, setWeatherData] = useState(testCold);
const navigation = useNavigation();
const changeEnvironment = () => {
// we'll change the environment in a future update
console.log('Change environment');
};
const performMagic = async () => {
/*
We should check if we can magically change the weather (subscription active) and if not, display the paywall.
*/
try {
// access latest customerInfo
const customerInfo = await Purchases.getCustomerInfo();
if (typeof customerInfo.entitlements.active[ENTITLEMENT_ID] !== 'undefined') {
setWeatherData(generateSampleData(Environment.EARTH));
} else {
navigation.navigate('Paywall');
}
} catch (e) {
Alert.alert('Error fetching customer info', e.message);
}
};
return (
<View style={[styles.page, { backgroundColor: weatherData.weatherColor }]}>
{/* Sample weather details */}
<Text style={styles.emoji}>{weatherData.emoji}</Text>
<Text style={styles.temperature}>
{weatherData.temperature}°{weatherData.unit.toUpperCase()}️
</Text>
{/* Environment button */}
<Pressable onPress={changeEnvironment}>
<Text style={styles.environment}>
<Ionicons name="navigate" color="white" size={24} /> {weatherData.environment}
</Text>
</Pressable>
{/* The magic button that is disabled behind our paywall */}
<Pressable onPress={performMagic} style={styles.changeWeatherButton}>
<Text style={styles.changeWeatherTitle}>✨ Change the Weather</Text>
</Pressable>
</View>
);
};
export default WeatherScreen;