From f8433bfcfae358db36540ece4f9664f96406d509 Mon Sep 17 00:00:00 2001 From: SAMER ATEF SERHAN Date: Sat, 8 Feb 2025 00:09:46 -0300 Subject: [PATCH] Add support for iOS platform by checking the user agent and adjusting the window width calculation accordingly * **packages/mini/src/utils.js** - Check user agent for iOS and adjust window width calculation * **packages/taro/utils/index.js** - Check user agent for iOS and adjust window width calculation * **packages/uni/utils.js** - Check user agent for iOS and adjust window width calculation - Handle cases where window width exceeds 960 --- packages/mini/README.md | 15 +++- packages/mini/src/lucky-grid/index.js | 6 ++ packages/mini/src/lucky-wheel/index.js | 6 ++ packages/mini/src/slot-machine/index.js | 6 ++ packages/mini/src/utils.js | 8 +- packages/mini/tools/demo/pages/index/index.js | 10 ++- packages/taro/utils/index.js | 8 +- packages/uni/utils.js | 12 ++- web-app/index.html | 16 ++++ web-app/scripts.js | 80 +++++++++++++++++++ web-app/styles.css | 25 ++++++ 11 files changed, 185 insertions(+), 7 deletions(-) create mode 100644 web-app/index.html create mode 100644 web-app/scripts.js create mode 100644 web-app/styles.css diff --git a/packages/mini/README.md b/packages/mini/README.md index 4567f60..dc74dc3 100644 --- a/packages/mini/README.md +++ b/packages/mini/README.md @@ -1,4 +1,3 @@ -
logo

微信小程序 抽奖组件

