transition.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. export var transition = function transition(showDefaultValue) {
  2. return Behavior({
  3. properties: {
  4. customStyle: String,
  5. show: {
  6. type: Boolean,
  7. value: showDefaultValue,
  8. observer: 'observeShow'
  9. },
  10. duration: {
  11. type: Number,
  12. value: 300
  13. }
  14. },
  15. data: {
  16. type: '',
  17. inited: false,
  18. display: false,
  19. supportAnimation: true
  20. },
  21. attached: function attached() {
  22. if (this.data.show) {
  23. this.show();
  24. }
  25. this.detectSupport();
  26. },
  27. methods: {
  28. detectSupport: function detectSupport() {
  29. var _this = this;
  30. wx.getSystemInfo({
  31. success: function success(info) {
  32. if (info && info.system && info.system.indexOf('iOS 8') === 0) {
  33. _this.set({
  34. supportAnimation: false
  35. });
  36. }
  37. }
  38. });
  39. },
  40. observeShow: function observeShow(value) {
  41. if (value) {
  42. this.show();
  43. } else {
  44. if (this.data.supportAnimation) {
  45. this.set({
  46. type: 'leave'
  47. });
  48. } else {
  49. this.set({
  50. display: false
  51. });
  52. }
  53. }
  54. },
  55. show: function show() {
  56. this.set({
  57. inited: true,
  58. display: true,
  59. type: 'enter'
  60. });
  61. },
  62. onAnimationEnd: function onAnimationEnd() {
  63. if (!this.data.show) {
  64. this.set({
  65. display: false
  66. });
  67. }
  68. }
  69. }
  70. });
  71. };