safeAreaBehavior.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { getSystemInfo, checkIPhoneX } from './checkIPhoneX'
  2. const defaultSafeArea = {
  3. top: false,
  4. bottom: false,
  5. }
  6. const setSafeArea = (params) => {
  7. if (typeof params === 'boolean') {
  8. return Object.assign({}, defaultSafeArea, {
  9. top: params,
  10. bottom: params,
  11. })
  12. } else if (params !== null && typeof params === 'object') {
  13. return Object.assign({}, defaultSafeArea)
  14. } else if (typeof params === 'string') {
  15. return Object.assign({}, defaultSafeArea, {
  16. [params]: true,
  17. })
  18. }
  19. return defaultSafeArea
  20. }
  21. export default Behavior({
  22. properties: {
  23. safeArea: {
  24. type: [Boolean, String, Object],
  25. value: false,
  26. },
  27. },
  28. observers: {
  29. safeArea(newVal) {
  30. this.setData({ safeAreaConfig: setSafeArea(newVal) })
  31. },
  32. },
  33. definitionFilter(defFields) {
  34. const { statusBarHeight } = getSystemInfo() || {}
  35. const isIPhoneX = checkIPhoneX()
  36. Object.assign(defFields.data = (defFields.data || {}), {
  37. safeAreaConfig: defaultSafeArea,
  38. statusBarHeight,
  39. isIPhoneX,
  40. })
  41. },
  42. })