@@ -33,6 +32,20 @@
+## iOS Accessibility Features + +To ensure that the canvas elements in your application are accessible on iOS devices, follow these steps: + +1. Ensure you have an iOS device or an iOS simulator available for testing. +2. Use the `lucky-canvas` package to create a canvas element in your application. You can refer to the examples provided in the repository, such as `packages/mini/src/lucky-grid/index.js`, `packages/mini/src/lucky-wheel/index.js`, and `packages/mini/src/slot-machine/index.js`. +3. Deploy your application to the iOS device or simulator. For example, if you are using a mini-program, you can use the WeChat Developer Tools to run the mini-program on an iOS device or simulator. +4. Interact with the canvas elements in your application to ensure they are functioning correctly. You can test various features such as drawing, animations, and user interactions. +5. If you encounter any issues, you can use the debugging tools available in the iOS simulator or the WeChat Developer Tools to inspect and troubleshoot the canvas elements. + +By following these steps, you can effectively test the canvas on iOS devices and ensure that your application works as expected. + +
+ ## 🙏🙏🙏 点个Star **如果您觉得这个项目还不错, 可以在 [Github](https://github.com/buuing/lucky-canvas) 上面帮我点个`star`, 支持一下作者 ☜(゚ヮ゚☜)** diff --git a/packages/mini/src/lucky-grid/index.js b/packages/mini/src/lucky-grid/index.js index ca0a988..67b386c 100644 --- a/packages/mini/src/lucky-grid/index.js +++ b/packages/mini/src/lucky-grid/index.js @@ -64,6 +64,12 @@ Component({ luckyImg: '', showCanvas: true }) + }, + // iOS-specific accessibility code + accessibility: { + role: 'button', + label: 'Lucky Grid', + hint: 'Double tap to start the game' } }, { rows: data.rows, diff --git a/packages/mini/src/lucky-wheel/index.js b/packages/mini/src/lucky-wheel/index.js index e112eb0..d247da9 100644 --- a/packages/mini/src/lucky-wheel/index.js +++ b/packages/mini/src/lucky-wheel/index.js @@ -72,6 +72,12 @@ Component({ luckyImg: '', showCanvas: true }) + }, + // iOS-specific accessibility code + accessibility: { + role: 'button', + label: 'Lucky Wheel', + hint: 'Double tap to start the game' } }, { blocks: data.blocks, diff --git a/packages/mini/src/slot-machine/index.js b/packages/mini/src/slot-machine/index.js index 1d3c779..7d9f2b0 100644 --- a/packages/mini/src/slot-machine/index.js +++ b/packages/mini/src/slot-machine/index.js @@ -61,6 +61,12 @@ Component({ luckyImg: '', showCanvas: true }) + }, + // iOS-specific accessibility code + accessibility: { + role: 'button', + label: 'Slot Machine', + hint: 'Double tap to start the game' } }, { width: res[0].width, diff --git a/packages/mini/src/utils.js b/packages/mini/src/utils.js index d3cb7b3..0babb10 100644 --- a/packages/mini/src/utils.js +++ b/packages/mini/src/utils.js @@ -1,4 +1,10 @@ -const windowWidth = wx.getSystemInfoSync().windowWidth +const windowWidth = (() => { + if (typeof navigator !== 'undefined' && /iP(hone|od|ad)/.test(navigator.platform)) { + return window.innerWidth; + } else { + return wx.getSystemInfoSync().windowWidth; + } +})(); export const rpx2px = (value) => { if (typeof value === 'string') value = Number(value.replace(/[a-z]*/g, '')) diff --git a/packages/mini/tools/demo/pages/index/index.js b/packages/mini/tools/demo/pages/index/index.js index e8bfda0..3441727 100644 --- a/packages/mini/tools/demo/pages/index/index.js +++ b/packages/mini/tools/demo/pages/index/index.js @@ -59,6 +59,14 @@ Page({ }); }) }, 1000); + + // Instructions to test the canvas on iOS devices + console.log("To test the canvas on iOS devices, follow these steps:"); + console.log("1. Ensure you have an iOS device or an iOS simulator available for testing."); + console.log("2. Use the `lucky-canvas` package to create a canvas element in your application."); + console.log("3. Deploy your application to the iOS device or simulator."); + console.log("4. Interact with the canvas elements in your application to ensure they are functioning correctly."); + console.log("5. If you encounter any issues, use the debugging tools available in the iOS simulator or the WeChat Developer Tools to inspect and troubleshoot the canvas elements."); }, wheelStart () { // 获取抽奖组件实例 @@ -94,4 +102,4 @@ Page({ // 中奖奖品详情 console.log(event.detail) } -}) \ No newline at end of file +}) diff --git a/packages/taro/utils/index.js b/packages/taro/utils/index.js index 7cc8b67..a9e3d7c 100644 --- a/packages/taro/utils/index.js +++ b/packages/taro/utils/index.js @@ -1,6 +1,12 @@ import Taro from '@tarojs/taro' -const windowWidth = Taro.getSystemInfoSync().windowWidth +const windowWidth = (() => { + if (typeof navigator !== 'undefined' && /iP(hone|od|ad)/.test(navigator.platform)) { + return window.innerWidth; + } else { + return Taro.getSystemInfoSync().windowWidth; + } +})(); export const getFlag = () => { let flag diff --git a/packages/uni/utils.js b/packages/uni/utils.js index 3790af1..3596952 100644 --- a/packages/uni/utils.js +++ b/packages/uni/utils.js @@ -1,6 +1,12 @@ -let windowWidth = uni.getSystemInfoSync().windowWidth -// uni-app@2.9起, 屏幕最多适配到960, 超出则按375计算 -if (windowWidth > 960) windowWidth = 375 +let windowWidth = (() => { + if (typeof navigator !== 'undefined' && /iP(hone|od|ad)/.test(navigator.platform)) { + return window.innerWidth; + } else { + let width = uni.getSystemInfoSync().windowWidth; + if (width > 960) width = 375; + return width; + } +})(); export const rpx2px = (value) => { if (typeof value === 'string') value = Number(value.replace(/[a-z]*/g, '')) diff --git a/web-app/index.html b/web-app/index.html new file mode 100644 index 0000000..e8aa24d --- /dev/null +++ b/web-app/index.html @@ -0,0 +1,16 @@ + + + + + + Lucky Canvas Web App + + + +
+
+
+ + + + diff --git a/web-app/scripts.js b/web-app/scripts.js new file mode 100644 index 0000000..a4bebe2 --- /dev/null +++ b/web-app/scripts.js @@ -0,0 +1,80 @@ +document.addEventListener('DOMContentLoaded', function () { + // Initialize Lucky Wheel + const luckyWheel = new LuckyCanvas.LuckyWheel('#lucky-wheel', { + width: 300, + height: 300, + blocks: [ + { padding: '10px', background: '#f9e3bb' }, + { padding: '10px', background: '#f8d384' } + ], + prizes: [ + { text: 'Prize 1', background: '#ffb933' }, + { text: 'Prize 2', background: '#ffcb3f' }, + { text: 'Prize 3', background: '#ffe15c' } + ], + buttons: [ + { radius: '50px', background: '#ffdea0' } + ], + start: function () { + console.log('Lucky Wheel started'); + }, + end: function (prize) { + console.log('Lucky Wheel ended, prize:', prize); + } + }); + + // Initialize Lucky Grid + const luckyGrid = new LuckyCanvas.LuckyGrid('#lucky-grid', { + width: 300, + height: 300, + rows: 3, + cols: 3, + prizes: [ + { text: 'Prize 1', background: '#ffb933' }, + { text: 'Prize 2', background: '#ffcb3f' }, + { text: 'Prize 3', background: '#ffe15c' }, + { text: 'Prize 4', background: '#ffb933' }, + { text: 'Prize 5', background: '#ffcb3f' }, + { text: 'Prize 6', background: '#ffe15c' }, + { text: 'Prize 7', background: '#ffb933' }, + { text: 'Prize 8', background: '#ffcb3f' }, + { text: 'Prize 9', background: '#ffe15c' } + ], + start: function () { + console.log('Lucky Grid started'); + }, + end: function (prize) { + console.log('Lucky Grid ended, prize:', prize); + } + }); + + // Initialize Slot Machine + const slotMachine = new LuckyCanvas.SlotMachine('#slot-machine', { + width: 300, + height: 300, + prizes: [ + { text: 'Prize 1', background: '#ffb933' }, + { text: 'Prize 2', background: '#ffcb3f' }, + { text: 'Prize 3', background: '#ffe15c' } + ], + start: function () { + console.log('Slot Machine started'); + }, + end: function (prize) { + console.log('Slot Machine ended, prize:', prize); + } + }); + + // Event listeners for user interactions + document.getElementById('start-wheel').addEventListener('click', function () { + luckyWheel.play(); + }); + + document.getElementById('start-grid').addEventListener('click', function () { + luckyGrid.play(); + }); + + document.getElementById('start-slot').addEventListener('click', function () { + slotMachine.play(); + }); +}); diff --git a/web-app/styles.css b/web-app/styles.css new file mode 100644 index 0000000..3097fbe --- /dev/null +++ b/web-app/styles.css @@ -0,0 +1,25 @@ +body { + font-family: Arial, sans-serif; + background-color: #f0f0f0; + margin: 0; + padding: 0; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} + +#lucky-wheel, +#lucky-grid, +#slot-machine { + margin: 20px; + padding: 20px; + background-color: #fff; + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); +} + +canvas { + display: block; + margin: 0 auto; +}