No Description

explorer.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 = 'cornflowerblue';`;
  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. enableAnimation
  52. onHeightUpdated={height => this.setState({ height })}
  53. source={{ html: this.state.html }}
  54. customScript={this.state.script} />
  55. <TouchableOpacity
  56. onPress={this.changeSource}
  57. style={Styles.button}>
  58. <Text>change source</Text>
  59. </TouchableOpacity>
  60. <TouchableOpacity
  61. onPress={this.changeScript}
  62. style={Styles.button}>
  63. <Text>change script (have to change source to reload on android)</Text>
  64. </TouchableOpacity>
  65. <Text style={{ padding: 5 }}>
  66. {this.state.height}
  67. </Text>
  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. });