Как иметь двухцентровую и кликабельную ссылку на изображение в реагирующем - PullRequest
0 голосов
/ 21 января 2020

Я хочу, чтобы два изображения были кликабельны рядом с каждым, это мой вид:

    function MyView(props) {
        return (
              <View style={{ flex: 1, }}>
                <View style={{
                  // width: 230,
                  flex: 1,
                  justifyContent: 'center',
                  alignItems: 'center',
                }}>
                  <ExternalLink href="https://play.google.com/store/apps/details">
                    <Image
                      source={availableAtGooglePlayImage}
                      style={{
                        width: '100%',
                        height: 70,
                        flex: 1,
                        marginTop: 10,
                        resizeMode: 'contain',
                      }}
                    />
                  </ExternalLink>
                </View>
                <View style={{
                  // width: 230,
                  flex: 1,
                  justifyContent: 'center',
                  alignItems: 'center',
                }}>
                  <ExternalLink href="https://itunes.apple.com/fr/app">
                    <Image
                      resizeMode="stretch"
                      source={availableAtAppStoreImage}
                      style={{
                        width: '100%',
                        height: 70,
                        flex: 1,
                        marginTop: 10,
                        resizeMode: 'contain',
                      }}
                    />
                  </ExternalLink>
                </View>
        );
    }

Как только я использую flex: 1 в родительском представлении ExternalLink, изображение исчезает .

Я не нашел способа разместить эти два изображения рядом друг с другом.

Я только нашел способ сделать так, чтобы они были поверх каждого, и вся ширина кликабельна но я хочу, чтобы кликать можно было только на изображении.

Как это возможно в реакции на натуру?

Ответы [ 2 ]

1 голос
/ 21 января 2020

То, что вы ищете, это свойство {flexDirection: 'row'} в стиле. Скопируйте код в https://snack.expo.io/

import * as React from 'react';
import { Text, View, StyleSheet, TouchableOpacity, Image, Linking } from 'react-native';

export default class App extends React.Component {
  render() {
    return (
      <>
        <View style={{flex:1, flexDirection:'row'}}>

          <TouchableOpacity 
            style={styles.imageButton}
            onPress={() =>{Linking.openURL("https://play.google.com/store/apps/details")}}
          >
            <Image
                resizeMode={'contain'}
                style={styles.coverImage}
                source={{uri: 'https://facebook.github.io/react/logo-og.png'}}
            />
          </TouchableOpacity>

          <TouchableOpacity 
          style={styles.imageButton}
          onPress={() =>{Linking.openURL("https://itunes.apple.com/fr/app")}}
          >
            <Image
                resizeMode={'contain'}
                style={styles.coverImage}
                source={{uri: 'https://facebook.github.io/react/logo-og.png'}}
            />
          </TouchableOpacity>
        </View>
      </>
    );
  }
}

const styles = StyleSheet.create({
    coverImage: {
        flex: 1,
        alignSelf: 'stretch',
        width: undefined,
        height: undefined
    },
    imageButton:{
      flex:1,
      height:70
    }
});
1 голос
/ 21 января 2020

Можете ли вы проверить этот код, пожалуйста, это рабочий пример Экспо :

import * as React from 'react';
import { Text, View, StyleSheet ,Image,TouchableOpacity,Linking } from 'react-native';




export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
       <View>
       <TouchableOpacity onPress={() =>Linking.openURL("https://play.google.com/store/apps/details")}>
        <Image style={{height:50,width:50}} source={{uri:"https://source.unsplash.com/random"}} />
        </TouchableOpacity>
       </View>
       <View>
        <TouchableOpacity onPress={() =>Linking.openURL("https://itunes.apple.com/fr/app")}>
        <Image style={{height:50,width:50}} source={{uri:"https://source.unsplash.com/random"}} />
        </TouchableOpacity>
       </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection:'row',
    justifyContent:'space-around',
    alignItems:'center',

  },

});

Не стесняйтесь сомнений

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...