Ingen beskrivning

explorer.js 3.4KB

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