Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

functions.native.tsx 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react';
  2. import { Text, TextStyle } from 'react-native';
  3. import { brandedDialog as styles } from './native/styles';
  4. /**
  5. * Renders a specific {@code string} which may contain HTML.
  6. *
  7. * @param {string|undefined} html - The {@code string} which may
  8. * contain HTML to render.
  9. * @returns {ReactElement[]|string}
  10. */
  11. export function renderHTML(html?: string) {
  12. if (typeof html === 'string') {
  13. // At the time of this writing, the specified HTML contains a couple
  14. // of spaces one after the other. They do not cause a visible
  15. // problem on Web, because the specified HTML is rendered as, well,
  16. // HTML. However, we're not rendering HTML here.
  17. // eslint-disable-next-line no-param-reassign
  18. html = html.replace(/\s{2,}/gi, ' ');
  19. // Render text in <b>text</b> in bold.
  20. const opening = /<\s*b\s*>/gi;
  21. const closing = /<\s*\/\s*b\s*>/gi;
  22. let o;
  23. let c;
  24. let prevClosingLastIndex = 0;
  25. const r = [];
  26. // eslint-disable-next-line no-cond-assign
  27. while (o = opening.exec(html)) {
  28. closing.lastIndex = opening.lastIndex;
  29. // eslint-disable-next-line no-cond-assign
  30. if (c = closing.exec(html)) {
  31. r.push(html.substring(prevClosingLastIndex, o.index));
  32. r.push(
  33. <Text style = { (styles.boldDialogText as TextStyle) }>
  34. { html.substring(opening.lastIndex, c.index) }
  35. </Text>);
  36. opening.lastIndex
  37. = prevClosingLastIndex
  38. = closing.lastIndex;
  39. } else {
  40. break;
  41. }
  42. }
  43. if (prevClosingLastIndex < html.length) {
  44. r.push(html.substring(prevClosingLastIndex));
  45. }
  46. return r;
  47. }
  48. return html;
  49. }