小编lim*_*dev的帖子

如何在 React-Native 中从内部 Touchable 到外部 Touchable 冒泡新闻事件?

我有 2 个嵌套的Touchables,我想onPress在外层Touchable和内层中捕获事件Touchable,但只有内层会触发onPress事件,所以我们可以说该事件不会传播到父元素

我正在使用 React-Native 0.57

这是我的零食示例

我也在这里重新发布我的渲染代码:

<TouchableOpacity onPress={() => alert('outer')}
    style={{ backgroundColor: 'red', width: 200, height: 200 }}>
    <TouchableOpacity onPress={() => alert('inner')}
        style={{ backgroundColor: 'green', width: 100, height: 100 }}
    />
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)

显示了如何只看到内部警报或外部警报。
相反,我想显示按下绿色视图的外部和内部警报...

代码是一个简化版本,在真实情况下,innerTouchable是一个可以在各种场景中使用的组件,要么在 a 内部Touchable,要么在非 Touchable 组件中

javascript react-native

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

如何在打字稿中的自定义类型保护中使用instanceof?

我正在尝试使用创建自定义类型保护,instanceof但奇怪的是它在 else 子句中没有按预期工作

这是带有相关 Playground 链接的示例: Playground Link

class Person {}

class Animal {}

const isPerson = (obj: Person | Animal): obj is Person => obj instanceof Person;
const isAnimal = (obj: Person | Animal): obj is Animal => obj instanceof Animal;

const test: Person | Animal = new Person();

if(test instanceof Animal){
  test; // const test: Animal
}
else {
  test; // const test: Person
}

if(isAnimal(test)){
  test; // const test: Animal
}
else {
  test; // …
Run Code Online (Sandbox Code Playgroud)

narrowing typescript typeguards

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

React Native 中 resizeMode='contain' 的 ImageBackground 的位置


我是 React-native 的新手,我有一个非常简单的(至少我这么认为)问题。

我有一个 ImageBackground resizeMode='contain',现在我想将背景定位到容器的顶部......

<ImageBackground style={styles.imageBackground} source={backgroundImage} resizeMode='contain'> 
... some content 
</ImageBackground>
Run Code Online (Sandbox Code Playgroud)

图像以正确的方式渲染,但问题是它是垂直居中的,相反我想让它顶部对齐......

这是我的 ImageBackground 结果的示例

这是将底部添加到 ImageStyle 的结果示例

react-native

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

为什么打字稿无法通过其字段推断通用类型?

我不明白为什么有时打字稿无法推断 const 的泛型类型。

这是一个例子:

type OneTwoThree = 1 | 2 | 3;

type MyType<num extends OneTwoThree> = {
    n: num;
}

const first: MyType = { // <-- Generic type 'MyType' requires 1 type argument(s).(2314)
    n: 2,
};

const second: MyType<3> = {
    n: 3,
};
Run Code Online (Sandbox Code Playgroud)

为什么打字稿不能推断出它的first类型MyType<2>

我也尝试过MyType以这种方式声明:

type MyType<num extends OneTwoThree = OneTwoThree> = {
    n: num;
}
Run Code Online (Sandbox Code Playgroud)

但这样首先就成为了类型const first: MyType<OneTwoThree>......

这是游乐场链接: https: //www.typescriptlang.org/play ?#code/C4TwDgpgBA8gdhAKgdwPaIBYCcLQLxQCMUAPlAEylQDMA3AFD2iRQCyIi4EAPHAK4BbKBAAewCHAAmAZ1gIU6bLigF4SNJhwQAfCqgBvelGNQ4ALLOCGAX0YBjVHGnAoAMwCWWZxfacWBQxNT C3IAGnprBnoHJxdpCBjJHw4ubmpdAKMTcxpwyKA

有什么建议么?

typescript typescript-generics

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

向 Google Sheet 折线图添加一条垂直线

我有一张带有折线图的工作表,现在我正在尝试做一些可能非常简单的事情:
我想使用单元格中的值向该图表添加一条垂直线。

所以我有这个折线图 在此处输入图片说明
还有一个日期为 2016/01/01 的单元格,我想在单元格日期的所有图表上有一条垂直线

我不知道该怎么做...

这是该表的副本:https : //docs.google.com/spreadsheets/d/1oeiwmeDT8pUVqBQvoE_cqk7mZxxvD5moZr41Vp4IN2I/edit?usp=sharing

我想使用“购买日期”显示一条垂直线

google-sheets google-sheets-charts

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

如何使用 LINQ 延迟加载 where 条件

我是 LINQ 的新手

我正在尝试where使用延迟加载来执行动态,但我不明白该怎么做。

这是我的代码

protected int AnimalCount(System.Func<Animal, bool> expression = null, System.Func<Animal, bool> additionalExpression= null)
    {
    var records = (from temp in DbContext.Animal select temp);
    if (expression != null) records = records.Where(expression).AsQueryable();
    if (additionalExpression != null) records = records.Where(additionalExpression).AsQueryable();
    return records.Count();
}
Run Code Online (Sandbox Code Playgroud)

现在,问题是查询很慢,我认为是因为在SELECT * FROM Animal查询的列表上应用了where子句

c# linq lazy-loading

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