iamacup / react-native-markdown-display

React Native 100% compatible CommonMark renderer
MIT License
568 stars 167 forks source link

Dark Mode support #167

Closed tharpooljha closed 9 months ago

tharpooljha commented 2 years ago

What is best way to handle dark mode?

Uras-Somer commented 2 years ago

I am having difficulty tackling this as well, some help would be appreciated

NilsBaumgartner1994 commented 2 years ago

Maybe there could be a default style prop for this?

NilsBaumgartner1994 commented 2 years ago

import React, {FunctionComponent, useEffect, useState} from "react"; import Markdown from "react-native-markdown-display";

interface AppState { darkmode?: boolean, } export const ThemedMarkdown: FunctionComponent = (props) => {

let darkMode = false;
if(props.darkmode !== undefined){
    darkMode = props.darkmode
}

let darkModeTextColor = "white"
let lightModeTextColor = "black";

let textColor = darkMode ? darkModeTextColor : lightModeTextColor;
let fontSize = "18"; // or what you whish

//TODO add more adjustments
const style = {
    text: {
        color: textColor
    },
    body: {
        backgroundColor: "transparent",
        fontSize: fontSize
    },
    blockquote: {
        backgroundColor: 'transparent',
    },
    code_inline: {
        color: textColor,
        backgroundColor: 'transparent',
    },
}

return(
    <Markdown
        style={style}
    >
        {props.children}
    </Markdown>
)

}