我想把滑块放在我屏幕的顶部.

styles号不会影响它的位置.

以下是我的代码:

import React, { useRef } from 'react';
import { View, StyleSheet } from 'react-native';
import Swiper from 'react-native-swiper';
import SexScreen from './SexScreen';
import NameScreen from './NameScreen';
import BirthDateScreen from './BirthDateScreen';
import BirthLocationScreen from './BirthLocationScreen';
import BirthTimeScreen from './BirthTimeScreen';
// import other necessary components and styles

const OnboardingSwiper = () => {
  const swiperRef = useRef(null);

  const goToNextSlide = () => {
    swiperRef.current?.scrollBy(1);
  };

  const goToPreviousSlide = () => {
    swiperRef.current?.scrollBy(-1);
  };

  return (
    <View style={styles.container}>
      <Swiper
        loop={false}
        showsPagination={true}
        index={0}
        scrollEnabled={false}
        ref={swiperRef}
        activeDotColor="white"
        style={styles.swiper}
      >
        <SexScreen onNext={goToNextSlide} onBack={goToPreviousSlide} />
        <NameScreen onNext={goToNextSlide} onBack={goToPreviousSlide} />
        <BirthDateScreen onNext={goToNextSlide} onBack={goToPreviousSlide} />
        <BirthLocationScreen onNext={goToNextSlide} onBack={goToPreviousSlide} />
        <BirthTimeScreen onNext={goToNextSlide} onBack={goToPreviousSlide} />
        </Swiper>
    </View>
  );
};

const styles = StyleSheet.create({
    container: {
      flex: 1,
      justifyContent: 'flex-start', // Ensure content is aligned to the top
    },
    swiper: {
        height: 'auto', // Adjust height as needed
    },
    // Other styles...
  });

const OnboardingScreen = () => {
    return <OnboardingSwiper />;
};

export default OnboardingScreen;

enter image description here

推荐答案

react-native-swiper已经4年没有更新了.通常不建议使用没有积极维护的包.你可以试一试react-native-swiper-flatlist.

现在,只要react-native-swiper美元,你就可以使用他们的一个props paginationStyle,并根据你的需要给它一些造型.

<Swiper
  loop={false}
  showsPagination={true}
  index={0}
  scrollEnabled={false}
  ref={swiperRef}
  activeDotColor="white"
  style={styles.swiper}
  paginationStyle={{ top: "-80%" }} // add this
>

我已经判断了Style,添加top: "-80%"会将圆点滑块移动到屏幕顶部.

React-native相关问答推荐

在Reaction Native With EXPO中播放来自OpenAI TTS API的音频响应

如何在EXPO路由中重置导航

React Native 动画.您必须在转换属性中精确指定一个属性.

react-native 签名 [AppName]Tests 需要开发团队 ios

如何在react-native 中处理不同的屏幕尺寸?

图像背景ResizeMode调整大小模式

React-Native 应用程序的 Jest 测试 Animated.View

如何重置react-native 动画?

如何解决此错误您可能需要适当的加载程序来处理此文件类型

带有 react-navigation 的 DrawerNavigation 标头

在react native 中出现Cannot read property 'pick算法rithm' of null错误

props验证中缺少 React Navigation 'navigation'

React Native 中的原生广告

react-native run-android 在设备上构建旧版本的代码

React Native 得到这个错误'Unrecognized operator abs'

如何在本地构建 Expo APK

如何在 React Native 的 MapView 中设置标记

React Native font outline / textShadow

如何在react-native中更新数组状态?

React Native + Redux 基本认证