Skip to content
Open
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
14 changes: 5 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"react": "16.5.0",
"react-apollo": "^2.4.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-showdown": "^0.4.0",
"react-native-webview-autoheight": "^1.0.6",
"react-navigation": "^3.2.1",
"react-redux": "^6.0.0",
"redux": "^4.0.1",
"showdown": "^1.9.0",
"styled-components": "^4.1.3"
},
"devDependencies": {
Expand Down
71 changes: 40 additions & 31 deletions screens/SectionScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import {
StatusBar,
WebView,
Linking,
ScrollView
ScrollView,
Dimensions
} from "react-native";
import { Icon } from "expo";
import Markdown from "react-native-showdown";
import { PlayIcon } from "../components/Icons";
import MyWebView from 'react-native-webview-autoheight';
import showdown from 'showdown';

import defaultHTML from '../utils/defaultHTML';

const { width } = Dimensions.get('window');

const converter = new showdown.Converter();

class SectionScreen extends React.Component {
static navigationOptions = {
Expand All @@ -27,7 +35,7 @@ class SectionScreen extends React.Component {
render() {
const { navigation } = this.props;
const section = navigation.getParam("section");

const markdownToHtml = converter.makeHtml(section.content);
return (
<ScrollView>
<Container>
Expand Down Expand Up @@ -69,26 +77,30 @@ class SectionScreen extends React.Component {
</CloseView>
</TouchableOpacity>
<Content>
{/* <WebView
source={{ html: section.content + htmlStyles }}
scalesPageToFit={false}
scrollEnabled={false}
ref="webview"
onNavigationStateChange={event => {
console.log(event);

if (event.url != "about:blank") {
this.refs.webview.stopLoading();
Linking.openURL(event.url);
}
}}
/> */}
<Markdown
body={section.content}
pureCSS={htmlStyles}
scalesPageToFit={false}
scrollEnabled={false}
/>
<MyWebView
style={{
width: width - 40,
alignSelf: 'center',
marginBottom: 50,
marginTop: 20,
}}
source={{
html: defaultHTML
.replace('$title', '')
.replace('$body', markdownToHtml)
.replace('$pureCSS', htmlStyles),
}}
scalesPageToFit={false}
scrollEnabled={false}
startInLoadingState
ref="webview"
onNavigationStateChange={event => {
if (event.url.includes('http')) {
this.refs.webview.stopLoading();
Linking.openURL(event.url);
}
}}
/>
</Content>
</Container>
</ScrollView>
Expand Down Expand Up @@ -122,17 +134,17 @@ const htmlStyles = `
font-weight: 600;
margin-top: 50px;
}

p {
margin-top: 20px;
}

a {
color: #4775f2;
font-weight: 600;
text-decoration: none;
}

strong {
font-weight: 700;
}
Expand All @@ -151,16 +163,13 @@ const htmlStyles = `
border-radius: 10px;
margin-top: 20px;
}

code {
color: white;
}
`;

const Content = styled.View`
height: 1000px;
padding: 20px;
`;
const Content = styled.View``;

const Container = styled.View`
flex: 1;
Expand Down
32 changes: 32 additions & 0 deletions utils/defaultHTML.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="date=no">
<meta name="format-detection" content="address=no">
<meta name="format-detection" content="email=no">

<title>$title</title>

<style type="text/css">
body {
font-family: Roboto, '-apple-system', Helvetica Neue, Arial;
}
b, strong {
font-family: Roboto, '-apple-system', Helvetica Neue, Arial;
font-weight: bold;
}
h1, h2, h3, h4, h5, h6 {
font-family: Roboto, '-apple-system', Helvetica Neue, Arial;
font-weight: bold;
}
$pureCSS
</style>
</head>
<body>
$body
</body>
</html>`;