@hiloenergie/capacitor-plugin-safe-area 0.0.13 → 8.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.
@@ -1,17 +1,17 @@
1
- require 'json'
2
-
3
- package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
-
5
- Pod::Spec.new do |s|
6
- s.name = 'HiloenergieCapacitorPluginSafeArea'
7
- s.version = package['version']
8
- s.summary = package['description']
9
- s.license = package['license']
10
- s.homepage = package['repository']['url']
11
- s.author = package['author']
12
- s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
- s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '14.0'
15
- s.dependency 'Capacitor'
16
- s.swift_version = '5.1'
17
- end
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'HiloenergieCapacitorPluginSafeArea'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '14.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
@@ -1,58 +1,58 @@
1
- ext {
2
- junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
- }
7
-
8
- buildscript {
9
- repositories {
10
- google()
11
- mavenCentral()
12
- }
13
- dependencies {
14
- classpath 'com.android.tools.build:gradle:8.7.2'
15
- }
16
- }
17
-
18
- apply plugin: 'com.android.library'
19
-
20
- android {
21
- namespace "com.getcapacitor.community.plugins.safearea"
22
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
23
- defaultConfig {
24
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
25
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
26
- versionCode 1
27
- versionName "1.0"
28
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
- }
30
- buildTypes {
31
- release {
32
- minifyEnabled false
33
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
- }
35
- }
36
- lintOptions {
37
- abortOnError false
38
- }
39
- compileOptions {
40
- sourceCompatibility JavaVersion.VERSION_21
41
- targetCompatibility JavaVersion.VERSION_21
42
- }
43
- }
44
-
45
- repositories {
46
- google()
47
- mavenCentral()
48
- }
49
-
50
-
51
- dependencies {
52
- implementation fileTree(dir: 'libs', include: ['*.jar'])
53
- implementation project(':capacitor-android')
54
- implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
- testImplementation "junit:junit:$junitVersion"
56
- androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
- androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
- }
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.13.0'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace = "com.getcapacitor.community.plugins.safearea"
22
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_21
41
+ targetCompatibility JavaVersion.VERSION_21
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
47
+ mavenCentral()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ testImplementation "junit:junit:$junitVersion"
56
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+ }
@@ -1,2 +1,2 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
- </manifest>
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -1,158 +1,150 @@
1
- package com.getcapacitor.community.plugins.safearea;
2
-
3
- import android.annotation.SuppressLint;
4
- import android.graphics.Insets;
5
- import android.os.Build;
6
- import android.view.DisplayCutout;
7
- import android.view.View;
8
- import android.view.ViewGroup;
9
- import android.view.WindowInsets;
10
- import android.widget.FrameLayout;
11
-
12
- import com.getcapacitor.JSObject;
13
- import com.getcapacitor.Plugin;
14
- import com.getcapacitor.PluginCall;
15
- import com.getcapacitor.PluginMethod;
16
- import com.getcapacitor.annotation.CapacitorPlugin;
17
-
18
- @CapacitorPlugin(name = "SafeArea")
19
- public class SafeAreaPlugin extends Plugin {
20
- private static final String KEY_INSET = "insets";
21
- private static final String EVENT_ON_INSETS_CHANGED = "safeAreaPluginsInsetChange";
22
- private SafeAreaInsets safeAreaInsets = new com.getcapacitor.community.plugins.safearea.SafeAreaInsets();
23
- private SafeAreaView safeAreaView;
24
-
25
- @Override
26
- public void load() {
27
- this.getBridge().getActivity().runOnUiThread(() -> {
28
- safeAreaView = new SafeAreaView(this.getBridge().getActivity(), (WindowInsets insets) -> {
29
- this.getSafeArea(insets);
30
- this.doNotify();
31
- });
32
-
33
- FrameLayout.LayoutParams safeAreaPreviewParams = new FrameLayout.LayoutParams(
34
- FrameLayout.LayoutParams.MATCH_PARENT,
35
- FrameLayout.LayoutParams.MATCH_PARENT
36
- );
37
-
38
- // Set SafeAreaView as sibling View of WebView
39
- ((ViewGroup) this.getBridge().getWebView().getParent()).addView(safeAreaView, safeAreaPreviewParams);
40
-
41
- // Bring the WebView in front of the SafeAreaView
42
- this.getBridge().getWebView().bringToFront();
43
- });
44
- }
45
-
46
- @PluginMethod
47
- public void refresh(PluginCall call) {
48
- this.doNotify();
49
- call.resolve();
50
- }
51
-
52
- @PluginMethod
53
- public void getSafeAreaInsets(PluginCall call) {
54
- JSObject ret = new JSObject();
55
-
56
- ret.put(SafeAreaPlugin.KEY_INSET, this.safeAreaInsets.toJSON());
57
-
58
- call.resolve(ret);
59
- }
60
-
61
- protected void getSafeArea(WindowInsets windowInsets) {
62
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
63
- this.getSafeAreaR(windowInsets);
64
- } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
65
- this.getSafeAreaQ(windowInsets);
66
- } else {
67
- this.getSafeAreaLollipop(windowInsets);
68
- }
69
-
70
- // Cutout
71
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
72
- this.getSafeAreaCutout(windowInsets);
73
- }
74
-
75
- float density = this.getBridge().getActivity().getResources().getDisplayMetrics().density;
76
-
77
- this.applySafeAreaInsets(
78
- Math.round(this.safeAreaInsets.top() / density),
79
- Math.round(this.safeAreaInsets.bottom() / density),
80
- Math.round(this.safeAreaInsets.left() / density),
81
- Math.round(this.safeAreaInsets.right() / density)
82
- );
83
- }
84
-
85
- // api level 30
86
- // Get insets (Mandatory System Gestures: https://developer.android.com/reference/android/view/WindowInsets#getMandatorySystemGestureInsets())
87
- @SuppressLint("NewApi")
88
- protected void getSafeAreaR(WindowInsets windowInsets) {
89
- Insets finalInsets = windowInsets.getInsets(WindowInsets.Type.mandatorySystemGestures());
90
-
91
- this.applySafeAreaInsets(
92
- finalInsets.top,
93
- finalInsets.bottom,
94
- finalInsets.left,
95
- finalInsets.right
96
- );
97
- }
98
-
99
- // api level 29
100
- @SuppressLint("NewApi")
101
- protected void getSafeAreaQ(WindowInsets windowInsets) {
102
- Insets finalInsets = windowInsets.getMandatorySystemGestureInsets();
103
-
104
- this.applySafeAreaInsets(
105
- finalInsets.top,
106
- finalInsets.bottom,
107
- finalInsets.left,
108
- finalInsets.right
109
- );
110
- }
111
-
112
- // api level 21
113
- protected void getSafeAreaLollipop(WindowInsets windowInsets) {
114
- this.applySafeAreaInsets(
115
- windowInsets.getSystemWindowInsetTop(),
116
- windowInsets.getStableInsetBottom(),
117
- windowInsets.getStableInsetLeft(),
118
- windowInsets.getStableInsetRight()
119
- );
120
- }
121
-
122
- // cutout (api level >= 28)
123
- @SuppressLint("NewApi")
124
- protected void getSafeAreaCutout(WindowInsets windowInsets) {
125
- DisplayCutout cutout = windowInsets.getDisplayCutout();
126
- if (cutout != null) {
127
- this.applySafeAreaInsets(
128
- Math.max(this.safeAreaInsets.top(), cutout.getSafeInsetTop()),
129
- Math.max(this.safeAreaInsets.bottom(), cutout.getSafeInsetBottom()),
130
- Math.max(this.safeAreaInsets.left(), cutout.getSafeInsetLeft()),
131
- Math.max(this.safeAreaInsets.right(), cutout.getSafeInsetRight())
132
- );
133
- }
134
- }
135
-
136
- protected void doNotify() {
137
- JSObject ret = new JSObject();
138
-
139
- ret.put(SafeAreaPlugin.KEY_INSET, this.safeAreaInsets.toJSON());
140
-
141
- this.notifyListeners(SafeAreaPlugin.EVENT_ON_INSETS_CHANGED, ret);
142
- }
143
-
144
- private void applySafeAreaInsets(int top, int bottom, int left, int right) {
145
- View decorView = this.getBridge().getActivity().getWindow().getDecorView();
146
- int uiVisibility = decorView.getSystemUiVisibility();
147
-
148
- if ((uiVisibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {
149
- this.safeAreaInsets.bottom(bottom);
150
- } else {
151
- this.safeAreaInsets.bottom(0);
152
- }
153
-
154
- this.safeAreaInsets.top(top);
155
- this.safeAreaInsets.right(left);
156
- this.safeAreaInsets.left(right);
157
- }
158
- }
1
+ package com.getcapacitor.community.plugins.safearea;
2
+
3
+ import android.annotation.SuppressLint;
4
+ import android.graphics.Insets;
5
+ import android.os.Build;
6
+ import android.view.DisplayCutout;
7
+ import android.view.View;
8
+ import android.view.ViewGroup;
9
+ import android.view.WindowInsets;
10
+ import android.widget.FrameLayout;
11
+
12
+ import com.getcapacitor.JSObject;
13
+ import com.getcapacitor.Plugin;
14
+ import com.getcapacitor.PluginCall;
15
+ import com.getcapacitor.PluginMethod;
16
+ import com.getcapacitor.annotation.CapacitorPlugin;
17
+
18
+ @CapacitorPlugin(name = "SafeArea")
19
+ public class SafeAreaPlugin extends Plugin {
20
+ private static final String KEY_INSET = "insets";
21
+ private static final String EVENT_ON_INSETS_CHANGED = "safeAreaPluginsInsetChange";
22
+ private SafeAreaInsets safeAreaInsets = new com.getcapacitor.community.plugins.safearea.SafeAreaInsets();
23
+ private SafeAreaView safeAreaView;
24
+
25
+ @Override
26
+ public void load() {
27
+ this.getBridge().getActivity().runOnUiThread(() -> {
28
+ safeAreaView = new SafeAreaView(this.getBridge().getActivity(), (WindowInsets insets) -> {
29
+ this.getSafeArea(insets);
30
+ this.doNotify();
31
+ });
32
+
33
+ FrameLayout.LayoutParams safeAreaPreviewParams = new FrameLayout.LayoutParams(
34
+ FrameLayout.LayoutParams.MATCH_PARENT,
35
+ FrameLayout.LayoutParams.MATCH_PARENT
36
+ );
37
+
38
+ // Set SafeAreaView as sibling View of WebView
39
+ ((ViewGroup) this.getBridge().getWebView().getParent()).addView(safeAreaView, safeAreaPreviewParams);
40
+
41
+ // Bring the WebView in front of the SafeAreaView
42
+ this.getBridge().getWebView().bringToFront();
43
+ });
44
+ }
45
+
46
+ @PluginMethod
47
+ public void refresh(PluginCall call) {
48
+ this.doNotify();
49
+ call.resolve();
50
+ }
51
+
52
+ @PluginMethod
53
+ public void getSafeAreaInsets(PluginCall call) {
54
+ JSObject ret = new JSObject();
55
+
56
+ ret.put(SafeAreaPlugin.KEY_INSET, this.safeAreaInsets.toJSON());
57
+
58
+ call.resolve(ret);
59
+ }
60
+
61
+ protected void getSafeArea(WindowInsets windowInsets) {
62
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
63
+ this.getSafeAreaR(windowInsets);
64
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
65
+ this.getSafeAreaQ(windowInsets);
66
+ } else {
67
+ this.getSafeAreaLollipop(windowInsets);
68
+ }
69
+
70
+ // Cutout
71
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
72
+ this.getSafeAreaCutout(windowInsets);
73
+ }
74
+
75
+ float density = this.getBridge().getActivity().getResources().getDisplayMetrics().density;
76
+
77
+ this.applySafeAreaInsets(
78
+ Math.round(this.safeAreaInsets.top() / density),
79
+ Math.round(this.safeAreaInsets.bottom() / density),
80
+ Math.round(this.safeAreaInsets.left() / density),
81
+ Math.round(this.safeAreaInsets.right() / density)
82
+ );
83
+ }
84
+
85
+ // api level 30
86
+ // Get insets (Mandatory System Gestures: https://developer.android.com/reference/android/view/WindowInsets#getMandatorySystemGestureInsets())
87
+ @SuppressLint("NewApi")
88
+ protected void getSafeAreaR(WindowInsets windowInsets) {
89
+ Insets finalInsets = windowInsets.getInsets(WindowInsets.Type.mandatorySystemGestures());
90
+
91
+ this.applySafeAreaInsets(
92
+ finalInsets.top,
93
+ finalInsets.bottom,
94
+ finalInsets.left,
95
+ finalInsets.right
96
+ );
97
+ }
98
+
99
+ // api level 29
100
+ @SuppressLint("NewApi")
101
+ protected void getSafeAreaQ(WindowInsets windowInsets) {
102
+ Insets finalInsets = windowInsets.getMandatorySystemGestureInsets();
103
+
104
+ this.applySafeAreaInsets(
105
+ finalInsets.top,
106
+ finalInsets.bottom,
107
+ finalInsets.left,
108
+ finalInsets.right
109
+ );
110
+ }
111
+
112
+ // api level 21
113
+ protected void getSafeAreaLollipop(WindowInsets windowInsets) {
114
+ this.applySafeAreaInsets(
115
+ windowInsets.getSystemWindowInsetTop(),
116
+ windowInsets.getStableInsetBottom(),
117
+ windowInsets.getStableInsetLeft(),
118
+ windowInsets.getStableInsetRight()
119
+ );
120
+ }
121
+
122
+ // cutout (api level >= 28)
123
+ @SuppressLint("NewApi")
124
+ protected void getSafeAreaCutout(WindowInsets windowInsets) {
125
+ DisplayCutout cutout = windowInsets.getDisplayCutout();
126
+ if (cutout != null) {
127
+ this.applySafeAreaInsets(
128
+ Math.max(this.safeAreaInsets.top(), cutout.getSafeInsetTop()),
129
+ Math.max(this.safeAreaInsets.bottom(), cutout.getSafeInsetBottom()),
130
+ Math.max(this.safeAreaInsets.left(), cutout.getSafeInsetLeft()),
131
+ Math.max(this.safeAreaInsets.right(), cutout.getSafeInsetRight())
132
+ );
133
+ }
134
+ }
135
+
136
+ protected void doNotify() {
137
+ JSObject ret = new JSObject();
138
+
139
+ ret.put(SafeAreaPlugin.KEY_INSET, this.safeAreaInsets.toJSON());
140
+
141
+ this.notifyListeners(SafeAreaPlugin.EVENT_ON_INSETS_CHANGED, ret);
142
+ }
143
+
144
+ private void applySafeAreaInsets(int top, int bottom, int left, int right) {
145
+ this.safeAreaInsets.bottom(bottom);
146
+ this.safeAreaInsets.top(top);
147
+ this.safeAreaInsets.right(left);
148
+ this.safeAreaInsets.left(right);
149
+ }
150
+ }
@@ -1,49 +1,49 @@
1
- package com.getcapacitor.community.plugins.safearea;
2
-
3
- import android.content.Context;
4
- import android.util.AttributeSet;
5
- import android.view.View;
6
- import android.view.WindowInsets;
7
- import java.util.function.Consumer;
8
-
9
- /**
10
- * SafeArea View
11
- * WindowInsets monitor
12
- */
13
- public class SafeAreaView extends View {
14
- private Consumer<WindowInsets> callbackInsets;
15
-
16
- public SafeAreaView(Context context) {
17
- super(context);
18
- init(null, 0, null);
19
- }
20
-
21
- public SafeAreaView(Context context, Consumer<WindowInsets> onApplyInsets) {
22
- super(context);
23
- init(null, 0, onApplyInsets);
24
- }
25
-
26
- public SafeAreaView(Context context, AttributeSet attrs) {
27
- super(context, attrs);
28
- init(attrs, 0, null);
29
- }
30
-
31
- public SafeAreaView(Context context, AttributeSet attrs, int defStyle) {
32
- super(context, attrs, defStyle);
33
- init(attrs, defStyle, null);
34
- }
35
-
36
- private void init(AttributeSet attrs, int defStyle, Consumer<WindowInsets> onApplyInsets) {
37
- if (onApplyInsets == null) {
38
- this.callbackInsets = (WindowInsets wInsts) -> {};
39
- } else {
40
- this.callbackInsets = onApplyInsets;
41
- }
42
- }
43
-
44
- @Override
45
- public WindowInsets onApplyWindowInsets(WindowInsets insets) {
46
- this.callbackInsets.accept(insets);
47
- return super.onApplyWindowInsets(insets);
48
- }
1
+ package com.getcapacitor.community.plugins.safearea;
2
+
3
+ import android.content.Context;
4
+ import android.util.AttributeSet;
5
+ import android.view.View;
6
+ import android.view.WindowInsets;
7
+ import java.util.function.Consumer;
8
+
9
+ /**
10
+ * SafeArea View
11
+ * WindowInsets monitor
12
+ */
13
+ public class SafeAreaView extends View {
14
+ private Consumer<WindowInsets> callbackInsets;
15
+
16
+ public SafeAreaView(Context context) {
17
+ super(context);
18
+ init(null, 0, null);
19
+ }
20
+
21
+ public SafeAreaView(Context context, Consumer<WindowInsets> onApplyInsets) {
22
+ super(context);
23
+ init(null, 0, onApplyInsets);
24
+ }
25
+
26
+ public SafeAreaView(Context context, AttributeSet attrs) {
27
+ super(context, attrs);
28
+ init(attrs, 0, null);
29
+ }
30
+
31
+ public SafeAreaView(Context context, AttributeSet attrs, int defStyle) {
32
+ super(context, attrs, defStyle);
33
+ init(attrs, defStyle, null);
34
+ }
35
+
36
+ private void init(AttributeSet attrs, int defStyle, Consumer<WindowInsets> onApplyInsets) {
37
+ if (onApplyInsets == null) {
38
+ this.callbackInsets = (WindowInsets wInsts) -> {};
39
+ } else {
40
+ this.callbackInsets = onApplyInsets;
41
+ }
42
+ }
43
+
44
+ @Override
45
+ public WindowInsets onApplyWindowInsets(WindowInsets insets) {
46
+ this.callbackInsets.accept(insets);
47
+ return super.onApplyWindowInsets(insets);
48
+ }
49
49
  }
@@ -1,10 +1,10 @@
1
- #import <UIKit/UIKit.h>
2
-
3
- //! Project version number for Plugin.
4
- FOUNDATION_EXPORT double PluginVersionNumber;
5
-
6
- //! Project version string for Plugin.
7
- FOUNDATION_EXPORT const unsigned char PluginVersionString[];
8
-
9
- // In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
10
-
1
+ #import <UIKit/UIKit.h>
2
+
3
+ //! Project version number for Plugin.
4
+ FOUNDATION_EXPORT double PluginVersionNumber;
5
+
6
+ //! Project version string for Plugin.
7
+ FOUNDATION_EXPORT const unsigned char PluginVersionString[];
8
+
9
+ // In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
10
+
@@ -1,9 +1,9 @@
1
- #import <Foundation/Foundation.h>
2
- #import <Capacitor/Capacitor.h>
3
-
4
- // Define the plugin using the CAP_PLUGIN Macro, and
5
- // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
- CAP_PLUGIN(SafeAreaPlugin, "SafeArea",
7
- CAP_PLUGIN_METHOD(refresh, CAPPluginReturnPromise);
8
- CAP_PLUGIN_METHOD(getSafeAreaInsets, CAPPluginReturnPromise);
9
- )
1
+ #import <Foundation/Foundation.h>
2
+ #import <Capacitor/Capacitor.h>
3
+
4
+ // Define the plugin using the CAP_PLUGIN Macro, and
5
+ // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
+ CAP_PLUGIN(SafeAreaPlugin, "SafeArea",
7
+ CAP_PLUGIN_METHOD(refresh, CAPPluginReturnPromise);
8
+ CAP_PLUGIN_METHOD(getSafeAreaInsets, CAPPluginReturnPromise);
9
+ )
@@ -1,93 +1,93 @@
1
- import Foundation
2
- import Capacitor
3
-
4
- func makeSafeArea(_ insets: UIEdgeInsets) -> [String :[String: Int]] {
5
- return [
6
- "insets": [
7
- "top": Int(insets.top),
8
- "bottom": Int(insets.bottom),
9
- "right": Int(insets.right),
10
- "left": Int(insets.left)
11
- ]
12
- ];
13
- }
14
-
15
- func getInsets(controller: UIViewController) -> UIEdgeInsets {
16
- let keyWindow = UIApplication.shared.windows
17
- .filter { window in window.rootViewController == controller }
18
- .first
19
-
20
- if (keyWindow == nil) {
21
- return UIEdgeInsets.zero
22
- }
23
-
24
- return keyWindow!.safeAreaInsets
25
- }
26
-
27
- let EVENT_ON_INSETS_CHANGED = "safeAreaPluginsInsetChange"
28
-
29
- /**
30
- * Please read the Capacitor iOS Plugin Development Guide
31
- * here: https://capacitorjs.com/docs/plugins/ios
32
- */
33
- @objc(SafeAreaPlugin)
34
- public class SafeAreaPlugin: CAPPlugin {
35
- public static let ViewSafeAreaInsetsDidChange = NSNotification.Name(rawValue: "SafeAreaPlugin.ViewSafeAreaInsetsDidChange");
36
-
37
- private var safeArea = makeSafeArea(UIEdgeInsets.zero)
38
-
39
- override public func load() {
40
- NotificationCenter.default.addObserver(
41
- self,
42
- selector: #selector(self.onDidBecomeActive),
43
- name: UIApplication.didBecomeActiveNotification,
44
- object: nil
45
- )
46
-
47
- NotificationCenter.default.addObserver(
48
- self,
49
- selector: #selector(self.onViewSafeAreaInsetsDidChange),
50
- name: SafeAreaPlugin.ViewSafeAreaInsetsDidChange,
51
- object: nil
52
- )
53
- }
54
-
55
- deinit {
56
- NotificationCenter.default.removeObserver(self)
57
- }
58
-
59
- @objc func refresh(_ call: CAPPluginCall) {
60
- let insets = getInsets(controller: (self.bridge?.viewController)!)
61
- self.changeSafeArea(insets);
62
- call.resolve()
63
- }
64
-
65
- @objc func getSafeAreaInsets(_ call: CAPPluginCall) {
66
- call.resolve(self.safeArea)
67
- }
68
-
69
- @objc func onDidBecomeActive() {
70
- let insets = getInsets(controller: (self.bridge?.viewController)!)
71
- self.changeSafeArea(insets)
72
- }
73
-
74
- @objc func onViewSafeAreaInsetsDidChange() {
75
- let insets = getInsets(controller: (self.bridge?.viewController)!)
76
- self.changeSafeArea(insets)
77
- }
78
-
79
- func changeSafeArea(_ insets: UIEdgeInsets) {
80
- self.safeArea = makeSafeArea(insets)
81
- self.notifyListeners(EVENT_ON_INSETS_CHANGED, data: self.safeArea)
82
- }
83
- }
84
-
85
- extension CAPBridgeViewController {
86
- public override func viewSafeAreaInsetsDidChange() {
87
- super.viewSafeAreaInsetsDidChange()
88
- NotificationCenter.default.post(
89
- name: SafeAreaPlugin.ViewSafeAreaInsetsDidChange,
90
- object: nil
91
- )
92
- }
93
- }
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ func makeSafeArea(_ insets: UIEdgeInsets) -> [String :[String: Int]] {
5
+ return [
6
+ "insets": [
7
+ "top": Int(insets.top),
8
+ "bottom": Int(insets.bottom),
9
+ "right": Int(insets.right),
10
+ "left": Int(insets.left)
11
+ ]
12
+ ];
13
+ }
14
+
15
+ func getInsets(controller: UIViewController) -> UIEdgeInsets {
16
+ let keyWindow = UIApplication.shared.windows
17
+ .filter { window in window.rootViewController == controller }
18
+ .first
19
+
20
+ if (keyWindow == nil) {
21
+ return UIEdgeInsets.zero
22
+ }
23
+
24
+ return keyWindow!.safeAreaInsets
25
+ }
26
+
27
+ let EVENT_ON_INSETS_CHANGED = "safeAreaPluginsInsetChange"
28
+
29
+ /**
30
+ * Please read the Capacitor iOS Plugin Development Guide
31
+ * here: https://capacitorjs.com/docs/plugins/ios
32
+ */
33
+ @objc(SafeAreaPlugin)
34
+ public class SafeAreaPlugin: CAPPlugin {
35
+ public static let ViewSafeAreaInsetsDidChange = NSNotification.Name(rawValue: "SafeAreaPlugin.ViewSafeAreaInsetsDidChange");
36
+
37
+ private var safeArea = makeSafeArea(UIEdgeInsets.zero)
38
+
39
+ override public func load() {
40
+ NotificationCenter.default.addObserver(
41
+ self,
42
+ selector: #selector(self.onDidBecomeActive),
43
+ name: UIApplication.didBecomeActiveNotification,
44
+ object: nil
45
+ )
46
+
47
+ NotificationCenter.default.addObserver(
48
+ self,
49
+ selector: #selector(self.onViewSafeAreaInsetsDidChange),
50
+ name: SafeAreaPlugin.ViewSafeAreaInsetsDidChange,
51
+ object: nil
52
+ )
53
+ }
54
+
55
+ deinit {
56
+ NotificationCenter.default.removeObserver(self)
57
+ }
58
+
59
+ @objc func refresh(_ call: CAPPluginCall) {
60
+ let insets = getInsets(controller: (self.bridge?.viewController)!)
61
+ self.changeSafeArea(insets);
62
+ call.resolve()
63
+ }
64
+
65
+ @objc func getSafeAreaInsets(_ call: CAPPluginCall) {
66
+ call.resolve(self.safeArea)
67
+ }
68
+
69
+ @objc func onDidBecomeActive() {
70
+ let insets = getInsets(controller: (self.bridge?.viewController)!)
71
+ self.changeSafeArea(insets)
72
+ }
73
+
74
+ @objc func onViewSafeAreaInsetsDidChange() {
75
+ let insets = getInsets(controller: (self.bridge?.viewController)!)
76
+ self.changeSafeArea(insets)
77
+ }
78
+
79
+ func changeSafeArea(_ insets: UIEdgeInsets) {
80
+ self.safeArea = makeSafeArea(insets)
81
+ self.notifyListeners(EVENT_ON_INSETS_CHANGED, data: self.safeArea)
82
+ }
83
+ }
84
+
85
+ extension CAPBridgeViewController {
86
+ public override func viewSafeAreaInsetsDidChange() {
87
+ super.viewSafeAreaInsetsDidChange()
88
+ NotificationCenter.default.post(
89
+ name: SafeAreaPlugin.ViewSafeAreaInsetsDidChange,
90
+ object: nil
91
+ )
92
+ }
93
+ }
package/package.json CHANGED
@@ -1,75 +1,75 @@
1
- {
2
- "name": "@hiloenergie/capacitor-plugin-safe-area",
3
- "version": "0.0.13",
4
- "description": "A plugin to expose the safe area insets from the native iOS/Android device to your web project.",
5
- "author": "Kevin Pacheco",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://dev.azure.com/HQCdevops/HQC/_git/capacitor-community-safe-area"
10
- },
11
- "bugs": {
12
- "url": "https://dev.azure.com/HQCdevops/HQC/_git/capacitor-community-safe-area"
13
- },
14
- "main": "dist/plugin.cjs.js",
15
- "module": "dist/esm/index.js",
16
- "types": "dist/esm/index.d.ts",
17
- "unpkg": "dist/plugin.js",
18
- "files": [
19
- "android/src/main/",
20
- "android/build.gradle",
21
- "dist/",
22
- "ios/Plugin/",
23
- "HiloenergieCapacitorPluginSafeArea.podspec"
24
- ],
25
- "keywords": [
26
- "capacitor",
27
- "plugin",
28
- "native"
29
- ],
30
- "scripts": {
31
- "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
32
- "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
33
- "verify:android": "cd android && ./gradlew clean build test && cd ..",
34
- "verify:web": "npm run build",
35
- "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36
- "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- autocorrect --format",
37
- "eslint": "eslint . --ext ts",
38
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
39
- "swiftlint": "node-swiftlint",
40
- "docgen": "docgen --api SafeAreaPlugin --output-readme README.md --output-json dist/docs.json",
41
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
42
- "clean": "rimraf ./dist",
43
- "watch": "tsc --watch",
44
- "prepublishOnly": "npm run build"
45
- },
46
- "devDependencies": {
47
- "@capacitor/android": "^7.4.2",
48
- "@capacitor/core": "^7.4.2",
49
- "@capacitor/docgen": "^0.3.0",
50
- "@capacitor/ios": "^7.4.2",
51
- "@ionic/eslint-config": "^0.4.0",
52
- "@ionic/prettier-config": "^4.0.0",
53
- "@ionic/swiftlint-config": "^2.0.0",
54
- "eslint": "^8.57.0",
55
- "prettier": "^3.4.2",
56
- "prettier-plugin-java": "^2.6.6",
57
- "rimraf": "^6.0.1",
58
- "rollup": "^4.30.1",
59
- "swiftlint": "^2.0.0",
60
- "typescript": "~5.0.2"
61
- },
62
- "peerDependencies": {
63
- "@capacitor/core": ">=7.0.0"
64
- },
65
- "prettier": "@ionic/prettier-config",
66
- "swiftlint": "@ionic/swiftlint-config",
67
- "capacitor": {
68
- "ios": {
69
- "src": "ios"
70
- },
71
- "android": {
72
- "src": "android"
73
- }
74
- }
75
- }
1
+ {
2
+ "name": "@hiloenergie/capacitor-plugin-safe-area",
3
+ "version": "8.0.0",
4
+ "description": "A plugin to expose the safe area insets from the native iOS/Android device to your web project.",
5
+ "author": "Kevin Pacheco",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://dev.azure.com/HQCdevops/HQC/_git/capacitor-community-safe-area"
10
+ },
11
+ "bugs": {
12
+ "url": "https://dev.azure.com/HQCdevops/HQC/_git/capacitor-community-safe-area"
13
+ },
14
+ "main": "dist/plugin.cjs.js",
15
+ "module": "dist/esm/index.js",
16
+ "types": "dist/esm/index.d.ts",
17
+ "unpkg": "dist/plugin.js",
18
+ "files": [
19
+ "android/src/main/",
20
+ "android/build.gradle",
21
+ "dist/",
22
+ "ios/Plugin/",
23
+ "HiloenergieCapacitorPluginSafeArea.podspec"
24
+ ],
25
+ "keywords": [
26
+ "capacitor",
27
+ "plugin",
28
+ "native"
29
+ ],
30
+ "scripts": {
31
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
32
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
33
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
34
+ "verify:web": "npm run build",
35
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- autocorrect --format",
37
+ "eslint": "eslint . --ext ts",
38
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
39
+ "swiftlint": "node-swiftlint",
40
+ "docgen": "docgen --api SafeAreaPlugin --output-readme README.md --output-json dist/docs.json",
41
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
42
+ "clean": "rimraf ./dist",
43
+ "watch": "tsc --watch",
44
+ "prepublishOnly": "npm run build"
45
+ },
46
+ "devDependencies": {
47
+ "@capacitor/android": "^8.1.0",
48
+ "@capacitor/core": "^8.1.0",
49
+ "@capacitor/docgen": "^0.3.0",
50
+ "@capacitor/ios": "^8.1.0",
51
+ "@ionic/eslint-config": "^0.4.0",
52
+ "@ionic/prettier-config": "^4.0.0",
53
+ "@ionic/swiftlint-config": "^2.0.0",
54
+ "eslint": "^8.57.0",
55
+ "prettier": "^3.4.2",
56
+ "prettier-plugin-java": "^2.6.6",
57
+ "rimraf": "^6.0.1",
58
+ "rollup": "^4.30.1",
59
+ "swiftlint": "^2.0.0",
60
+ "typescript": "~5.0.2"
61
+ },
62
+ "peerDependencies": {
63
+ "@capacitor/core": ">=8.0.0"
64
+ },
65
+ "prettier": "@ionic/prettier-config",
66
+ "swiftlint": "@ionic/swiftlint-config",
67
+ "capacitor": {
68
+ "ios": {
69
+ "src": "ios"
70
+ },
71
+ "android": {
72
+ "src": "android"
73
+ }
74
+ }
75
+ }