No Description

explorer.js 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict'
  2. import React, {
  3. Component,
  4. PropTypes
  5. } from 'react';
  6. import {
  7. Platform,
  8. ScrollView,
  9. StyleSheet,
  10. Text,
  11. TouchableOpacity,
  12. View,
  13. WebView
  14. } from 'react-native';
  15. import AutoHeightWebView from 'react-native-autoheightwebview';
  16. export default class Explorer extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.html0 = `<p style="font-weight: 400;font-style: normal;font-size: 21px;line-height: 1.58;letter-spacing: -.003em;">Tags are great for describing the essence of your story in a single word or phrase, but stories are rarely about a single thing. <span style="background-color: transparent !important;background-image: linear-gradient(to bottom, rgba(146, 249, 190, 1), rgba(146, 249, 190, 1));">If I pen a story about moving across the country to start a new job in a car with my husband, two cats, a dog, and a tarantula, I wouldn’t only tag the piece with “moving”. I’d also use the tags “pets”, “marriage”, “career change”, and “travel tips”.</span></p>`;
  20. this.html1 = `<p>Tags are great for describing the essence of your story in a single word or phrase, but stories are rarely about a single thing. <span>If I pen a story about moving across the country to start a new job in a car with my husband, two cats, a dog, and a tarantula, I wouldn’t only tag the piece with “moving”. I’d also use the tags “pets”, “marriage”, “career change”, and “travel tips”.</span></p>`;
  21. this.script0 = '';
  22. this.script1 = `document.body.style.background = 'lightyellow';`;
  23. this.changeHtml = this.changeHtml.bind(this);
  24. this.changeScript = this.changeScript.bind(this);
  25. this.state = {
  26. html: this.html0,
  27. script: this.script0
  28. };
  29. }
  30. changeHtml() {
  31. this.setState(prevState => ({
  32. html: prevState.html === this.html0 ? this.html1 : this.html0
  33. }));
  34. }
  35. changeScript() {
  36. this.changeHtml();
  37. this.setState(prevState => ({
  38. script: prevState.script === this.script0 ? this.script1 : this.script0
  39. }));
  40. }
  41. render() {
  42. return (
  43. <ScrollView
  44. style={{
  45. backgroundColor: 'lightyellow'
  46. }}
  47. contentContainerStyle={{
  48. justifyContent: 'center',
  49. alignItems: 'center'
  50. }}>
  51. {
  52. <AutoHeightWebView
  53. html={this.state.html}
  54. customScript={this.state.script} />
  55. }
  56. <TouchableOpacity
  57. onPress={this.changeHtml}
  58. style={Styles.button}>
  59. <Text>change html</Text>
  60. </TouchableOpacity>
  61. <TouchableOpacity
  62. onPress={this.changeScript}
  63. style={Styles.button}>
  64. <Text>change script (have to change html to reload)</Text>
  65. </TouchableOpacity>
  66. </ScrollView>
  67. );
  68. }
  69. }
  70. const Styles = StyleSheet.create({
  71. button: {
  72. marginTop: 15,
  73. backgroundColor: 'aliceblue',
  74. borderRadius: 5,
  75. padding: 5
  76. }
  77. });