問題:
BaseButton
リップルは、子としてのテキストでは正常に機能しますが、画像では機能しません。
再現するには:
<BaseButton style={{height: 150, width: 100}}>
<Image source={...} style={{width: 100, height: 100}}/>
</BaseButton>
"react-native-gesture-handler": "^ 1.0.16"、
"react": "16.8.3"、
"react-native": "0.59.1"、
テスト済みデバイス:Samsung Galaxy S6、Android 7.0
絶対塗りつぶしを回避策として使用し、絶対塗りつぶしを使用してビューとスタイルボタンでボタンと画像を折り返すことができます。ところで、rippleColorも指定する必要があります。そうしないと、奇妙な動作が発生します。
これが、RNのTouchableNativeFeedback
コンポーネントにuseForeground
小道具がある理由です。 RNGHの3つのボタンコンポーネントは、この動作を模倣する必要があります。
ところで、「絶対充填」の回避策は私にはうまくいきません。
Ripple.jsをラップします
import React from 'react';
import { View, StyleSheet } from 'react-native';
import { RectButton } from 'react-native-gesture-handler';
const styles = StyleSheet.create({
box: {
position: 'relative',
},
ripple: {
position: 'absolute',
left: 0,
top: 0,
width: '100%',
height: '100%',
zIndex: 1,
},
});
export default ({ style, children, ...props }) => {
return (
<View style={[style, styles.box]}>
{children}
<RectButton rippleColor="#888" style={styles.ripple} {...props} />
</View>
);
};
最も参考になるコメント
これが、RNの
TouchableNativeFeedback
コンポーネントにuseForeground
小道具がある理由です。 RNGHの3つのボタンコンポーネントは、この動作を模倣する必要があります。ところで、「絶対充填」の回避策は私にはうまくいきません。