gpt4 book ai didi

javascript - 函数未在 React native 中定义

转载 作者:行者123 更新时间:2023-11-30 19:52:31 25 4
gpt4 key购买 nike

我在 React Native 中创建了一个循环进度条,错误是 get is rotateByStyle' is not defined。

这是我在一篇文章的帮助下设计的代码。这必须根据某些参数绘制带有进度的圆圈。我正在使用 ES6 定义函数

import React,{Component} from 'react';
import {Text, View, StyleSheet} from 'react-native';

rotateByStyle = (percent, base_degrees, clockwise) => {
let rotateBy = base_degrees;

if(clockwise) {
rotateBy = base_degrees + (percent * 3.6);
} else {
//anti clockwise progress
rotateBy = base_degrees - (percent * 3.6);
}

return {
transform:[{rotateZ: `${rotateBy}deg`}]
};
}

renderThirdLayer = (percent, commonStyles, ringColorStyle, ringBgColorStyle, clockwise, bgRingWidth, progressRingWidth, innerRingStyle, startDegrees) => {
let rotation = 45 + startDegrees;
let offsetLayerRotation = -135 + startDegrees;

if(!clockwise) {
rotation += 180;
offsetLayerRotation += 180;
}

if(percent > 50) {
return <View style= {[styles.secondProgressLayer,this.rotateByStyle((percent - 50), rotation, clockwise),
commonStyles, ringColorStyle, {borderWidth: progressRingWidth} ]}></View>
} else {
return <View
style={[styles.offsetLayer, innerRingStyle, ringBgColorStyle, {transform:[{rotateZ: `${offsetLayerRotation}deg`}], borderWidth: bgRingWidth}]}>
</View>
}
}

const CircularProgress = ({percent, radius, bgRingWidth, progressRingWidth, ringColor, ringBgColor, textFontSize, textFontWeight, clockwise, bgColor, startDegrees}) => {
const commonStyles = {
width: radius * 2,
height: radius * 2,
borderRadius: radius
};
}

let firstProgressLayerStyle;
let displayThickOffsetLayer = false;

if(percent > 50){
firstProgressLayerStyle = this.rotateByStyle(50, rotation, clockwise);
} else {
firstProgressLayerStyle = this.rotateByStyle(percent, rotation, clockwise);
if( progressRingWidth > bgRingWidth ) {
displayThickOffsetLayer = true;
}
}

let offsetLayerRotation = -135 + startDegrees;
if(!clockwise) {
offsetLayerRotation += 180;
}


export default CircularProgress;

我希望有一个带进度条的圆圈

最佳答案

解决方案

this.rotateByStyle

=>

rotateByStyle

为什么

rotateByStyle 不包含在 this 中。

In a method, this refers to the owner object. Alone, this refers to the global object. In a function, this refers to the global object. In a function, in strict mode, this is undefined. In an event, this refers to the element that received the event. Methods like call(), and apply() can refer this to any object.

官方:JS This

关于javascript - 函数未在 React native 中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54337799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com