React Native实现底部Tab切换—TabNavigator

本文介绍了如何使用React-native-tab-navigator库实现移动端底部Tab切换的功能。详细讲述了集成步骤、核心代码展示,并列举了TabNavigator配置参数,包括title、tabBarVisible、tabBarIcon等,以及TabNavigatorConfig的相关配置如tabBarComponent、animationEnabled和tabBarOptions等,帮助开发者创建自定义的底部Tab导航。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

功能:

使用React-native-tab-navigator(https://github.com/exponentjs/react-native-tab-navigator) 实现底部选项卡切换

实现效果:

在这里插入图片描述

在这里插入图片描述

实现过程:

1、项目集成react-native-tab-navigator

在项目根目录下,运行:npm install react-native-tab-navigator –-save

2、核心代码:

App.js代码

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,StatusBar,Image} from 'react-native';
import {StackNavigator, TabNavigator, TabBarBottom} from 'react-navigation'

import color from './widget/color'
import TabBarItem from './widget/TabBarItem'

import HomeScene from './scene/Home/HomeScene'
import MineScene from './scene/Mine/MineScene'

const lightContentScenes = ['Home', 'Mine']

function getCurrentRouteName(navigationState: any) {
    if (!navigationState) {
        return null
    }
    const route = navigationState.routes[navigationState.index]
    // dive into nested navigators
    if (route.routes) {
        return getCurrentRouteName(route)
### Java 实现根据经纬度计算日出和日落时间 以下是基于太阳位置算法的一个简单实现,用于通过给定的经纬度以及日期来计算当天的日出和日落时间。此方法依赖于天文计算中的标准公式[^1]。 ```java import java.time.LocalDate; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; public class SunriseSunsetCalculator { private static final double PI = Math.PI; private static final double DEG_TO_RAD = PI / 180.0; public static void main(String[] args) { double latitude = 40.7128; // 替换为实际纬度 double longitude = -74.0060; // 替换为实际经度 LocalDate date = LocalDate.now(); // 当前日期 ZonedDateTime sunriseTime = calculateSunrise(date, latitude, longitude); ZonedDateTime sunsetTime = calculateSunset(date, latitude, longitude); System.out.println("Sunrise Time: " + sunriseTime.format(DateTimeFormatter.ISO_LOCAL_TIME)); System.out.println("Sunset Time: " + sunsetTime.format(DateTimeFormatter.ISO_LOCAL_TIME)); } private static ZonedDateTime calculateSunrise(LocalDate date, double latitude, double longitude) { return computeSunEventTime(date, latitude, longitude, true); } private static ZonedDateTime calculateSunset(LocalDate date, double latitude, double longitude) { return computeSunEventTime(date, latitude, longitude, false); } private static ZonedDateTime computeSunEventTime(LocalDate date, double latitude, double longitude, boolean isRiseTime) { int dayOfYear = date.getDayOfYear(); ZoneId zoneId = ZoneId.systemDefault(); double lngHour = longitude / 15.0; double t = dayOfYear + ((6 - lngHour) / 24); // 日序数调整 double meanAnomaly = (0.9856 * t) - 3.289; double sunLongitude = meanAnomalyToSunLongitude(meanAnomaly); double rightAscension = sunLongitudeToRightAscension(sunLongitude); double sinDec = Math.sin(sunLongitude * DEG_TO_RAD) * Math.sin(23.44 * DEG_TO_RAD); double cosH = (Math.cos(-0.83 * DEG_TO_RAD) - (sinDec * Math.sin(latitude * DEG_TO_RAD))) / (Math.cos(sinDec) * Math.cos(latitude * DEG_TO_RAD)); double h = Math.acos(cosH) / DEG_TO_RAD; h = isRiseTime ? 360 - h : h; double localMeanNoon = (720 - (4 * longitude) - (lngHour * 60)) + (h * 4); double utcTime = localMeanNoon / 60; return ZonedDateTime.of(date.getYear(), date.getMonthValue(), date.getDayOfMonth(), (int) utcTime, (int) ((utcTime % 1) * 60), 0, 0, zoneId); } private static double meanAnomalyToSunLongitude(double m) { double l = m + (1.916 * Math.sin(m * DEG_TO_RAD)) + (0.020 * Math.sin(2 * m * DEG_TO_RAD)) + 282.634; while (l >= 360) l -= 360; while (l < 0) l += 360; return l; } private static double sunLongitudeToRightAscension(double l) { double ra = Math.atan(0.91764 * Math.tan(l * DEG_TO_RAD)) / DEG_TO_RAD; if (ra < 0) ra += 360; return ra; } } ``` #### 关键说明 - **输入参数**:该程序接受三个主要参数——`latitude`(纬度)、`longitude`(经度)和 `date`(日期)。这些数据决定了具体的地理位置目标日期。 - **核心逻辑**:利用天文学上的均差修正法,结合地球自转角度变化规律,推导出特定地的日出/日落时刻[^2]。 - **时区处理**:最终返回的时间会自动转换成运行环境所在的本地时区。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值