小编Amr*_*tha的帖子

键盘可见时无法单击按钮 - 反应原生

我有一个 textInput 和一个按钮。当 textInput 被聚焦时,键盘会出现,但如果你在键盘可见的情况下点击按钮,首先键盘消失,然后只有你可以点击按钮。为什么?我怎样才能让它工作,以便可以在键盘可见的情况下点击按钮?在 android studio(android native)中开发的应用程序可以获取键盘可见的点击监听器。但是在本机反应中,它不起作用。如果你点击按钮以外的任何地方,那么键盘应该消失,不是吗?但是如果你点击键盘可见的按钮,btn 应该接收监听器。我正在android设备上测试它。

PS你可以在这里试试:https : //snack.expo.io/@codebyte99/addcomponents

<TextInput
    placeholder={'Type smth'}
    style={[{ borderBottomColor: 'gray', borderBottomWidth: 1 }]}
/>

<TouchableOpacity onPress={() => { this._onPressOut(); }}>
  <Text>click here</Text>
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)

react-native react-native-android

17
推荐指数
3
解决办法
7022
查看次数

如何为前棒棒糖创造涟漪效应

如何申请像连锁反应

我已将依赖项放在app/build.gradle中

应用程序/的build.gradle

dependencies {
    compile 'com.github.traex.rippleeffect:library:1.3'
}
Run Code Online (Sandbox Code Playgroud)

的build.gradle

allprojects{
    repositories{
        jcenter()
        maven(url "https://jitpack.io" }
Run Code Online (Sandbox Code Playgroud)

XML文件:

<com.andexert.library.RippleView
        android:id="@+id/rect1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
  <Button
      android:id="@+id/enterButton"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Save your user name" />
 </com.andexert.library.RippleView>
Run Code Online (Sandbox Code Playgroud)

Java类文件

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.save_user);
    editText=(EditText) findViewById(R.id.userNameEditText);
    button=(Button) findViewById(R.id.enterButton);

    sharedPreferences=getSharedPreferences(SHARED_NAME_STRING, MODE_PRIVATE);
    String userNameString=sharedPreferences.getString(USER_NAME_STRING, "");

    editText.setText(userNameString);

    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String string=editText.getText().toString();
            Intent intent=new Intent(SaveUser.this, MainActivity.class);
            intent.putExtra("user", string);

            SharedPreferences.Editor editor=sharedPreferences.edit();
            editor.putString(USER_NAME_STRING, string);
            editor.commit();

            startActivity(intent);

        }
    });
}
Run Code Online (Sandbox Code Playgroud)

它工作但我的问题是在涟漪效果完成之前打开另一个活动,当我按下后退按钮时剩余的涟漪完成.我该怎么解决?

android rippledrawable

16
推荐指数
3
解决办法
3万
查看次数

单击flatlist中的侦听器

如何添加点击监听器Flatlist

我的代码:

renderItem({item, index}){
    return <View style = {{
    flex:1,
    margin: 5, 
    minWidth: 170, 
    maxWidth: 223,
    height: 304,
    maxHeight: 304,
    backgroundColor: '#ccc',
    }}/>
}
render(){
return(<FlatList
contentContainerStyle={styles.list}
data={[{key: 'a'}, {key: 'b'},{key:'c'}]}
renderItem={this.renderItem}
/>);
}
}
Run Code Online (Sandbox Code Playgroud)

更新1:我使用了按钮,但它没有工作Flatlist.但是只使用按钮代替Flatlist,它可以工作.为什么它在FlatlistrenderItem 中不起作用?

_listener = () => {
    alert("clicked");
}

renderItem({item, index}){
    return<View>
      <Button
          title = "Button"
          color = "#ccc"
          onPress={this._listener}
      />
    </View>
}
Run Code Online (Sandbox Code Playgroud)

react-native react-native-flatlist

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

将数据从Activity传递到JobService

