Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,54 @@ Snitcher.install(

### Custom Snitcher Theme

If you just want to use the pre-builts sreens, but want to customize those components, such as colors and strings, you can easily accomplish it by giving a copy of `SnitcherColor` to the `SnitcherTheme`:
The pre-built screens are styled by a `SnitcherThemeConfig`. Give one to `Snitcher.install`, and the built-in `ExceptionTraceActivity`, as well as every screen you wrap in `SnitcherTheme`, will be drawn with it:

```kotlin
Snitcher.install(
application = this,
theme = SnitcherThemeConfig(
lightColors = SnitcherColor.defaultColors().copy(primary = Color(0xFF6650a4)),
darkColors = SnitcherColor.defaultDarkColors().copy(primary = Color(0xFFD0BCFF)),
typography = SnitcherTypography.defaultTypography().copy(
title = TextStyle(fontSize = 30.sp, fontWeight = FontWeight.Black),
),
shapes = SnitcherShapes(button = RoundedCornerShape(20.dp)),
),
)
```

`lightColors` and `darkColors` are picked by the system dark mode. Every field has a default, so you only need to declare what you want to change.

**SnitcherColor**

| Property | Where it is used |
|---|---|
| `primary` | The title, the section labels, and the button background |
| `onPrimary` | The content that is drawn on the buttons |
| `background` | The screen background, which is also drawn behind the system bars |
| `textHighEmphasis` | The exception message, the stack trace, and the restore screen texts |
| `textLowEmphasis` | The package and device information |
| `outline` | The border of the stack trace container |

**SnitcherTypography**

`title`, `message`, `deviceInfo`, `sectionLabel`, `stacktrace`, and `button` are plain `TextStyle`s, so fonts, sizes, and weights are all yours.

**SnitcherShapes**

`button` and `stacktrace` are plain `Shape`s.

You can also swap the theme at any time, which restyles the screens right away:

```kotlin
Snitcher.theme = Snitcher.theme.copy(darkColors = SnitcherColor.defaultDarkColors())
```

If you build your own trace screens, wrap them in `SnitcherTheme`. Its defaults come from the installed configuration, so your screens and the pre-built ones stay in sync, and you can still override any of them for a single screen:

```kotlin
SnitcherTheme(
colors = SnitcherTheme.colors.copy(
primary = Color.Blue,
background = Color.White,
textHighEmphasis = Color.Black
)
colors = SnitcherTheme.colors.copy(primary = Color.Blue),
) {
if (exception != null) {
ExceptionTraceScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
package com.skydoves.snitcherdemo

import android.app.Application
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.skydoves.snitcher.Snitcher
import com.skydoves.snitcher.ui.theme.SnitcherColor
import com.skydoves.snitcher.ui.theme.SnitcherShapes
import com.skydoves.snitcher.ui.theme.SnitcherThemeConfig
import com.skydoves.snitcher.ui.theme.SnitcherTypography
import com.skydoves.snitcherdemo.ui.theme.Purple40
import com.skydoves.snitcherdemo.ui.theme.Purple80

class SnitcherDemoApp : Application() {

Expand All @@ -25,6 +36,14 @@ class SnitcherDemoApp : Application() {

Snitcher.install(
application = this,
theme = SnitcherThemeConfig(
lightColors = SnitcherColor.defaultColors().copy(primary = Purple40),
darkColors = SnitcherColor.defaultDarkColors().copy(primary = Purple80),
typography = SnitcherTypography.defaultTypography().copy(
title = TextStyle(fontSize = 30.sp, fontWeight = FontWeight.Black),
),
shapes = SnitcherShapes(button = RoundedCornerShape(20.dp)),
),
exceptionHandler = {
// do something
},
Expand Down
51 changes: 45 additions & 6 deletions docs/custom-theme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
# Snitcher Theme

If you just want to use the pre-builts sreens, but want to customize those components, such as colors and strings, you can easily accomplish it by giving a copy of `SnitcherColor` to the `SnitcherTheme`:
The pre-built screens are styled by a `SnitcherThemeConfig`. Give one to `Snitcher.install`, and the built-in `ExceptionTraceActivity`, as well as every screen you wrap in `SnitcherTheme`, will be drawn with it:

```kotlin
Snitcher.install(
application = this,
theme = SnitcherThemeConfig(
lightColors = SnitcherColor.defaultColors().copy(primary = Color(0xFF6650a4)),
darkColors = SnitcherColor.defaultDarkColors().copy(primary = Color(0xFFD0BCFF)),
typography = SnitcherTypography.defaultTypography().copy(
title = TextStyle(fontSize = 30.sp, fontWeight = FontWeight.Black),
),
shapes = SnitcherShapes(button = RoundedCornerShape(20.dp)),
),
)
```

`lightColors` and `darkColors` are picked by the system dark mode. Every field has a default, so you only need to declare what you want to change.

**SnitcherColor**

| Property | Where it is used |
|---|---|
| `primary` | The title, the section labels, and the button background |
| `onPrimary` | The content that is drawn on the buttons |
| `background` | The screen background, which is also drawn behind the system bars |
| `textHighEmphasis` | The exception message, the stack trace, and the restore screen texts |
| `textLowEmphasis` | The package and device information |
| `outline` | The border of the stack trace container |

**SnitcherTypography**

`title`, `message`, `deviceInfo`, `sectionLabel`, `stacktrace`, and `button` are plain `TextStyle`s, so fonts, sizes, and weights are all yours.

**SnitcherShapes**

`button` and `stacktrace` are plain `Shape`s.

You can also swap the theme at any time, which restyles the screens right away:

```kotlin
Snitcher.theme = Snitcher.theme.copy(darkColors = SnitcherColor.defaultDarkColors())
```

If you build your own trace screens, wrap them in `SnitcherTheme`. Its defaults come from the installed configuration, so your screens and the pre-built ones stay in sync, and you can still override any of them for a single screen:

```kotlin
SnitcherTheme(
colors = SnitcherTheme.colors.copy(
primary = Color.Blue,
background = Color.White,
textHighEmphasis = Color.Black
)
colors = SnitcherTheme.colors.copy(primary = Color.Blue),
) {
if (exception != null) {
ExceptionTraceScreen(
Expand Down
90 changes: 82 additions & 8 deletions snitcher/api/snitcher.api
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ public final class com/skydoves/snitcher/Snitcher : java/lang/Thread$UncaughtExc
public final class com/skydoves/snitcher/Snitcher$Companion {
public final fun getException ()Lkotlinx/coroutines/flow/StateFlow;
public final fun getLauncher ()Lkotlinx/coroutines/flow/StateFlow;
public final fun install (Landroid/app/Application;Lkotlin/reflect/KClass;Lcom/skydoves/snitcher/TraceStrategy;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun install$default (Lcom/skydoves/snitcher/Snitcher$Companion;Landroid/app/Application;Lkotlin/reflect/KClass;Lcom/skydoves/snitcher/TraceStrategy;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun getTheme ()Lcom/skydoves/snitcher/ui/theme/SnitcherThemeConfig;
public final fun install (Landroid/app/Application;Lkotlin/reflect/KClass;Lcom/skydoves/snitcher/TraceStrategy;Lcom/skydoves/snitcher/ui/theme/SnitcherThemeConfig;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun install$default (Lcom/skydoves/snitcher/Snitcher$Companion;Landroid/app/Application;Lkotlin/reflect/KClass;Lcom/skydoves/snitcher/TraceStrategy;Lcom/skydoves/snitcher/ui/theme/SnitcherThemeConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun isDebuggable ()Z
public final fun isDebuggableApp (Landroid/app/Application;)Z
public final fun isInstalled ()Z
public final fun setDebuggable (Z)V
public final fun setTheme (Lcom/skydoves/snitcher/ui/theme/SnitcherThemeConfig;)V
}

public final class com/skydoves/snitcher/TraceStrategy : java/lang/Enum {
Expand Down Expand Up @@ -131,32 +133,104 @@ public final class com/skydoves/snitcher/ui/ExceptionTraceScreenKt {
public final class com/skydoves/snitcher/ui/theme/SnitcherColor {
public static final field $stable I
public static final field Companion Lcom/skydoves/snitcher/ui/theme/SnitcherColor$Companion;
public synthetic fun <init> (JJJLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (JJJJJJILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (JJJJJJLkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1-0d7_KjU ()J
public final fun component2-0d7_KjU ()J
public final fun component3-0d7_KjU ()J
public final fun copy-ysEtTa8 (JJJ)Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public static synthetic fun copy-ysEtTa8$default (Lcom/skydoves/snitcher/ui/theme/SnitcherColor;JJJILjava/lang/Object;)Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public final fun component4-0d7_KjU ()J
public final fun component5-0d7_KjU ()J
public final fun component6-0d7_KjU ()J
public final fun copy-tNS2XkQ (JJJJJJ)Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public static synthetic fun copy-tNS2XkQ$default (Lcom/skydoves/snitcher/ui/theme/SnitcherColor;JJJJJJILjava/lang/Object;)Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public fun equals (Ljava/lang/Object;)Z
public final fun getBackground-0d7_KjU ()J
public final fun getOnPrimary-0d7_KjU ()J
public final fun getOutline-0d7_KjU ()J
public final fun getPrimary-0d7_KjU ()J
public final fun getTextHighEmphasis-0d7_KjU ()J
public final fun getTextLowEmphasis-0d7_KjU ()J
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/skydoves/snitcher/ui/theme/SnitcherColor$Companion {
public final fun defaultColors (Landroidx/compose/runtime/Composer;I)Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public final fun defaultDarkColors (Landroidx/compose/runtime/Composer;I)Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public final fun defaultColors ()Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public final fun defaultDarkColors ()Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
}

public final class com/skydoves/snitcher/ui/theme/SnitcherShapes {
public static final field $stable I
public fun <init> ()V
public fun <init> (Landroidx/compose/ui/graphics/Shape;Landroidx/compose/ui/graphics/Shape;)V
public synthetic fun <init> (Landroidx/compose/ui/graphics/Shape;Landroidx/compose/ui/graphics/Shape;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Landroidx/compose/ui/graphics/Shape;
public final fun component2 ()Landroidx/compose/ui/graphics/Shape;
public final fun copy (Landroidx/compose/ui/graphics/Shape;Landroidx/compose/ui/graphics/Shape;)Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;
public static synthetic fun copy$default (Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;Landroidx/compose/ui/graphics/Shape;Landroidx/compose/ui/graphics/Shape;ILjava/lang/Object;)Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;
public fun equals (Ljava/lang/Object;)Z
public final fun getButton ()Landroidx/compose/ui/graphics/Shape;
public final fun getStacktrace ()Landroidx/compose/ui/graphics/Shape;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/skydoves/snitcher/ui/theme/SnitcherTheme {
public static final field $stable I
public static final field INSTANCE Lcom/skydoves/snitcher/ui/theme/SnitcherTheme;
public final fun getColors (Landroidx/compose/runtime/Composer;I)Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public final fun getShapes (Landroidx/compose/runtime/Composer;I)Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;
public final fun getTypography (Landroidx/compose/runtime/Composer;I)Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;
}

public final class com/skydoves/snitcher/ui/theme/SnitcherThemeConfig {
public static final field $stable I
public fun <init> ()V
public fun <init> (Lcom/skydoves/snitcher/ui/theme/SnitcherColor;Lcom/skydoves/snitcher/ui/theme/SnitcherColor;Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;)V
public synthetic fun <init> (Lcom/skydoves/snitcher/ui/theme/SnitcherColor;Lcom/skydoves/snitcher/ui/theme/SnitcherColor;Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public final fun component2 ()Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public final fun component3 ()Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;
public final fun component4 ()Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;
public final fun copy (Lcom/skydoves/snitcher/ui/theme/SnitcherColor;Lcom/skydoves/snitcher/ui/theme/SnitcherColor;Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;)Lcom/skydoves/snitcher/ui/theme/SnitcherThemeConfig;
public static synthetic fun copy$default (Lcom/skydoves/snitcher/ui/theme/SnitcherThemeConfig;Lcom/skydoves/snitcher/ui/theme/SnitcherColor;Lcom/skydoves/snitcher/ui/theme/SnitcherColor;Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;ILjava/lang/Object;)Lcom/skydoves/snitcher/ui/theme/SnitcherThemeConfig;
public fun equals (Ljava/lang/Object;)Z
public final fun getDarkColors ()Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public final fun getLightColors ()Lcom/skydoves/snitcher/ui/theme/SnitcherColor;
public final fun getShapes ()Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;
public final fun getTypography ()Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/skydoves/snitcher/ui/theme/SnitcherThemeKt {
public static final fun SnitcherTheme (ZLcom/skydoves/snitcher/ui/theme/SnitcherColor;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
public static final fun SnitcherTheme (ZLcom/skydoves/snitcher/ui/theme/SnitcherColor;Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;Lcom/skydoves/snitcher/ui/theme/SnitcherShapes;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
}

public final class com/skydoves/snitcher/ui/theme/SnitcherTypography {
public static final field $stable I
public static final field Companion Lcom/skydoves/snitcher/ui/theme/SnitcherTypography$Companion;
public fun <init> (Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;)V
public final fun component1 ()Landroidx/compose/ui/text/TextStyle;
public final fun component2 ()Landroidx/compose/ui/text/TextStyle;
public final fun component3 ()Landroidx/compose/ui/text/TextStyle;
public final fun component4 ()Landroidx/compose/ui/text/TextStyle;
public final fun component5 ()Landroidx/compose/ui/text/TextStyle;
public final fun component6 ()Landroidx/compose/ui/text/TextStyle;
public final fun copy (Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;)Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;
public static synthetic fun copy$default (Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;ILjava/lang/Object;)Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;
public fun equals (Ljava/lang/Object;)Z
public final fun getButton ()Landroidx/compose/ui/text/TextStyle;
public final fun getDeviceInfo ()Landroidx/compose/ui/text/TextStyle;
public final fun getMessage ()Landroidx/compose/ui/text/TextStyle;
public final fun getSectionLabel ()Landroidx/compose/ui/text/TextStyle;
public final fun getStacktrace ()Landroidx/compose/ui/text/TextStyle;
public final fun getTitle ()Landroidx/compose/ui/text/TextStyle;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/skydoves/snitcher/ui/theme/SnitcherTypography$Companion {
public final fun defaultTypography ()Lcom/skydoves/snitcher/ui/theme/SnitcherTypography;
}

Loading