Skip to content

Commit 2c33f1f

Browse files
authored
fix: deprecate container style prop (#104)
deprecate container style prop
2 parents 26624a7 + 2d244f5 commit 2c33f1f

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

example/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export default function App() {
7171
textStyle={styles.text}
7272
hljsStyle={hljsStyle}
7373
language="typescript"
74+
scrollViewProps={{
75+
contentContainerStyle: styles.codeContainer,
76+
}}
7477
>
7578
{CODE_STR}
7679
</CodeHighlighter>
@@ -82,7 +85,6 @@ export default function App() {
8285
const styles = StyleSheet.create({
8386
codeContainer: {
8487
paddingHorizontal: 16,
85-
minWidth: "100%",
8688
},
8789
text: {
8890
fontSize: 16,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"react-native",
4242
"ios",
4343
"android",
44+
"web",
4445
"code-hightlighter",
4546
"syntax-highlighter"
4647
],

rome.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,21 @@
88
"rules": {
99
"recommended": true
1010
},
11-
"ignore": ["dist", "node_modules", "example/node_modules", "example/.expo"]
11+
"ignore": [
12+
"dist",
13+
"node_modules",
14+
"example/node_modules",
15+
"example/.expo",
16+
"coverage"
17+
]
1218
},
1319
"formatter": {
14-
"ignore": ["dist", "node_modules", "example/node_modules", "example/.expo"]
20+
"ignore": [
21+
"dist",
22+
"node_modules",
23+
"example/node_modules",
24+
"example/.expo",
25+
"coverage"
26+
]
1527
}
1628
}

src/lib/CodeHighlighter.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ import {
2121

2222
export interface CodeHighlighterProps extends SyntaxHighlighterProps {
2323
hljsStyle: ReactStyle;
24-
containerStyle?: StyleProp<ViewStyle>;
2524
textStyle?: StyleProp<TextStyle>;
2625
scrollViewProps?: ScrollViewProps;
26+
/**
27+
* @deprecated, Use scrollViewProps.contentContainerStyle instead
28+
*/
29+
containerStyle?: StyleProp<ViewStyle>;
2730
}
2831

2932
export const CodeHighlighter: FunctionComponent<CodeHighlighterProps> = ({
3033
children,
31-
containerStyle,
3234
textStyle,
3335
hljsStyle,
3436
scrollViewProps,
37+
containerStyle,
3538
...rest
3639
}) => {
3740
const stylesheet: HighlighterStyleSheet = useMemo(
@@ -75,7 +78,11 @@ export const CodeHighlighter: FunctionComponent<CodeHighlighterProps> = ({
7578
<ScrollView
7679
{...scrollViewProps}
7780
horizontal
78-
contentContainerStyle={[stylesheet.hljs, containerStyle]}
81+
contentContainerStyle={[
82+
stylesheet.hljs,
83+
scrollViewProps?.contentContainerStyle,
84+
containerStyle,
85+
]}
7986
>
8087
<View>{renderNode(rows)}</View>
8188
</ScrollView>

src/lib/__tests__/CodeHighlighter.spec.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { atomOneDarkReasonable as hljsStyle } from "react-syntax-highlighter/dis
55
describe(CodeHighlighter, () => {
66
it("render", async () => {
77
const code = `const hello = "world"`;
8-
const r = await render(
8+
const r = render(
99
<CodeHighlighter hljsStyle={hljsStyle} language="typescript">
1010
{code}
1111
</CodeHighlighter>,
@@ -24,10 +24,12 @@ describe(CodeHighlighter, () => {
2424
const hello = "world";
2525
let foo = "bar";
2626
`;
27-
const r = await render(
27+
const r = render(
2828
<CodeHighlighter
2929
hljsStyle={hljsStyle}
30-
containerStyle={{ padding: 8, backgroundColor: "#000" }}
30+
scrollViewProps={{
31+
contentContainerStyle: { padding: 8, backgroundColor: "#000" },
32+
}}
3133
textStyle={{ color: "#fff", fontSize: 12 }}
3234
language="javascript"
3335
>

src/lib/__tests__/__snapshots__/CodeHighlighter.spec.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ exports[`CodeHighlighter render 1`] = `
2525
"color": "#abb2bf",
2626
},
2727
undefined,
28+
undefined,
2829
]
2930
}
3031
horizontal={true}
@@ -101,6 +102,7 @@ exports[`CodeHighlighter render with styles 1`] = `
101102
"backgroundColor": "#000",
102103
"padding": 8,
103104
},
105+
undefined,
104106
]
105107
}
106108
horizontal={true}

0 commit comments

Comments
 (0)