55 ScrollView ,
66 type ViewStyle ,
77 type TextStyle ,
8+ type StyleProp ,
9+ StyleSheet ,
810} from "react-native" ;
911import SyntaxHighlighter , {
1012 type SyntaxHighlighterProps ,
@@ -18,8 +20,8 @@ import {
1820
1921export interface CodeHighlighterProps extends SyntaxHighlighterProps {
2022 hljsStyle : ReactStyle ;
21- containerStyle ?: ViewStyle ;
22- textStyle ?: TextStyle ;
23+ containerStyle ?: StyleProp < ViewStyle > ;
24+ textStyle ?: StyleProp < TextStyle > ;
2325}
2426
2527export const CodeHighlighter : FunctionComponent < CodeHighlighterProps > = ( {
@@ -37,18 +39,19 @@ export const CodeHighlighter: FunctionComponent<CodeHighlighterProps> = ({
3739 const getStylesForNode = ( node : rendererNode ) : TextStyle [ ] => {
3840 const classes : string [ ] = node . properties ?. className || [ ] ;
3941 return classes
40- . map < TextStyle | undefined > ( ( c : string ) => stylesheet [ c ] )
42+ . map ( ( c : string ) => stylesheet [ c ] )
4143 . filter ( ( c ) => ! ! c ) as TextStyle [ ] ;
4244 } ;
4345
4446 const renderNode = ( nodes : rendererNode [ ] , keyPrefix = "row" ) =>
4547 nodes . reduce < ReactNode [ ] > ( ( acc , node , index ) => {
4648 const keyPrefixWithIndex = `${ keyPrefix } _${ index } ` ;
4749 if ( node . children ) {
48- const styles = [
49- { ...textStyle , color : stylesheet . hljs ?. color } ,
50+ const styles = StyleSheet . flatten ( [
51+ textStyle ,
52+ { color : stylesheet . hljs ?. color } ,
5053 getStylesForNode ( node ) ,
51- ] ;
54+ ] ) ;
5255 acc . push (
5356 < Text style = { styles } key = { keyPrefixWithIndex } >
5457 { renderNode ( node . children , `${ keyPrefixWithIndex } _child` ) }
@@ -63,7 +66,7 @@ export const CodeHighlighter: FunctionComponent<CodeHighlighterProps> = ({
6366 return acc ;
6467 } , [ ] ) ;
6568
66- const nativeRenderer = ( props : rendererProps ) => {
69+ const renderer = ( props : rendererProps ) => {
6770 const { rows } = props ;
6871 return (
6972 < ScrollView
@@ -78,7 +81,7 @@ export const CodeHighlighter: FunctionComponent<CodeHighlighterProps> = ({
7881 return (
7982 < SyntaxHighlighter
8083 { ...rest }
81- renderer = { nativeRenderer }
84+ renderer = { renderer }
8285 CodeTag = { View }
8386 PreTag = { View }
8487 style = { { } }
0 commit comments