小编Tim*_*Tim的帖子

设置为透明色时,React Native TextInput背景色看起来是双层的

我有一个TextInputbackgroundColor'rgba(255,255,255,0.16)',如下:

小吃示例:https//snack.expo.io/rkEhXn6Nr

import * as React from 'react';
import { TextInput, View, StyleSheet } from 'react-native';

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <TextInput
          style={styles.paragraph}
          value={"bleep bleep bleep bleep"}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: 'green',
  },
  paragraph: {
    padding: 24,
    margin: 24,
    fontSize: 24,
    textAlign: 'center',
    backgroundColor: 'rgba(255,255,255,0.16)',
  },
});
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

看起来好像有一个具有该背景色的视图(THERE IS N'T)和一个文本元素,其内部也包裹了该背景色。我怎样才能只有“视图”才能具有该背景色?在android上看起来还不错:

在此处输入图片说明

ios react-native

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

我怎样才能使用bootstrap与rails做出反应

我试过使用npm包reactstrap.我的组件:

import { Col, Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap';
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

ExecJS::ProgramError at /dir/xyz
TypeError: require is not a function
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails sprockets reactjs reactstrap

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

React 和 i18n - 通过在 URL 中添加语言环境进行翻译

您好,我正在构建一个演示应用程序只是为了学习 React,但我对翻译过程有点困惑。我想要做的是拥有一个多语言网站,默认语言为“希腊语”,辅助语言为“英语”。当启用希腊语时,URL 不应在 URL 中包含任何区域设置,但当启用英语时,应使用 /en/ 重写 URL。

i18n 配置

import translationEn from './locales/en/translation';
import translationEl from './locales/el/translation';
import Constants from './Utility/Constants';

i18n
    .use(Backend)
    .use(LanguageDetector)
    .use(initReactI18next)
    .init({
        fallbackLng: 'el',
        debug: true,
        ns: ['translations'],
        defaultNS: 'translations',
        detection: {
            order: ['path'],
            lookupFromPathIndex: 0,

        },
        resources: {

            el: {
                translations: translationEl
            },
            en: {
                translations: translationEn

            }
        },

        interpolation: {
            escapeValue: false, // not needed for react as it escapes by default

        }
    }, () => {

        // Why the fuck this doesnt …
Run Code Online (Sandbox Code Playgroud)

internationalization i18next reactjs react-router

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

TensorFlow图像分类

我对TensorFlow很新.我正在使用自己的培训数据库进行图像分类.

但是,在我训练自己的数据集后,我不知道如何对输入图像进行分类.

这是我准备自己的数据集的代码

filenames = ['01.jpg', '02.jpg', '03.jpg', '04.jpg']
label = [0,1,1,1]
filename_queue = tf.train.string_input_producer(filenames)

reader = tf.WholeFileReader()
filename, content = reader.read(filename_queue)
image = tf.image.decode_jpeg(content, channels=3)
image = tf.cast(image, tf.float32)
resized_image = tf.image.resize_images(image, 224, 224)

image_batch , label_batch= tf.train.batch([resized_image,label], batch_size=8, num_threads = 3, capacity=5000)
Run Code Online (Sandbox Code Playgroud)

这是训练数据集的正确代码吗?

之后,我尝试使用它来使用以下代码对输入图像进行分类.

test = ['test.jpg', 'test2.jpg']
test_queue=tf.train.string_input_producer(test)
reader = tf.WholeFileReader()
testname, test_content = reader.read(test_queue)
test = tf.image.decode_jpeg(test_content, channels=3)
test = tf.cast(test, tf.float32)
resized_image = tf.image.resize_images(test, 224,224)

with tf.Session() as sess:
    coord = …
Run Code Online (Sandbox Code Playgroud)

python image-processing tensorflow tensorboard

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

FlatList 标头中有多个元素

有没有什么方法可以将元素数组传递给 FlatList 而不使用包装器,以便我以后stickyHeaderIndices={[1]}可以只使第二个元素具有粘性?

我的意图是将非粘性标题与粘性工具栏一起使用并将它们传递给组件。

如果我尝试将 renderHeader 作为函数传递给 ListHeaderComponent,例如

  renderHeader = () => {
    const { toolbar, header } = this.props;
    const arr = [header(), toolbar()];
    return arr;
  };
Run Code Online (Sandbox Code Playgroud)

我得到一个

Invariant Violation: Invariant Violation: Invariant Violation: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

Check the render method of `VirtualizedList`.
Run Code Online (Sandbox Code Playgroud)

实现该行为的另一种方法是什么(即)有一个列表,其中只有第二个标题变得粘滞?

我尝试的另一种方法是声明一个带有 3 个孩子的滚动视图:

The non-sticky header
The toolbar
The flatlist itself
Run Code Online (Sandbox Code Playgroud)

stickyHeaderIndices={[1]}ScrollView 上设置时。 …

react-native react-native-flatlist

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

React Native 自定义字体额外填充

我正在为 Android 和 IOS 使用自定义字体 (Cairo)。针对两个平台使用额外填充呈现的字体,如下所示

样品一

当我尝试设置时,lineHeight=[fontSize]我得到以下信息

样本二

我尝试lineGap=0按照这篇文章进行设置: 一致的字体行高渲染 ,但我发现它已经为零

还尝试了 paddingTop 解决方案,但它根本不起作用,只需将文本向下移动到底部空间,如上图所示

希望任何人都可以提供帮助:)

android native ios reactjs react-native

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

imshow 彩色图像,错误显示为蓝色

我正在尝试使用 opencv 读取并显示 tiff 图像。我在 imread (-1,0,1,2) 中尝试了不同的阅读模式 下面代码的结果仅在彩色图像时将图像错误地显示为蓝色。

import numpy as np
import cv2 
import matplotlib.pyplot as plt
def readImagesAndTimes():
  # List of exposure times
  times = np.array([ 1/30.0, 0.25, 2.5, 15.0 ], dtype=np.float32)

  # List of image filenames
  filenames = ["img01.tif", "img02.tif", "img03.tif", "img04.tif", "img05.tif"]
  images = []
  for filename in filenames:
    im = cv2.imread("./data/hdr_images/" + filename, -1)
    images.append(im)

  return images, times

images, times = readImagesAndTimes()
for im in images:
    print(im.shape)
    plt.imshow(im, cmap = plt.cm.Spectral)
Run Code Online (Sandbox Code Playgroud)

原图:

[原来的] …

python opencv matplotlib python-3.x

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

如何将 x,y 像素映射到世界坐标

在我的项目中,我计算 x、y(以像素为单位)和 Z(以毫米为单位)距相机的距离。所以我想利用深度并计算 x,y,z。

谁能告诉我该怎么做?

我有以下信息:

  1. 从图像中获取的 x,y 像素
  2. 距相机的距离以及距相机和物体的距离不断变化,因为我从不同的距离拍摄图像

opencv image-processing

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

预期的二维数组,得到一维数组而不是错误

我收到错误为

“ValueError:预期的二维数组,而是得到一维数组:数组=[ 45000. 50000. 60000. 80000. 110000. 150000. 200000. 300000. 500000. 1000000. 1000000. 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000. ) 如果您的数据具有单个特征或 array.reshape(1, -1) 如果它包含单个样本。”

在执行以下代码时:

# SVR

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Position_S.csv')
X = dataset.iloc[:, 1:2].values
y = dataset.iloc[:, 2].values

 # Feature Scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
sc_y = StandardScaler()
X = sc_X.fit_transform(X)
y = sc_y.fit_transform(y)

# Fitting SVR to the dataset
from sklearn.svm …
Run Code Online (Sandbox Code Playgroud)

python machine-learning data-science

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

如何获取TextInput的String中的当前行数?

在中输入文本后,TextInput 我想知道 中当前的行数TextInput。或者当前的数量strings也是可以的。

我已经尝试过了string.split('\n').length,但是此代码没有检测到当文本大于屏幕时该行会自动递增。

如何获取行数

当我使用函数Swift 实现此功能时string.enumerateLines

你们有类似的功能吗?

react-native react-native-textinput

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

ReactJS:如何将className添加到子组件

我正在尝试向子组件添加类名,保留可能设置为组件的原始类.

这是代码:

import React, { Component } from "react";
import PropTypes from "prop-types";

    class ClassExtender extends Component {
        getChildrenWithProps = () => {
            let addedClass = "my-new-css-class-name";

            return React.Children.map(this.props.children, child => 
                React.cloneElement(child, { className: [child.className, addedClass] })
            );
        };

        render = () => {
            return this.getChildrenWithProps();
        };
    }

    export default ClassExtender;
Run Code Online (Sandbox Code Playgroud)

当我的组件渲染时,我得到了错误的结果:

<div class=",my-new-css-class-name">Test</div>
Run Code Online (Sandbox Code Playgroud)

这指出了两个可能的问题:

  1. 逗号可能表示我需要将代码更改为React.cloneElement(child, { className: child.className + " " + addedClass });.这是一个简单的步骤.
  2. child.className正在恢复null.如何检索附加到子组件的当前classe?

javascript reactjs

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

获取 Flatlist ItemSeparatorComponent 尾随项目?

Flatlist 允许您定义一个ItemSeparatorComponent接收作为默认道具highlightedleadingItem. 前导项表示显示分隔符之前的项。

问题是我inverted在我的 Flatlist 上使用,我的分隔符现在需要适应下一个项目而不是前一个项目。

有没有办法访问分隔符显示的项目?像一个 trailingItem 之类的东西?

react-native react-native-flatlist

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

如何获取滚动视图索引

我正在对我scrollview的.slideimageBackground

我用来pagingEnabled滑动图像。index但是有没有办法让我每次刷卡时都能得到号码?

我正在使用滚动视图,如下面的代码。添加pagingEnabled将使滚动视图像 a 一样工作swiper,但我不知道如何获取index.

<ScrollView horizontal={true} pagingEnabled={true}>
            {this.createScrollImageSources(this.state.image)}
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

react-native react-native-scrollview

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