Application Android et IOS pour l'amicale des élèves
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.

Utils.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // @flow
  2. import {Platform, StatusBar} from 'react-native';
  3. import ThemeManager from '../managers/ThemeManager';
  4. /**
  5. * Gets a sublist of the given list with items of the given ids only
  6. *
  7. * The given list must have a field id or key
  8. *
  9. * @param idList The ids of items to find
  10. * @param originalList The original list
  11. * @returns {[]}
  12. */
  13. export function getSublistWithIds<T>(
  14. idList: Array<string>,
  15. originalList: Array<{key: string, ...T}>,
  16. ): Array<{key: string, ...T} | null> {
  17. const subList = [];
  18. for (let i = 0; i < idList.length; i += 1) {
  19. subList.push(null);
  20. }
  21. let itemsAdded = 0;
  22. for (let i = 0; i < originalList.length; i += 1) {
  23. const item = originalList[i];
  24. if (idList.includes(item.key)) {
  25. subList[idList.indexOf(item.key)] = item;
  26. itemsAdded += 1;
  27. if (itemsAdded === idList.length) break;
  28. }
  29. }
  30. return subList;
  31. }
  32. /**
  33. * Updates status bar content color if on iOS only,
  34. * as the android status bar is always set to black.
  35. */
  36. export function setupStatusBar() {
  37. if (ThemeManager.getNightMode()) {
  38. StatusBar.setBarStyle('light-content', true);
  39. } else {
  40. StatusBar.setBarStyle('dark-content', true);
  41. }
  42. if (Platform.OS === 'android') {
  43. StatusBar.setBackgroundColor(
  44. ThemeManager.getCurrentTheme().colors.surface,
  45. true,
  46. );
  47. }
  48. }