-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into improve-sidebar-animation
- Loading branch information
Showing
5 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
package com.uplink.app; | ||
|
||
import com.getcapacitor.BridgeActivity; | ||
import com.uplink.plugins.SafeAreaColorPlugin; | ||
import android.os.Bundle; | ||
|
||
public class MainActivity extends BridgeActivity {} | ||
public class MainActivity extends BridgeActivity { | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
registerPlugin(SafeAreaColorPlugin.class); | ||
super.onCreate(savedInstanceState); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
android/app/src/main/java/com/uplink/plugins/SafeAreaColorPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.uplink.plugins; | ||
|
||
import android.app.Activity; | ||
import android.os.Build; | ||
import android.view.View; | ||
import android.view.Window; | ||
import androidx.annotation.NonNull; | ||
|
||
import com.getcapacitor.JSObject; | ||
import com.getcapacitor.Plugin; | ||
import com.getcapacitor.annotation.CapacitorPlugin; | ||
import com.getcapacitor.PluginCall; | ||
import com.getcapacitor.PluginMethod; | ||
|
||
@CapacitorPlugin(name = "SafeAreaColorPlugin") | ||
public class SafeAreaColorPlugin extends Plugin { | ||
|
||
@PluginMethod | ||
public void setStatusBarColor(PluginCall call) { | ||
String color = call.getString("color"); | ||
|
||
if (color == null) { | ||
call.reject("Color must be provided"); | ||
return; | ||
} | ||
getActivity().runOnUiThread(() -> { | ||
try { | ||
Window window = getActivity().getWindow(); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
window.setStatusBarColor(android.graphics.Color.parseColor(color)); | ||
} | ||
call.resolve(); | ||
} catch (Exception e) { | ||
call.reject("Failed to set status bar color", e); | ||
} | ||
}); | ||
} | ||
|
||
@PluginMethod | ||
public void setNavigationBarColor(PluginCall call) { | ||
String color = call.getString("color"); | ||
|
||
if (color == null) { | ||
call.reject("Color must be provided"); | ||
return; | ||
} | ||
|
||
getActivity().runOnUiThread(() -> { | ||
try { | ||
Window window = getActivity().getWindow(); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
window.setNavigationBarColor(android.graphics.Color.parseColor(color)); | ||
} | ||
call.resolve(); | ||
} catch (Exception e) { | ||
call.reject("Failed to set navigation bar color", e); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { log } from "$lib/utils/Logger" | ||
import { registerPlugin } from "@capacitor/core" | ||
|
||
interface ISafeAreaColorPlugin { | ||
setStatusBarColor(options: { color: string }): Promise<{ value: string }> | ||
setNavigationBarColor(options: { color: string }): Promise<{ value: string }> | ||
} | ||
|
||
const SafeAreaColorPlugin = registerPlugin<ISafeAreaColorPlugin>("SafeAreaColorPlugin") | ||
|
||
async function setStatusBarColor(color: string) { | ||
try { | ||
log.info("Calling native android function to change status bar color") | ||
await SafeAreaColorPlugin.setStatusBarColor({ color }) | ||
} catch (error) { | ||
log.error("Error setting status bar color:", error) | ||
} | ||
} | ||
|
||
async function setNavigationBarColor(color: string) { | ||
try { | ||
log.info("Calling native android function to change navigation bar color") | ||
await SafeAreaColorPlugin.setNavigationBarColor({ color }) | ||
} catch (error) { | ||
log.error("Error setting navigation bar color:", error) | ||
} | ||
} | ||
|
||
export function changeSafeAreaColorsOnAndroid(color: string) { | ||
setStatusBarColor(color) | ||
setNavigationBarColor(color) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters