小编Muh*_*mad的帖子

如何将抖动动画添加到视图(react-native)?

View当我的密码错误时,我想摇晃下面的内容。例如:

它应该是从位置 10 到位置 20 的 translateX 4 次 1 秒。然后应该停在原地 10。

放置 10(我的意思是 的 X 位置View

startShake = () => {
   Animated.loop(
       Animated.sequence([
         Animated.timing(this.animatedValue, {toValue: 1, duration: 150, easing: Easing.linear, useNativeDriver: true}),
         Animated.timing(this.animatedValue, {toValue: -1, duration: 300, easing: Easing.linear, useNativeDriver: true}),
         Animated.timing(this.animatedValue, {toValue: 0, duration: 150, easing: Easing.linear, useNativeDriver: true}),
       ])
   ).start();
}

<Animated.View style={{transform: [{
    translateX: this.animatedValue.interpolate({
        inputRange: [0, 0],
        outputRange: [0, 0]
     })
  }]
}}>

</Animated.View>
Run Code Online (Sandbox Code Playgroud)

react-native

12
推荐指数
1
解决办法
6906
查看次数

如何在 macos catalina 10.15 上的 bash_profile 中设置路径?

最近我安装了 macos 10.15 (catalina),我正在安装一些需要设置路径的软件,比如 java_home。

但我找不到 .bash_profile 或 .zshrc ?

macos

9
推荐指数
2
解决办法
2万
查看次数

useRef 钩子不适用于 lottie-react-native

我已将我class componentfunctional component钩子升级到钩子,但现在 ref 不起作用。

前:

class A extends Component{

   animation = null;

   onPress = ()=> {
      this.animation.play();
   }

   render(){
     return (
        <View>
          <LottieView
            source={require('./file.json')}
            ref={animation => {this.animation = animation}}
          />
          <Button onPress={this.onPress} title='click me' />
        </View>
     );
   }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码,它是类Component工作得很好。

但是我升级以下代码不起作用。

更新代码:

const A = props => {

   const animation = useRef(null);

   const onPress = ()=> {
      animation.play();
   }

   return (
        <View>
          <LottieView
            source={require('./file.json')}
            ref={animation}
          />
          <Button …
Run Code Online (Sandbox Code Playgroud)

react-native react-hooks

7
推荐指数
1
解决办法
2445
查看次数

如何使用 react-native-keychain 保存多个键值?

我有多个key, value,我不知道如何key, value在不同的地方存储多个。

是否有使用react-native-keychainpackage的以下代码的替代方法

await AsyncStorage.setItem('pincode',  '12345');
await AsyncStorage.setItem('userid',  '@user8383928');
await AsyncStorage.setItem('contacts',  JSON.stringify(contacts_array_of_object));
Run Code Online (Sandbox Code Playgroud)

以上每个都key, value saving可能在不同的函数和不同的时间调用。

问题在于react-native-keychain只有两个属性username, password

async () => {
  const username = 'zuck';
  const password = 'poniesRgr8';

  // Store the credentials
  await Keychain.setGenericPassword(username, password);

  try {
    // Retrieve the credentials
    const credentials = await Keychain.getGenericPassword();
    if (credentials) {
      console.log('Credentials successfully loaded for user ' + credentials.username);
    } else {
      console.log('No credentials stored');
    }
  } …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-keychain

6
推荐指数
2
解决办法
1935
查看次数

在flutter中使用provider时如何避免不必要的重建?

我在我的应用程序中使用提供程序,但是我面临不必要的构建。

class AllWidget extends StatelessWidget{

  @override
  Widget build(BuildContext context){
    print('state build called');
    return ChangeNotifierProvider(
            builder: (_) => MyCounter(),
            child: Column(children: <Widget>[
                  MyCounterText(),
                  MyIncreaseButton(),
                  MyDecreaseButton(),
            ],
          ),
    );
  }
}

class MyCounterText extends StatelessWidget{

  @override
  Widget build(BuildContext context) {
    final myCounter = Provider.of<MyCounter>(context, listen: false);
    print('MyCounterText');
    return Text(myCounter.num.toString());

  }
}

class MyIncreaseButton extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    final myCounter = Provider.of<MyCounter>(context, listen: false);
    print('MyIncreaseButton');
    return RaisedButton(
      child: Text('Increase +'),
      onPressed: ()=> myCounter.increament(),
    );

  } …
Run Code Online (Sandbox Code Playgroud)

provider dart flutter

5
推荐指数
3
解决办法
748
查看次数

使用 useReducer 函数挂钩更新状态的最佳方法是什么?

我有一个包含以下操作的列表:

  1. 使用函数将对象添加useReducer()到数组中。
  2. 使用函数从数组中删除对象useReducer()
  3. 使用函数将新数组替换为旧数组useReducer()

我需要最好、最安全的方式来更新我的列表。

目前我已经做了类似下面的事情,但它不能正常工作。

const reducer = (state, {type, value}) => {
    switch(type){
        case 'replacenewarray':
            return value;
        case 'additem':
            return {...state, value}
        case 'removeitem':
            return state.filter(item => item.room !== value);
        default:
            return state;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的功能组件如下:

const newArray = [
     {room: 'someroomid1', ....},
     {room: 'someroomid2', ....},
     {room: 'someroomid3', ....}
];

const itemToAdd = {room: 'someroomid4', ....};
const itemToRemoveWithRoomId = 'someroomid2';

export const Group = memo(props=> {

    const [list, setList] …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native react-hooks

5
推荐指数
1
解决办法
8692
查看次数

如何聆听 react-native-reanimated 中的价值变化?

我用Animatedfrom react-nativewith创建了一个简单的动画react-native-svg

这工作做得很好,

但是现在我改用了,react-native-reanimated因为我在他们的网站上读到,reanimated 比Animatedfrom react-native.

但是在这里我遇到了一个问题,那就是我找不到addListener监听值变化的函数。

代码Animated来自react-native

const circleRadius = new Animated.value(100);

circleRadius.addListener( circleRadius => {
       circleSVG.current.setNativeProps({ cx: circleRadius.value.toString() });
});
Run Code Online (Sandbox Code Playgroud)

如何addListener react-native-reanimated.

javascript react-native react-native-svg react-native-reanimated

4
推荐指数
1
解决办法
6782
查看次数

如何使用 Firestore 安全规则解密加密的 UID?

  1. 我得到的uid,当用户登录到火力使用第一次phone number
  2. 然后我加密了uid.
  3. 然后,我创建了一个集合作为users文件ID uid在像公司的FireStore: users/uid

  4. 现在用户希望写进去users/userId,如果 conditiontrue象下面这样:

  match /users/{userId} {
     allow write: if request.auth.uid == userId;
  }
Run Code Online (Sandbox Code Playgroud)

这里正如我所提到的number 2userId是加密的,但未request.auth.uid加密。

那么我们如何在这里解密呢(userId)

如果我使用散列 sha256,那么如何在客户端解码 sha256?

我在用 crypto-js

javascript firebase firebase-security google-cloud-firestore

4
推荐指数
1
解决办法
622
查看次数

业务逻辑和 UI 逻辑有什么区别?

我正在学习状态管理,flutter大部分时间遇到单词business logic ui logic,有一段时间presentation logic,我在互联网上搜索它,人们用不同的语言解释它,我无法更好地理解,有人可以展示这三种类型logic以一个例子的形式解释它很干净和容易吗?

dart flutter bloc flutter-bloc flutter-state

3
推荐指数
1
解决办法
1570
查看次数

如何在react-native-firebase中禁用recaptcha?

最近更新了@react-native-firebase/auth,现在Recaptcha verifier更新的版本里有添加。

但我不想,即使我没有配置任何Recaptcha,但它在使用电话号码登录时会自动打开react-native,这不是一个好的体验。

我怎样才能禁用它,这可能吗?

firebase react-native firebase-authentication react-native-firebase

3
推荐指数
1
解决办法
5117
查看次数