暂无描述

explorer.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. 'use strict'
  2. import React, {
  3. Component,
  4. PropTypes
  5. } from 'react';
  6. import {
  7. findNodeHandle,
  8. requireNativeComponent,
  9. Dimensions,
  10. UIManager,
  11. Platform,
  12. ScrollView,
  13. StyleSheet,
  14. Text,
  15. TouchableOpacity,
  16. View,
  17. WebView
  18. } from 'react-native';
  19. import AutoHeightWebView from 'react-native-autoheightwebview';
  20. export default class Explorer extends Component {
  21. constructor(props) {
  22. super(props);
  23. 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>`;
  24. 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>`;
  25. this.script0 = '';
  26. this.script1 = `document.body.style.background = 'lightyellow';`;
  27. this.changeHtml = this.changeHtml.bind(this);
  28. this.changeScript = this.changeScript.bind(this);
  29. this.state = {
  30. html: this.html0,
  31. script: this.script0
  32. };
  33. }
  34. changeHtml() {
  35. this.setState(prevState => ({
  36. html: prevState.html === this.html0 ? this.html1 : this.html0
  37. }));
  38. }
  39. changeScript() {
  40. this.changeHtml();
  41. this.setState(prevState => ({
  42. script: prevState.script === this.script0 ? this.script1 : this.script0
  43. }));
  44. }
  45. render() {
  46. return (
  47. <ScrollView
  48. style={{
  49. backgroundColor: 'lightyellow'
  50. }}
  51. contentContainerStyle={{
  52. justifyContent: 'center',
  53. alignItems: 'center'
  54. }}>
  55. <AutoHeightWebView
  56. html={this.state.html}
  57. customScript={this.state.script} />
  58. <TouchableOpacity
  59. onPress={this.changeHtml}
  60. style={Styles.button}>
  61. <Text>change html</Text>
  62. </TouchableOpacity>
  63. <TouchableOpacity
  64. onPress={this.changeScript}
  65. style={Styles.button}>
  66. <Text>change script (have to change html to reload)</Text>
  67. </TouchableOpacity>
  68. </ScrollView>
  69. );
  70. }
  71. }
  72. const Styles = StyleSheet.create({
  73. button: {
  74. marginTop: 15,
  75. backgroundColor: 'aliceblue',
  76. borderRadius: 5,
  77. padding: 5
  78. }
  79. });