説明なし

Scrolling.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React, {Component} from 'react';
  2. import {Button, Text, View} from 'react-native';
  3. import WebView from 'react-native-webview';
  4. const HTML = `
  5. <!DOCTYPE html>\n
  6. <html>
  7. <head>
  8. <title>Hello World</title>
  9. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  10. <meta name="viewport" content="width=320, user-scalable=no">
  11. <style type="text/css">
  12. body {
  13. margin: 0;
  14. padding: 0;
  15. font: 62.5% arial, sans-serif;
  16. background: #ccc;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <p>Lorem ipsum dolor sit amet, virtute utroque voluptaria et duo, probo aeque partiendo pri at. Mea ut stet aliquip deterruisset. Inani erroribus principes ei mel, no dicit recteque delicatissimi usu. Ne has dolore nominavi, feugait hendrerit interesset vis ea, amet regione ne pri. Te cum amet etiam.</p>
  22. <p>Ut adipiscing neglegentur mediocritatem sea, suas abhorreant ius cu, ne nostrud feugiat per. Nam paulo facete iudicabit an, an brute mundi suavitate has, ex utamur numquam duo. Sea platonem argumentum instructior in, quo no prima inani perfecto. Ex illum postea copiosae has, ei mea sonet ocurreret.</p>
  23. <p>Has convenire erroribus cu, quo homero facilisis inciderint ea. Vix choro gloriatur definitionem an, te exerci debitis voluptaria pri, mea admodum antiopam neglegentur te. His ea iisque splendide, nam id malorum pertinacia. Iusto tempor in eos, vis debet erant an. An nostrum rationibus sit, et sed dicta delenit suscipiantur. Est dolore vituperatoribus in, ubique explicari est cu. Legere tractatos ut usu, probo atqui vituperata in usu, mazim nemore praesent pro no.</p>
  24. <p>Ei pri facilisi accusamus. Ut partem quaestio sit, an usu audiam quaerendum, ei qui hinc soleat. Fabulas phaedrum erroribus ut est. Intellegebat delicatissimi vis cu. His ea vidit libris facilis. Usu ne scripta legimus intellegam. Hendrerit urbanitas accommodare mei in.</p>
  25. <p>Brute appetere efficiendi has ne. Ei ornatus labores vis. Vel harum fierent no, ad erat partiendo vis, harum democritum duo at. Has no labitur vulputate. Has cu autem aperiam hendrerit, sed eu justo verear menandri.</p>
  26. </body>
  27. </html>
  28. `;
  29. type Props = {};
  30. type State = {
  31. scrollEnabled: boolean,
  32. lastScrollEvent: string
  33. };
  34. export default class Scrolling extends Component<Props, State> {
  35. state = {
  36. scrollEnabled: true,
  37. lastScrollEvent: ''
  38. };
  39. render() {
  40. return (
  41. <View>
  42. <View style={{ height: 120 }}>
  43. <WebView
  44. source={{html: HTML}}
  45. automaticallyAdjustContentInsets={false}
  46. onScroll={this._onScroll}
  47. scrollEnabled={this.state.scrollEnabled}
  48. />
  49. </View>
  50. <Button
  51. title={this.state.scrollEnabled ? 'Scroll enabled' : 'Scroll disabled'}
  52. onPress={() => this.setState({scrollEnabled: !this.state.scrollEnabled})}
  53. />
  54. <Text>Last scroll event:</Text>
  55. <Text>{this.state.lastScrollEvent}</Text>
  56. </View>
  57. );
  58. }
  59. _onScroll = event => {
  60. this.setState({lastScrollEvent: JSON.stringify(event.nativeEvent)});
  61. }
  62. }