我想从Activity类获取lat和经度值到JobService.我怎样才能做到这一点?我尝试过使用Intent和putExtras等(请看下面的代码),但是无法正确使用.

MainActivity.class

protected void createLocationRequest(Bundle bundle) {

    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, new LocationCallback() {
        @Override
        public void onLocationResult(final LocationResult locationResult) {
            Log.i("onLocationResult", locationResult + "");
            latitude = locationResult.getLastLocation().getLatitude() + "";
            longitude = locationResult.getLastLocation().getLongitude() + "";
            Log.e("onLocationResult lat", latitude);
            Log.e("onLocationResult Lon", longitude);
            //I need to send latitude and longitude value to jobService? 
            //how to do that?

        //tried using intent but didn't seem to work
            //Intent mIntent = new Intent();
            //mIntent.putExtra("lat", latitude);
            //mIntent.putExtra("lon", longitude);
        }
    }, null);
}
Run Code Online (Sandbox Code Playgroud)

MyJobService类

public class MyJobService extends JobService …
Run Code Online (Sandbox Code Playgroud)

android jobservice

8
推荐指数
1
解决办法
4883
查看次数

图像 borderRadius 在本机反应中不起作用

我在 Image 中使用了 borderRadius 并循环它。它适用于某些图像,但其他图像是矩形的。如果我触摸它,它就会显示半径,并在未触摸时立即消失。使用溢出隐藏也不能解决问题。

我很困惑我使用了相同的风格但结果不同。我只在 Android 设备上测试过。

https://snack.expo.io/@codebyte99/multiplearrays

代码:

<TouchableOpacity activeOpacity={0.8}>
  <ImageBackground
    source={{
      uri: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcREX0q18KDbtN-obe1EFxAwNg27xgR_KItZ7U8MkXnH7zBCEr_ASQ",
    }}
    style={[
      {
        width: 200,
        height: 80,
        resizeMode: "center",
        justifyContent: "flex-end",
        alignItems: "center",
        margin: 5,
        marginRight: 0,
        marginTop: 0,
        marginBottom: 5,
        borderRadius: 6,
        overflow: "hidden",
      },
    ]}
  >
    <Text>{childItem.title}</Text>
  </ImageBackground>
</TouchableOpacity>;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

react-native

6
推荐指数
1
解决办法
8155
查看次数

垂直对齐顶部与图像中的调整大小模式覆盖 - 反应原生

我有一个高度大于宽度的矩形图像。所以使用了 resizeMode='cover'。它保持纵横比相等,但从图像的中心和顶部扩展看不到。我想要做的是保持纵横比并从顶部显示图像。

请尝试小吃中的代码:https : //snack.expo.io/@codebyte99/new-addition-to-home-page

代码:

<View>
    <Image
      source={{
        uri:
          'https://img.kpopmap.com/2017/09/HanYeSul-min.jpg',
      }}
      resizeMode={'cover'}
      style={{ width: 120, height: 120 }}
    />
 </View>
Run Code Online (Sandbox Code Playgroud)

现在图片

在此处输入图片说明

想象我想要实现的目标

在此处输入图片说明

图片原件

在此处输入图片说明

我想从顶部对齐图像,以便清楚地看到头部。我们可以通过 object-fit:cover 和 object-position:top 在 css 中做到这一点,但是如何在 react native 中做到这一点?

react-native

6
推荐指数
1
解决办法
487
查看次数

React-native 地图:带有动画 API 的 MapView 在 Android 中滞后太多

我刚刚从react-native-map 复制了具有动画API 的MapView。它可以工作,但在 Android 设备(三星)中性能太慢。有人经历过吗?怎么解决呢?

观看此处的视频

PS我不需要地图顶部的组件向上移动,所以我删除了变换Y。保留与否对性能没有影响。该应用程序在一段时间后挂起。

代码:

import React from 'react';
import {
  StyleSheet,
  View,
  Dimensions,
  Animated,
} from 'react-native';

