瀏覽代碼

CANVAS begin

Leon 2 年之前
父節點
當前提交
23aee87e18
共有 2 個文件被更改,包括 39 次插入0 次删除
  1. 37 0
      src/components_base/input/dial.tsx
  2. 2 0
      src/pages/clock.tsx

+ 37 - 0
src/components_base/input/dial.tsx

@@ -0,0 +1,37 @@
+import { View, Text, Canvas } from '@tarojs/components'
+import Taro, { useDidShow, useReady } from '@tarojs/taro'
+import { useLoad } from '@tarojs/taro'
+import { useEffect, useRef, useState } from 'react'
+import { useTranslation } from 'react-i18next'
+
+export default function Dial() {
+    const canvasRef = useRef();
+    // const [ctx, setCtx] = useState(null);
+
+    // useEffect(() => {
+    //     if (canvasRef.current) {
+    //         const context = canvasRef.current.getContext('2d');
+    //         setCtx(context);
+    //     }
+    // }, []);
+
+    // useEffect(() => {
+    //     if (ctx) {
+    //         drawCircle();
+    //     }
+    // }, [ctx]);
+
+    // const drawCircle = () => {
+    //     ctx.beginPath();
+    //     ctx.arc(100, 100, 50, 0, 2 * Math.PI);
+    //     ctx.stroke();
+    // };
+
+    return (
+        <View>
+            <Canvas ref={canvasRef}
+                style={{ width: '200px', height: '200px' }}
+                canvasId="circleCanvas"></Canvas>
+        </View>
+    )
+}

+ 2 - 0
src/pages/clock.tsx

@@ -2,6 +2,7 @@ import { View, Text,Button } from '@tarojs/components'
 import Taro, { useLoad } from '@tarojs/taro'
 import { useTranslation } from 'react-i18next'
 import './clock.scss'
+import Dial from '@/components_base/input/dial'
 // import { changeLanguage } from 'i18next'
 
 export default function Index() {
@@ -22,6 +23,7 @@ export default function Index() {
             <Text>{t('languageList.en')}</Text>
             <Button onTap={()=>changeLanguage()}>{t('languageList.switch_language')}</Button>
             <Text>1234</Text>
+            <Dial />
         </View>
     )
 }