expo-battery 6.2.0 → 7.0.0
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.
- package/CHANGELOG.md +14 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/battery/BatteryModule.kt +2 -1
- package/build/ExpoBattery.d.ts +1 -1
- package/build/ExpoBattery.d.ts.map +1 -1
- package/build/ExpoBattery.js +2 -2
- package/build/ExpoBattery.js.map +1 -1
- package/expo-module.config.json +7 -0
- package/ios/BatteryModule.swift +98 -0
- package/ios/{EXBattery.podspec → ExpoBattery.podspec} +11 -4
- package/package.json +3 -3
- package/src/ExpoBattery.ts +2 -2
- package/tsconfig.json +1 -1
- package/ios/EXBattery/EXBattery.h +0 -24
- package/ios/EXBattery/EXBattery.m +0 -157
- package/unimodule.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,20 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 7.0.0 — 2022-10-25
|
|
14
|
+
|
|
15
|
+
### 🛠 Breaking changes
|
|
16
|
+
|
|
17
|
+
- Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
|
|
18
|
+
|
|
19
|
+
### 🎉 New features
|
|
20
|
+
|
|
21
|
+
- Native module on iOS is now written in Swift using the Sweet API. ([#19470](https://github.com/expo/expo/pull/19470) by [@fobos531](https://github.com/fobos531))
|
|
22
|
+
|
|
23
|
+
## 6.3.0 — 2022-07-07
|
|
24
|
+
|
|
25
|
+
_This version does not introduce any user-facing changes._
|
|
26
|
+
|
|
13
27
|
## 6.2.0 — 2022-04-18
|
|
14
28
|
|
|
15
29
|
### ⚠️ Notices
|
package/android/build.gradle
CHANGED
|
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
|
|
|
3
3
|
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '
|
|
6
|
+
version = '7.0.0'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
@@ -74,7 +74,7 @@ android {
|
|
|
74
74
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
75
75
|
targetSdkVersion safeExtGet("targetSdkVersion", 31)
|
|
76
76
|
versionCode 11
|
|
77
|
-
versionName '
|
|
77
|
+
versionName '7.0.0'
|
|
78
78
|
}
|
|
79
79
|
lintOptions {
|
|
80
80
|
abortOnError false
|
|
@@ -12,11 +12,12 @@ import expo.modules.core.Promise
|
|
|
12
12
|
import expo.modules.core.interfaces.ExpoMethod
|
|
13
13
|
import expo.modules.core.interfaces.RegistryLifecycleListener
|
|
14
14
|
import expo.modules.core.interfaces.services.EventEmitter
|
|
15
|
+
import expo.modules.kotlin.types.Enumerable
|
|
15
16
|
|
|
16
17
|
class BatteryModule(context: Context) : ExportedModule(context), RegistryLifecycleListener {
|
|
17
18
|
private val NAME = "ExpoBattery"
|
|
18
19
|
|
|
19
|
-
enum class BatteryState(val value: Int) {
|
|
20
|
+
enum class BatteryState(val value: Int) : Enumerable {
|
|
20
21
|
UNKNOWN(0), UNPLUGGED(1), CHARGING(2), FULL(3);
|
|
21
22
|
}
|
|
22
23
|
|
package/build/ExpoBattery.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoBattery.d.ts","sourceRoot":"","sources":["../src/ExpoBattery.ts"],"names":[],"mappings":";AACA,
|
|
1
|
+
{"version":3,"file":"ExpoBattery.d.ts","sourceRoot":"","sources":["../src/ExpoBattery.ts"],"names":[],"mappings":";AACA,wBAAkD"}
|
package/build/ExpoBattery.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default
|
|
1
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
+
export default requireNativeModule('ExpoBattery');
|
|
3
3
|
//# sourceMappingURL=ExpoBattery.js.map
|
package/build/ExpoBattery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoBattery.js","sourceRoot":"","sources":["../src/ExpoBattery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ExpoBattery.js","sourceRoot":"","sources":["../src/ExpoBattery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,eAAe,mBAAmB,CAAC,aAAa,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\nexport default requireNativeModule('ExpoBattery');\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
let batteryLevelDidChange: String = "Expo.batteryLevelDidChange"
|
|
4
|
+
let batteryStateDidChange: String = "Expo.batteryStateDidChange"
|
|
5
|
+
let powerModeDidChange: String = "Expo.powerModeDidChange"
|
|
6
|
+
|
|
7
|
+
public class BatteryModule: Module {
|
|
8
|
+
public func definition() -> ModuleDefinition {
|
|
9
|
+
Name("ExpoBattery")
|
|
10
|
+
|
|
11
|
+
Constants([
|
|
12
|
+
"isSupported": isSupported()
|
|
13
|
+
])
|
|
14
|
+
|
|
15
|
+
Events(batteryLevelDidChange, batteryStateDidChange, powerModeDidChange)
|
|
16
|
+
|
|
17
|
+
AsyncFunction("getBatteryLevelAsync") { () -> Float in
|
|
18
|
+
return UIDevice.current.batteryLevel
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
AsyncFunction("isLowPowerModeEnabledAsync") { () -> Bool in
|
|
22
|
+
return ProcessInfo.processInfo.isLowPowerModeEnabled
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
AsyncFunction("getBatteryStateAsync") { () -> Int in
|
|
26
|
+
// Apple's enum values directly correspond to Expo's
|
|
27
|
+
// enum values for battery state and are in sync, so
|
|
28
|
+
// we can return the rawValue from Apple's enum directly
|
|
29
|
+
return UIDevice.current.batteryState.rawValue
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
OnCreate {
|
|
33
|
+
UIDevice.current.isBatteryMonitoringEnabled = true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
OnDestroy {
|
|
37
|
+
UIDevice.current.isBatteryMonitoringEnabled = false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
OnStartObserving {
|
|
41
|
+
NotificationCenter.default.addObserver(
|
|
42
|
+
self,
|
|
43
|
+
selector: #selector(self.batteryLevelListener),
|
|
44
|
+
name: UIDevice.batteryLevelDidChangeNotification,
|
|
45
|
+
object: nil
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
NotificationCenter.default.addObserver(
|
|
49
|
+
self,
|
|
50
|
+
selector: #selector(self.batteryStateListener),
|
|
51
|
+
name: UIDevice.batteryStateDidChangeNotification,
|
|
52
|
+
object: nil
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
NotificationCenter.default.addObserver(
|
|
56
|
+
self,
|
|
57
|
+
selector: #selector(self.powerModeListener),
|
|
58
|
+
name: Notification.Name.NSProcessInfoPowerStateDidChange,
|
|
59
|
+
object: nil
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
OnStopObserving {
|
|
64
|
+
NotificationCenter.default.removeObserver(self, name: UIDevice.batteryLevelDidChangeNotification, object: nil)
|
|
65
|
+
NotificationCenter.default.removeObserver(self, name: UIDevice.batteryStateDidChangeNotification, object: nil)
|
|
66
|
+
NotificationCenter.default.removeObserver(self, name: Notification.Name.NSProcessInfoPowerStateDidChange, object: nil)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@objc
|
|
71
|
+
func batteryLevelListener() {
|
|
72
|
+
sendEvent(batteryLevelDidChange, [
|
|
73
|
+
"batteryLevel": UIDevice.current.batteryLevel
|
|
74
|
+
])
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@objc
|
|
78
|
+
func batteryStateListener() {
|
|
79
|
+
sendEvent(batteryStateDidChange, [
|
|
80
|
+
"batteryState": UIDevice.current.batteryState.rawValue
|
|
81
|
+
])
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@objc
|
|
85
|
+
func powerModeListener() {
|
|
86
|
+
sendEvent(powerModeDidChange, [
|
|
87
|
+
"lowPowerMode": ProcessInfo.processInfo.isLowPowerModeEnabled
|
|
88
|
+
])
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
func isSupported() -> Bool {
|
|
93
|
+
#if targetEnvironment(simulator)
|
|
94
|
+
return false
|
|
95
|
+
#else
|
|
96
|
+
return true
|
|
97
|
+
#endif
|
|
98
|
+
}
|
|
@@ -3,23 +3,30 @@ require 'json'
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
|
-
s.name = '
|
|
6
|
+
s.name = 'ExpoBattery'
|
|
7
7
|
s.version = package['version']
|
|
8
8
|
s.summary = package['description']
|
|
9
9
|
s.description = package['description']
|
|
10
10
|
s.license = package['license']
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.homepage = package['homepage']
|
|
13
|
-
s.platform = :ios, '
|
|
13
|
+
s.platform = :ios, '13.0'
|
|
14
|
+
s.swift_version = '5.4'
|
|
14
15
|
s.source = { git: 'https://github.com/expo/expo.git' }
|
|
15
16
|
s.static_framework = true
|
|
16
17
|
|
|
17
18
|
s.dependency 'ExpoModulesCore'
|
|
18
19
|
|
|
20
|
+
# Swift/Objective-C compatibility
|
|
21
|
+
s.pod_target_xcconfig = {
|
|
22
|
+
'DEFINES_MODULE' => 'YES',
|
|
23
|
+
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
|
|
20
|
-
s.source_files = "
|
|
27
|
+
s.source_files = "**/*.h"
|
|
21
28
|
s.vendored_frameworks = "#{s.name}.xcframework"
|
|
22
29
|
else
|
|
23
|
-
s.source_files = "
|
|
30
|
+
s.source_files = "**/*.{h,m,swift}"
|
|
24
31
|
end
|
|
25
32
|
end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-battery",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Provides battery information for the physical device, as well as corresponding event listeners.",
|
|
5
5
|
"main": "build/Battery.js",
|
|
6
6
|
"types": "build/Battery.d.ts",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"homepage": "https://docs.expo.dev/versions/latest/sdk/battery/",
|
|
32
32
|
"dependencies": {},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"expo-module-scripts": "^
|
|
34
|
+
"expo-module-scripts": "^3.0.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"expo": "*"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "eab2b09c735fb0fc2bf734a3f29a6593adba3838"
|
|
40
40
|
}
|
package/src/ExpoBattery.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default
|
|
1
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
+
export default requireNativeModule('ExpoBattery');
|
package/tsconfig.json
CHANGED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Copyright © 2018 650 Industries. All rights reserved.
|
|
2
|
-
|
|
3
|
-
#import <ExpoModulesCore/EXExportedModule.h>
|
|
4
|
-
#import <ExpoModulesCore/EXModuleRegistryConsumer.h>
|
|
5
|
-
#import <Foundation/Foundation.h>
|
|
6
|
-
#import <ExpoModulesCore/EXEventEmitter.h>
|
|
7
|
-
#import <ExpoModulesCore/EXEventEmitterService.h>
|
|
8
|
-
|
|
9
|
-
NS_ASSUME_NONNULL_BEGIN
|
|
10
|
-
|
|
11
|
-
// Keep this enum in sync with JavaScript
|
|
12
|
-
typedef NS_ENUM(NSInteger, EXBatteryState) {
|
|
13
|
-
EXBatteryStateUnknown = 0,
|
|
14
|
-
EXBatteryStateUnplugged,
|
|
15
|
-
EXBatteryStateCharging,
|
|
16
|
-
EXBatteryStateFull
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@interface EXBattery : EXExportedModule <EXModuleRegistryConsumer, EXEventEmitter>
|
|
21
|
-
|
|
22
|
-
@end
|
|
23
|
-
|
|
24
|
-
NS_ASSUME_NONNULL_END
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
|
-
|
|
3
|
-
#import <EXBattery/EXBattery.h>
|
|
4
|
-
#import <ExpoModulesCore/EXUtilities.h>
|
|
5
|
-
|
|
6
|
-
@interface EXBattery ()
|
|
7
|
-
|
|
8
|
-
@property (nonatomic, weak) EXModuleRegistry *moduleRegistry;
|
|
9
|
-
@property (nonatomic, weak) id <EXEventEmitterService> eventEmitter;
|
|
10
|
-
@property (nonatomic, assign) BOOL hasListeners;
|
|
11
|
-
@property (nonatomic, readonly) EXBatteryState batteryState;
|
|
12
|
-
|
|
13
|
-
@end
|
|
14
|
-
|
|
15
|
-
@implementation EXBattery
|
|
16
|
-
|
|
17
|
-
EX_EXPORT_MODULE(ExpoBattery);
|
|
18
|
-
|
|
19
|
-
- (NSDictionary *)constantsToExport
|
|
20
|
-
{
|
|
21
|
-
BOOL _isSupported = YES;
|
|
22
|
-
|
|
23
|
-
#if TARGET_OS_SIMULATOR
|
|
24
|
-
_isSupported = NO;
|
|
25
|
-
#endif
|
|
26
|
-
|
|
27
|
-
return @{ @"isSupported": @(_isSupported) };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
- (dispatch_queue_t)methodQueue
|
|
31
|
-
{
|
|
32
|
-
return dispatch_get_main_queue();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
- (void)setModuleRegistry:(EXModuleRegistry *)moduleRegistry
|
|
36
|
-
{
|
|
37
|
-
if (_moduleRegistry) {
|
|
38
|
-
[self invalidate];
|
|
39
|
-
}
|
|
40
|
-
_moduleRegistry = moduleRegistry;
|
|
41
|
-
_eventEmitter = [moduleRegistry getModuleImplementingProtocol:@protocol(EXEventEmitterService)];
|
|
42
|
-
|
|
43
|
-
if (moduleRegistry) {
|
|
44
|
-
UIDevice.currentDevice.batteryMonitoringEnabled = YES;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
- (NSArray<NSString *> *)supportedEvents
|
|
49
|
-
{
|
|
50
|
-
return @[@"Expo.batteryLevelDidChange", @"Expo.batteryStateDidChange", @"Expo.powerModeDidChange"];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
- (void)startObserving
|
|
54
|
-
{
|
|
55
|
-
_hasListeners = YES;
|
|
56
|
-
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
57
|
-
selector:@selector(batteryLevelDidChange:)
|
|
58
|
-
name:UIDeviceBatteryLevelDidChangeNotification
|
|
59
|
-
object:nil];
|
|
60
|
-
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
61
|
-
selector:@selector(batteryStateDidChange:)
|
|
62
|
-
name:UIDeviceBatteryStateDidChangeNotification
|
|
63
|
-
object:nil];
|
|
64
|
-
|
|
65
|
-
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
66
|
-
selector:@selector(powerModeDidChange:)
|
|
67
|
-
name:NSProcessInfoPowerStateDidChangeNotification
|
|
68
|
-
object:nil];
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
- (void)stopObserving
|
|
73
|
-
{
|
|
74
|
-
_hasListeners = NO;
|
|
75
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
76
|
-
name:UIDeviceBatteryLevelDidChangeNotification
|
|
77
|
-
object:nil];
|
|
78
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
79
|
-
name:UIDeviceBatteryStateDidChangeNotification
|
|
80
|
-
object:nil];
|
|
81
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
82
|
-
name:NSProcessInfoPowerStateDidChangeNotification
|
|
83
|
-
object:nil];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
- (void)invalidate
|
|
87
|
-
{
|
|
88
|
-
_eventEmitter = nil;
|
|
89
|
-
UIDevice.currentDevice.batteryMonitoringEnabled = NO;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Called at most once every minute
|
|
93
|
-
- (void)batteryLevelDidChange:(NSNotification *)notification
|
|
94
|
-
{
|
|
95
|
-
if (!_hasListeners) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
NSDictionary *result = @{@"batteryLevel": @(UIDevice.currentDevice.batteryLevel)};
|
|
99
|
-
[_eventEmitter sendEventWithName:@"Expo.batteryLevelDidChange" body:result];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
- (void)batteryStateDidChange:(NSNotification *)notification
|
|
103
|
-
{
|
|
104
|
-
if (!_hasListeners) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
NSDictionary *result = @{@"batteryState": @(self.batteryState)};
|
|
108
|
-
[_eventEmitter sendEventWithName:@"Expo.batteryStateDidChange" body:result];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
- (void)powerModeDidChange:(NSNotification *)notification
|
|
113
|
-
{
|
|
114
|
-
if(!_hasListeners) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
NSDictionary *result = @{@"lowPowerMode": @(NSProcessInfo.processInfo.isLowPowerModeEnabled)};
|
|
118
|
-
[_eventEmitter sendEventWithName:@"Expo.powerModeDidChange" body:result];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
EX_EXPORT_METHOD_AS(getBatteryLevelAsync,
|
|
122
|
-
getBatteryLevelAsyncWithResolver:(EXPromiseResolveBlock)resolve
|
|
123
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
124
|
-
{
|
|
125
|
-
resolve(@(UIDevice.currentDevice.batteryLevel));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
EX_EXPORT_METHOD_AS(getBatteryStateAsync,
|
|
129
|
-
getBatteryStateAsyncWithResolver:(EXPromiseResolveBlock)resolve rejecter:(EXPromiseRejectBlock)reject)
|
|
130
|
-
{
|
|
131
|
-
resolve(@([self batteryState]));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
EX_EXPORT_METHOD_AS(isLowPowerModeEnabledAsync,
|
|
135
|
-
isLowPowerModeEnabledAsyncWithResolver:(EXPromiseResolveBlock)resolve
|
|
136
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
137
|
-
{
|
|
138
|
-
resolve(@(NSProcessInfo.processInfo.isLowPowerModeEnabled));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
- (EXBatteryState)batteryState
|
|
142
|
-
{
|
|
143
|
-
switch (UIDevice.currentDevice.batteryState) {
|
|
144
|
-
case UIDeviceBatteryStateUnknown:
|
|
145
|
-
return EXBatteryStateUnknown;
|
|
146
|
-
case UIDeviceBatteryStateUnplugged:
|
|
147
|
-
return EXBatteryStateUnplugged;
|
|
148
|
-
case UIDeviceBatteryStateCharging:
|
|
149
|
-
return EXBatteryStateCharging;
|
|
150
|
-
case UIDeviceBatteryStateFull:
|
|
151
|
-
return EXBatteryStateFull;
|
|
152
|
-
default:
|
|
153
|
-
return EXBatteryStateUnknown;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
@end
|
package/unimodule.json
DELETED