import {
  ProviderPropType,
  Animated as AnimatedMap,
  AnimatedRegion,
  Marker,
} from 'react-native-maps';
import PanController from './PanController';
import PriceMarker from './AnimatedPriceMarker';

const screen = Dimensions.get('window');

const ASPECT_RATIO = screen.width / screen.height;
const LATITUDE = 37.78825;
const LONGITUDE = -122.4324;
const LATITUDE_DELTA = 0.0922;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;

const ITEM_SPACING = 10;
const ITEM_PREVIEW = 10;
const ITEM_WIDTH = …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-maps

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

反应原生中flatList的性能问题

我已经尝试过flatlist但它在android中有一些性能问题.

  1. 当我向下滚动时,它会加载列表.但之后,它向上滚动时显示空白.

  2. 到达屏幕的末尾后,它会停止一段时间,然后加载数据.为什么不在底部显示加载器(活动指示器)?为什么onEndReached和onEndReachedThreshold不起作用?

Plz在这里看一下视频

https://youtu.be/5tkkEAUEAHM

我的代码:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  FlatList,
  ActivityIndicator,
} from 'react-native';
import { List, ListItem, SearchBar } from "react-native-elements";

export default class FlatListExample extends Component
{
constructor(props) {
    super(props);

    this.state = {
      loading: false,
      data: [],
      page: 1,
      seed: 1,
      error: null,
      refreshing: false,
    };
  }

  componentDidMount() {
    this.makeRemoteRequest();
  }

  makeRemoteRequest = () => {
    const { page, seed } = this.state;
    const url = …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-flatlist

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

卸载应用程序不会删除 SharedPreferences 的值

我已经使用 SharedPreferences 来检查它是否已经登录。但是,在我登录并卸载应用程序后,在重新安装应用程序时它总是给出真实的值,并且不会显示登录页面。为什么?是不是当应用程序被卸载时,sharedPreference中的值也应该消失了?它可以在未签名的 apk 中运行(即当您直接通过 android studio 安装应用程序时),但一旦我使用签名的 apk,问题就会出现。它发生在诺基亚 5 和其他一些设备上,但在其他 Android 设备上工作得很好。我该如何解决?

public class MainActivity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);

        **//always gives true value here...**
        Log.e("loginStatus", pref.getBoolean("activity_executed", false) + "");
        if (pref.getBoolean("activity_executed", false)) {
            Log.e("loginStatus", pref.getBoolean("activity_executed", false) + "");

            Intent intent = new Intent(this, LiveTrack.class);
            startActivity(intent);
            finish();
        } else {
            Log.e("loginStatus", "notlogin");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

android sharedpreferences

2
推荐指数
1
解决办法
1577
查看次数

在本机反应中一次水平滚动两行

我有一个水平滚动视图,其中有 2 行作为一个单元水平滑动。以下是测试代码,它可以工作,但相同的数据被渲染两次。IE。“在第一列的两行中发布 1”,“在第二列的两行中发布 2”。我需要的是第一列中的“post 1”和“post 2”,第二列中的“post 3”和“post 4”等等。它就像在水平滚动视图中具有 2 行和几列的表格布局。

https://snack.expo.io/@codebyte99/multipleloop

renderRow(item) {
    return (
      <View style={{ margin: 5 }}>   
        <View style={{
            backgroundColor: 'red',
            width: 200,
            height: 100,
            marginBottom: 1,
          }}>
          <Text>{item.title}</Text>
        </View> 

        <View
          style={{
            backgroundColor: 'green',
            width: 200,
            height: 100,
            marginBottom: 1,
          }}>
          <Text>{item.title}</Text>
        </View>
      </View>
    );
}

render() {
    return (
      <View style={styles.container}>
        <ScrollView horizontal={true}>
          {this.state.data.map(item => this.renderRow(item))}
        </ScrollView>
      </View>
    );
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

react-native

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