expo-app-blocker 0.1.46 → 0.1.47
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.
|
@@ -2,6 +2,7 @@ package expo.modules.appblocker
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.content.Intent
|
|
5
|
+
import android.graphics.BitmapFactory
|
|
5
6
|
import android.graphics.Color
|
|
6
7
|
import android.graphics.PixelFormat
|
|
7
8
|
import android.graphics.Typeface
|
|
@@ -12,6 +13,7 @@ import android.util.TypedValue
|
|
|
12
13
|
import android.view.Gravity
|
|
13
14
|
import android.view.View
|
|
14
15
|
import android.view.WindowManager
|
|
16
|
+
import android.widget.ImageView
|
|
15
17
|
import android.widget.LinearLayout
|
|
16
18
|
import android.widget.TextView
|
|
17
19
|
|
|
@@ -140,6 +142,25 @@ class OverlayManager(private val context: Context) {
|
|
|
140
142
|
setBackgroundColor(backgroundColor)
|
|
141
143
|
setPadding(dp(32), dp(32), dp(32), dp(32))
|
|
142
144
|
|
|
145
|
+
// Optional brand icon — drawable named `expo_app_blocker_overlay_icon`
|
|
146
|
+
// is copied by the config plugin from `pluginConfig.android.overlay.icon`.
|
|
147
|
+
// Skip silently if missing so apps that don't ship one still get a clean overlay.
|
|
148
|
+
val iconResId = context.resources.getIdentifier(
|
|
149
|
+
"expo_app_blocker_overlay_icon",
|
|
150
|
+
"drawable",
|
|
151
|
+
context.packageName,
|
|
152
|
+
)
|
|
153
|
+
if (iconResId != 0) {
|
|
154
|
+
addView(ImageView(context).apply {
|
|
155
|
+
val bitmap = BitmapFactory.decodeResource(context.resources, iconResId)
|
|
156
|
+
if (bitmap != null) setImageBitmap(bitmap)
|
|
157
|
+
val size = dp(96)
|
|
158
|
+
layoutParams = LinearLayout.LayoutParams(size, size).apply {
|
|
159
|
+
bottomMargin = dp(20)
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
143
164
|
addView(TextView(context).apply {
|
|
144
165
|
text = overlayTitle
|
|
145
166
|
setTextColor(titleColor)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-app-blocker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.47",
|
|
4
4
|
"description": "Expo module for cross-platform app blocking. Android: UsageStatsManager + Overlay. iOS: Screen Time API (FamilyControls + ManagedSettings + DeviceActivity).",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
package/plugin/src/index.js
CHANGED
|
@@ -144,6 +144,39 @@ function withAppBlockerAndroid(config, pluginConfig) {
|
|
|
144
144
|
]);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
// Copy the overlay icon (PNG) to `res/drawable/expo_app_blocker_overlay_icon.png`
|
|
148
|
+
// so `OverlayManager.kt` can resolve it via Resources.getIdentifier(...).
|
|
149
|
+
// The icon is rendered above the title in the SYSTEM_ALERT_WINDOW overlay.
|
|
150
|
+
// Path is resolved relative to the project root for consistency with the
|
|
151
|
+
// top-level `icon` config field.
|
|
152
|
+
const overlayIconRel = pluginConfig?.android?.overlay?.icon;
|
|
153
|
+
if (overlayIconRel) {
|
|
154
|
+
config = withDangerousMod(config, [
|
|
155
|
+
"android",
|
|
156
|
+
(config) => {
|
|
157
|
+
const platformRoot = config.modRequest.platformProjectRoot;
|
|
158
|
+
const projectRoot = config.modRequest.projectRoot;
|
|
159
|
+
const drawableDir = path.join(platformRoot, "app", "src", "main", "res", "drawable");
|
|
160
|
+
const iconSrc = path.isAbsolute(overlayIconRel)
|
|
161
|
+
? overlayIconRel
|
|
162
|
+
: path.join(projectRoot, overlayIconRel);
|
|
163
|
+
|
|
164
|
+
if (!fs.existsSync(iconSrc)) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`[expo-app-blocker] android.overlay.icon points to a missing file: ${iconSrc}`,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!fs.existsSync(drawableDir)) {
|
|
171
|
+
fs.mkdirSync(drawableDir, { recursive: true });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
fs.copyFileSync(iconSrc, path.join(drawableDir, "expo_app_blocker_overlay_icon.png"));
|
|
175
|
+
return config;
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
178
|
+
}
|
|
179
|
+
|
|
147
180
|
return config;
|
|
148
181
|
}
|
|
149
182
|
|