Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomHTML.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* eslint-disable flowtype/require-parameter-type */
  2. // @flow
  3. import * as React from 'react';
  4. import {Text, withTheme} from 'react-native-paper';
  5. import HTML from 'react-native-render-html';
  6. import {Linking} from 'react-native';
  7. import type {CustomThemeType} from '../../managers/ThemeManager';
  8. type PropsType = {
  9. theme: CustomThemeType,
  10. html: string,
  11. };
  12. /**
  13. * Abstraction layer for Agenda component, using custom configuration
  14. */
  15. class CustomHTML extends React.Component<PropsType> {
  16. openWebLink = (event: {...}, link: string) => {
  17. Linking.openURL(link);
  18. };
  19. getBasicText = (
  20. htmlAttribs,
  21. children,
  22. convertedCSSStyles,
  23. passProps,
  24. ): React.Node => {
  25. // eslint-disable-next-line react/jsx-props-no-spreading
  26. return <Text {...passProps}>{children}</Text>;
  27. };
  28. getListBullet = (): React.Node => {
  29. return <Text>- </Text>;
  30. };
  31. render(): React.Node {
  32. const {props} = this;
  33. // Surround description with p to allow text styling if the description is not html
  34. return (
  35. <HTML
  36. html={`<p>${props.html}</p>`}
  37. renderers={{
  38. p: this.getBasicText,
  39. li: this.getBasicText,
  40. }}
  41. listsPrefixesRenderers={{
  42. ul: this.getListBullet,
  43. }}
  44. ignoredTags={['img']}
  45. ignoredStyles={['color', 'background-color']}
  46. onLinkPress={this.openWebLink}
  47. />
  48. );
  49. }
  50. }
  51. export default withTheme(CustomHTML);