Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added monospace code font #4

Merged
merged 4 commits into from
May 1, 2022
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
22 changes: 14 additions & 8 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import 'react-native-gesture-handler';
import { NavigationContainer } from '@react-navigation/native';
import { StatusBar } from 'expo-status-bar';
import BottomTabNav from './navigation/BottomTabNav';
import "react-native-gesture-handler";
import { NavigationContainer } from "@react-navigation/native";
import { StatusBar } from "expo-status-bar";
import BottomTabNav from "./navigation/BottomTabNav";
import { useFonts } from "expo-font";
import AppLoading from "expo-app-loading";

export default function App() {
let [fontsLoaded] = useFonts({
Hack: require("./assets/fonts/Hack-Regular.ttf"),
});

if (!fontsLoaded) {
return <AppLoading />;
}

return (
<NavigationContainer >

<NavigationContainer>
<BottomTabNav />
<StatusBar style="light" />

</NavigationContainer>

);
}
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"expo": {
"name": "practical03-solution",
"slug": "practical03-solution",
"name": "codedash",
"slug": "codedash",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
Expand Down
Binary file added assets/fonts/Hack-Bold.ttf
Binary file not shown.
Binary file added assets/fonts/Hack-BoldItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Hack-Italic.ttf
Binary file not shown.
Binary file added assets/fonts/Hack-Regular.ttf
Binary file not shown.
26 changes: 24 additions & 2 deletions components/Code/Code.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import styles from './CodeStyle';
import Highlight, { defaultProps, Language } from "prism-react-renderer";
import {View, Text} from 'react-native';
import {View, Text, Platform} from 'react-native';
//import theme from "prism-react-renderer/themes/nightOwl";
import theme from "prism-react-renderer/themes/okaidia";
import { useFonts } from 'expo-font';



Expand All @@ -14,6 +15,17 @@ interface CodeProps {

function Code({code, language}: CodeProps){

let [fontsLoaded] = useFonts({
Hack: require("../../assets/fonts/Hack-Regular.ttf"),
});

const courierFont =
Platform.OS === "ios" && parseInt(Platform.Version, 10) >= 15
? "Courier New"
: "Courier";
const platformFont = Platform.OS === "ios" ? courierFont : "monospace";
const fontFamily = (fontsLoaded) ? "Hack" : platformFont;

return (
<View style={styles.container}>
<Highlight {...defaultProps} theme={theme} code={code} language={language}>
Expand All @@ -24,7 +36,17 @@ function Code({code, language}: CodeProps){
{line.map((token, key) => {
const props = getTokenProps({ token, key });
return (
<Text key={props.key} style={{color: props.style?.color ?? "#fff"} as any}>
<Text
key={props.key}
style={
{
color: props.style?.color ?? "#fff",
fontFamily: fontFamily,
fontSize: 12,
fontWeight: props.style?.fontWeight ?? "normal",
} as any
}
>
{props.children}
</Text>
);
Expand Down
1 change: 1 addition & 0 deletions components/Code/CodeStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const styles = StyleSheet.create({
flexDirection: "row",
alignItems: "flex-start",
justifyContent: "flex-start",
flexWrap: "wrap",
},
});

Expand Down
Loading