下タブバーの実装

This commit is contained in:
YoheiZuho 2023-07-02 06:22:56 +00:00
parent d5ef4dff60
commit d05a0c8fa3
14 changed files with 200 additions and 19 deletions

View File

@ -55,6 +55,8 @@ class Settings::PreferencesController < Settings::BaseController
:setting_trends,
:setting_crop_images,
:setting_always_send_emails,
:setting_place_tab_bar_at_bottom,
:setting_show_tab_bar_label,
notification_emails: %i(follow follow_request reblog favourite mention report pending_account trending_tag appeal),
interactions: %i(must_be_follower must_be_following must_be_following_dm)
)

View File

@ -21,8 +21,15 @@ import {
} from '../../ui/util/async-components';
import ComposePanel from './compose_panel';
import NavigationPanel from './navigation_panel';
import TabsBar from './tabs_bar';
import { place_tab_bar_at_bottom } from 'mastodon/initial_state';
import { supportsPassiveEvents } from 'detect-passive-events';
import { scrollRight } from '../../../scroll';
import { Link } from 'react-router-dom';
import classNames from 'classnames';
import Icon from 'mastodon/components/icon';
const shouldHideFAB = path => path.match(/^\/statuses\/|^\/search|^\/getting-started/);
const componentMap = {
'COMPOSE': Compose,
@ -138,6 +145,28 @@ export default class ColumnsArea extends ImmutablePureComponent {
const { renderComposePanel } = this.state;
if (singleColumn) {
if (place_tab_bar_at_bottom) {
return (
<div className='columns-area__panels tab-ber-bottom'>
<div className='columns-area__panels__pane columns-area__panels__pane--compositional'>
<div className='columns-area__panels__pane__inner'>
{renderComposePanel && <ComposePanel />}
</div>
</div>
<div className='columns-area__panels__main timeline'>
<div className='tabs-bar__wrapper'><div id='tabs-bar__portal' /></div>
<div className='columns-area columns-area--mobile'>{children}</div>
</div>
<div className='columns-area__panels__main navber'>
{location.pathname !== '/publish' && <Link to='/publish' className='button bottom_right'><Icon id='pencil' fixedWidth /></Link>}
<TabsBar key='tabs' />
</div>
</div>
);
} else {
return (
<div className='columns-area__panels'>
<div className='columns-area__panels__pane columns-area__panels__pane--compositional'>
@ -159,6 +188,7 @@ export default class ColumnsArea extends ImmutablePureComponent {
</div>
);
}
}
return (
<div className={`columns-area ${ isModalOpen ? 'unscrollable' : '' }`} ref={this.setRef}>

View File

@ -0,0 +1,96 @@
import React from 'react';
import PropTypes from 'prop-types';
import { NavLink, withRouter } from 'react-router-dom';
import { FormattedMessage, injectIntl } from 'react-intl';
import NotificationsCounterIcon from './notifications_counter_icon';
import { place_tab_bar_at_bottom, show_tab_bar_label } from 'mastodon/initial_state';
import classNames from 'classnames';
import { debounce } from 'lodash';
import { isUserTouching } from '../../../is_mobile';
import Icon from 'mastodon/components/icon';
export const links = [
<NavLink className='tabs-bar__link' to='/home' data-preview-title-id='column.home' data-preview-icon='home' ><Icon id='home' fixedWidth /><span className='tabs-bar__link__full-label'><FormattedMessage id='tabs_bar.home' defaultMessage='Home' /></span><span className='tabs-bar__link__short-label'><FormattedMessage id='navigation_bar.short.home' defaultMessage='Home' /></span></NavLink>,
<NavLink className='tabs-bar__link' to='/notifications' data-preview-title-id='column.notifications' data-preview-icon='bell' ><NotificationsCounterIcon /><span className='tabs-bar__link__full-label'><FormattedMessage id='tabs_bar.notifications' defaultMessage='Notifications' /></span><span className='tabs-bar__link__short-label'><FormattedMessage id='navigation_bar.short.notifications' defaultMessage='Notif.' /></span></NavLink>,
<NavLink className='tabs-bar__link' to='/public/local' data-preview-title-id='column.community' data-preview-icon='users' ><Icon id='users' fixedWidth /><span className='tabs-bar__link__full-label'><FormattedMessage id='tabs_bar.local_timeline' defaultMessage='Federated' /></span><span className='tabs-bar__link__short-label'><FormattedMessage id='navigation_bar.short.local_timeline' defaultMessage='LTL' /></span></NavLink>,
<NavLink className='tabs-bar__link' exact to='/public' data-preview-title-id='column.public' data-preview-icon='globe' ><Icon id='globe' fixedWidth /><span className='tabs-bar__link__full-label'><FormattedMessage id='tabs_bar.federated_timeline' defaultMessage='Federated' /></span><span className='tabs-bar__link__short-label'><FormattedMessage id='navigation_bar.short.public_timeline' defaultMessage='FTL' /></span></NavLink>,
<NavLink className='tabs-bar__link optional' to='/search' data-preview-title-id='tabs_bar.search' data-preview-icon='bell' ><Icon id='search' fixedWidth /><span className='tabs-bar__link__full-label'><FormattedMessage id='tabs_bar.search' defaultMessage='Search' /></span><span className='tabs-bar__link__short-label'><FormattedMessage id='navigation_bar.short.search' defaultMessage='Search' /></span></NavLink>,
<NavLink className='tabs-bar__link hamburger' to='/getting-started' data-preview-title-id='getting_started.heading' data-preview-icon='bars' ><Icon id='bars' fixedWidth /></NavLink>,
];
export function getIndex (path) {
return links.findIndex(link => link.props.to === path);
}
export function getLink (index) {
return links[index].props.to;
}
export default @injectIntl
@withRouter
class TabsBar extends React.PureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
};
setRef = ref => {
this.node = ref;
}
handleClick = (e) => {
// Only apply optimization for touch devices, which we assume are slower
// We thus avoid the 250ms delay for non-touch devices and the lag for touch devices
if (isUserTouching()) {
e.preventDefault();
e.persist();
requestAnimationFrame(() => {
const tabs = Array(...this.node.querySelectorAll('.tabs-bar__link'));
const currentTab = tabs.find(tab => tab.classList.contains('active'));
const nextTab = tabs.find(tab => tab.contains(e.target));
const { props: { to } } = links[Array(...this.node.childNodes).indexOf(nextTab)];
if (currentTab !== nextTab) {
if (currentTab) {
currentTab.classList.remove('active');
}
const listener = debounce(() => {
nextTab.removeEventListener('transitionend', listener);
this.props.history.push(to);
}, 50);
nextTab.addEventListener('transitionend', listener);
nextTab.classList.add('active');
}
});
}
}
static contextTypes = {
router: PropTypes.object.isRequired,
identity: PropTypes.object.isRequired,
};
static propTypes = {
intl: PropTypes.object.isRequired,
};
render () {
const { intl: { formatMessage } } = this.props;
return (
<div className='tabs-bar__wrapper'>
<nav className={classNames('tabs-bar', { 'bottom-bar': place_tab_bar_at_bottom })} ref={this.setRef}>
{links.map(link => React.cloneElement(link, { key: link.props.to, className: classNames(link.props.className, { 'short-label': show_tab_bar_label }), onClick: this.handleClick, 'aria-label': formatMessage({ id: link.props['data-preview-title-id'] }) }))}
</nav>
<div id='tabs-bar__portal' />
</div>
);
}
}

View File

@ -135,5 +135,7 @@ export const version = getMeta('version');
export const translationEnabled = getMeta('translation_enabled');
export const languages = initialState?.languages;
export const statusPageUrl = getMeta('status_page_url');
export const place_tab_bar_at_bottom = getMeta('place_tab_bar_at_bottom');
export const show_tab_bar_label = getMeta('show_tab_bar_label');
export default initialState;

View File

@ -23,3 +23,5 @@
@import 'mastodon/dashboard';
@import 'mastodon/rtl';
@import 'mastodon/accessibility';
@import 'plugin';

View File

@ -0,0 +1,34 @@
// ここから下タブバーの実装
//投稿ボタン
.columns-area__panels__main .button.bottom_right {
position: fixed;
right: 18px;
bottom: 65px;
display: flex;
align-items: center;
justify-content: center;
width: 64px;
height: 64px;
font-size: 24px;
border-radius: 50%;
}
.tab-ber-bottom .timeline{
width:100%;
height: calc(100% - 55px);
margin: 0 0 50px 0;
}
.tab-ber-bottom .navber{
width:100%;
bottom: 0;
position: fixed;
}
.tab-ber-bottom .navber .tabs-bar__wrapper{
bottom: 0;
width: 100%;
}
//ここまで下タブバーの実装

View File

@ -39,6 +39,7 @@ class UserSettingsDecorator
user.settings['trends'] = trends_preference if change?('setting_trends')
user.settings['crop_images'] = crop_images_preference if change?('setting_crop_images')
user.settings['always_send_emails'] = always_send_emails_preference if change?('setting_always_send_emails')
user.settings['place_tab_bar_at_bottom'] = place_tab_bar_at_bottom_preference if change?('setting_place_tab_bar_at_bottom')
end
def merged_notification_emails
@ -137,6 +138,14 @@ class UserSettingsDecorator
boolean_cast_setting 'setting_always_send_emails'
end
def place_tab_bar_at_bottom_preference
boolean_cast_setting 'setting_place_tab_bar_at_bottom'
end
def show_tab_bar_label_preference
boolean_cast_setting 'setting_show_tab_bar_label'
end
def boolean_cast_setting(key)
ActiveModel::Type::Boolean.new.cast(settings[key])
end

View File

@ -136,6 +136,7 @@ class User < ApplicationRecord
:expand_spoilers, :default_language, :aggregate_reblogs, :show_application,
:advanced_layout, :use_blurhash, :use_pending_items, :trends, :crop_images,
:disable_swiping, :always_send_emails,
:place_tab_bar_at_bottom,
to: :settings, prefix: :setting, allow_nil: false
delegate :can?, to: :role

View File

@ -51,6 +51,7 @@ class InitialStateSerializer < ActiveModel::Serializer
store[:use_pending_items] = object.current_account.user.setting_use_pending_items
store[:trends] = Setting.trends && object.current_account.user.setting_trends
store[:crop_images] = object.current_account.user.setting_crop_images
store[:place_tab_bar_at_bottom] = object.current_account.user.setting_place_tab_bar_at_bottom
else
store[:auto_play_gif] = Setting.auto_play_gif
store[:display_media] = Setting.display_media

View File

@ -2,7 +2,7 @@
%html{ lang: I18n.locale }
%head
%meta{ charset: 'utf-8' }/
%meta{ name: 'viewport', content: 'width=device-width, initial-scale=1' }/
%meta{ name: 'viewport', content: 'width=device-width, initial-scale=1, viewport-fit=cover'}/
- if cdn_host?
%link{ rel: 'dns-prefetch', href: cdn_host }/

View File

@ -32,6 +32,7 @@
= f.input :setting_reduce_motion, as: :boolean, wrapper: :with_label
= f.input :setting_disable_swiping, as: :boolean, wrapper: :with_label
= f.input :setting_system_font_ui, as: :boolean, wrapper: :with_label
= f.input :setting_place_tab_bar_at_bottom, as: :boolean, wrapper: :with_label
%h4= t 'appearance.toot_layout'

View File

@ -56,6 +56,7 @@ en:
setting_display_media_show_all: Always show media
setting_hide_network: Who you follow and who follows you will be hidden on your profile
setting_noindex: Affects your public profile and post pages
setting_place_tab_bar_at_bottom: Place the tab bar at the bottom
setting_show_application: The application you use to post will be displayed in the detailed view of your posts
setting_use_blurhash: Gradients are based on the colors of the hidden visuals but obfuscate any details
setting_use_pending_items: Hide timeline updates behind a click instead of automatically scrolling the feed

View File

@ -209,6 +209,7 @@ ja:
setting_expand_spoilers: 閲覧注意としてマークされたトゥートを常に展開する
setting_hide_network: 繋がりを隠す
setting_noindex: 検索エンジンによるインデックスを拒否する
setting_place_tab_bar_at_bottom: タブバーを下に配置する
setting_reduce_motion: アニメーションの動きを減らす
setting_show_application: 送信したアプリを開示する
setting_system_font_ui: システムのデフォルトフォントを使う

View File

@ -38,6 +38,7 @@ defaults: &defaults
trends_as_landing_page: true
trendable_by_default: false
crop_images: true
place_tab_bar_at_bottom: false
notification_emails:
follow: true
reblog: false