Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. var startMove = 0;
  2. var bottomSheet = Ti.UI.createView({
  3. height: 300,
  4. width: Ti.UI.FILL,
  5. backgroundColor: "red",
  6. bottom: -300,
  7. zIndex: 50
  8. });
  9.  
  10. var overlay = Ti.UI.createView({
  11. backgroundColor: "#000",
  12. opacity: 0,
  13. height: Ti.UI.FILL,
  14. widdth: Ti.UI.FILL,
  15. zIndex: 30
  16. });
  17.  
  18. var win = Ti.UI.createWindow({
  19. backgroundColor: "#fff"
  20. });
  21.  
  22. var button = Ti.UI.createButton({
  23. title: "Open menu",
  24. backgroundColor: "#2A7E42",
  25. height: 40,
  26. width: 100,
  27. color: "#fff"
  28. });
  29.  
  30. button.addEventListener('click', function(e) {
  31. showSheet();
  32. });
  33.  
  34. overlay.addEventListener('click', function() {
  35. hideSheet();
  36. })
  37.  
  38. function showSheet() {
  39. startMove = 0;
  40. win.add(overlay);
  41. overlay.animate({
  42. opacity: 0.4,
  43. duration: 300
  44. });
  45. bottomSheet.animate({
  46. bottom: -100,
  47. duration: 300
  48. })
  49. };
  50.  
  51. function hideSheet() {
  52. overlay.animate({
  53. opacity: 0,
  54. duration: 300
  55. }, function() {
  56. win.remove(overlay);
  57. });
  58.  
  59. bottomSheet.animate({
  60. bottom: -300,
  61. duration: 300
  62. });
  63. }
  64.  
  65. bottomSheet.addEventListener('touchstart', (e) => {
  66. // only allow the top 30 pixels to trigger the move
  67. if (e.y < 30) {
  68. startMove = e.y;
  69. } else {
  70. startMove = 0;
  71. }
  72. })
  73.  
  74. var position = -100;
  75. bottomSheet.addEventListener('touchmove', (e) => {
  76. if (startMove === 0) return;
  77. var difference = e.y - startMove;
  78. position -= difference;
  79. bottomSheet.bottom = position;
  80. startMove = e.y;
  81. console.log(position);
  82. });
  83.  
  84. bottomSheet.addEventListener('touchend', (e) => {
  85. if (bottomSheet.bottom > -150) {
  86. bottomSheet.animate({
  87. bottom: -100,
  88. duration: 300
  89. });
  90. } else {
  91. hideSheet();
  92. }
  93. startMove = 0;
  94. position = -100;
  95. })
  96.  
  97. win.add(button);
  98. win.add(bottomSheet);
  99. win.open();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement