Skip to content

Commit

Permalink
fix: deprecate background property from UserTheme and fix h1 text color
Browse files Browse the repository at this point in the history
Changes:
- Deprecate background property from UserTheme it wasn't used and
background color can be easily override using flatlist props
- H1 styles wasn't inheriting user specified text color
  • Loading branch information
gmsgowtham committed Sep 30, 2023
1 parent 2a5e7d2 commit e819285
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/lib/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, {
import { FlatList, useColorScheme } from "react-native";
import type { MarkdownProps } from "./types";
import useMarkdown from "../hooks/useMarkdown";
import colors from "../theme/colors";

const Markdown = ({
value,
Expand Down Expand Up @@ -45,10 +44,7 @@ const Markdown = ({
maxToRenderPerBatch={8}
initialNumToRender={8}
style={{
backgroundColor:
colorScheme === "light"
? colors.light.background
: colors.dark.background,
backgroundColor: colorScheme === "light" ? "#ffffff" : "#000000",
}}
{...flatListProps}
data={rnElements}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/__tests__/__snapshots__/Markdown.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,7 @@ exports[`Headings Alternate Syntax: Heading level 1 1`] = `
{
"borderBottomColor": "#d0d7de",
"borderBottomWidth": 1,
"color": "#333333",
"fontSize": 32,
"fontWeight": "bold",
"letterSpacing": 0,
Expand Down Expand Up @@ -2460,6 +2461,7 @@ exports[`Headings Alternate Syntax: Heading level 1 1`] = `
{
"borderBottomColor": "#d0d7de",
"borderBottomWidth": 1,
"color": "#333333",
"fontSize": 32,
"fontWeight": "bold",
"letterSpacing": 0,
Expand Down Expand Up @@ -2588,6 +2590,7 @@ exports[`Headings Best Practice 1`] = `
{
"borderBottomColor": "#d0d7de",
"borderBottomWidth": 1,
"color": "#333333",
"fontSize": 32,
"fontWeight": "bold",
"letterSpacing": 0,
Expand Down Expand Up @@ -2698,6 +2701,7 @@ exports[`Headings Best Practice 1`] = `
{
"borderBottomColor": "#d0d7de",
"borderBottomWidth": 1,
"color": "#333333",
"fontSize": 32,
"fontWeight": "bold",
"letterSpacing": 0,
Expand Down Expand Up @@ -2758,6 +2762,7 @@ exports[`Headings Heading level 1 1`] = `
{
"borderBottomColor": "#d0d7de",
"borderBottomWidth": 1,
"color": "#333333",
"fontSize": 32,
"fontWeight": "bold",
"letterSpacing": 0,
Expand Down Expand Up @@ -2806,6 +2811,7 @@ exports[`Headings Heading level 1 1`] = `
{
"borderBottomColor": "#d0d7de",
"borderBottomWidth": 1,
"color": "#333333",
"fontSize": 32,
"fontWeight": "bold",
"letterSpacing": 0,
Expand Down
14 changes: 12 additions & 2 deletions src/theme/colors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
export type ColorKeysType = "background" | "code" | "link" | "text" | "border";
export type ColorsPropType = Record<ColorKeysType, string>;
import type { ColorValue } from "react-native";

export interface ColorsPropType {
code: ColorValue;
link: ColorValue;
text: ColorValue;
border: ColorValue;
/**
* @deprecated Use flatlist containerStyle or style prop for setting background color
*/
background?: ColorValue;
}

const colors: Record<"light" | "dark", ColorsPropType> = {
light: {
Expand Down
1 change: 1 addition & 0 deletions src/theme/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const getStyles = (
userStyles?.blockquote,
]),
h1: StyleSheet.flatten([
fontStyle.heading,
{
fontSize: 32,
lineHeight: 40,
Expand Down
4 changes: 2 additions & 2 deletions src/theme/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ImageStyle, TextStyle, ViewStyle } from "react-native";
import type { ColorKeysType } from "./colors";
import type { ColorsPropType } from "./colors";
import type { SpacingKeysType } from "./spacing";

export interface MarkedStyles {
Expand Down Expand Up @@ -28,6 +28,6 @@ export interface MarkedStyles {
}

export interface UserTheme {
colors?: Record<ColorKeysType, string>;
colors?: ColorsPropType;
spacing?: Record<SpacingKeysType, number>;
}

0 comments on commit e819285

Please sign in to comment.