mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 06:43:00 +00:00 
			
		
		
		
	Added scrollbar to comment section
This commit is contained in:
		| @@ -294,6 +294,7 @@ dependencies { | ||||
|     implementation 'androidx.activity:activity-compose' | ||||
|     implementation 'androidx.compose.ui:ui-tooling-preview' | ||||
|     implementation 'androidx.compose.ui:ui-text:1.7.0-beta03' // Needed for parsing HTML to AnnotatedString | ||||
|     implementation 'com.github.nanihadesuka:LazyColumnScrollbar:2.1.0' | ||||
|  | ||||
|     // Paging | ||||
|     implementation 'androidx.paging:paging-rxjava3:3.3.0' | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package org.schabi.newpipe.fragments.list.comments | ||||
|  | ||||
| import android.content.res.Configuration | ||||
| import androidx.compose.foundation.lazy.LazyColumn | ||||
| import androidx.compose.foundation.lazy.rememberLazyListState | ||||
| import androidx.compose.material3.HorizontalDivider | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.ui.tooling.preview.Preview | ||||
| @@ -10,6 +11,8 @@ import androidx.paging.PagingData | ||||
| import androidx.paging.compose.collectAsLazyPagingItems | ||||
| import kotlinx.coroutines.flow.Flow | ||||
| import kotlinx.coroutines.flow.flowOf | ||||
| import my.nanihadesuka.compose.LazyColumnScrollbar | ||||
| import my.nanihadesuka.compose.ScrollbarSettings | ||||
| import org.schabi.newpipe.extractor.comments.CommentsInfoItem | ||||
| import org.schabi.newpipe.extractor.stream.Description | ||||
| import org.schabi.newpipe.ui.theme.AppTheme | ||||
| @@ -20,8 +23,10 @@ fun CommentSection( | ||||
|     parentComment: CommentsInfoItem? = null, | ||||
| ) { | ||||
|     val replies = flow.collectAsLazyPagingItems() | ||||
|     val listState = rememberLazyListState() | ||||
|  | ||||
|     LazyColumn { | ||||
|     LazyColumnScrollbar(state = listState, settings = ScrollbarSettings.Default) { | ||||
|         LazyColumn(state = listState) { | ||||
|             if (parentComment != null) { | ||||
|                 item { | ||||
|                     CommentRepliesHeader(comment = parentComment) | ||||
| @@ -34,20 +39,19 @@ fun CommentSection( | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO) | ||||
| @Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES) | ||||
| @Composable | ||||
| private fun CommentSectionPreview() { | ||||
|     val comment1 = CommentsInfoItem( | ||||
|         commentText = Description("This is a comment", Description.PLAIN_TEXT), | ||||
|         uploaderName = "Test", | ||||
|     val comments = (0..100).map { | ||||
|         CommentsInfoItem( | ||||
|             commentText = Description("Comment $it", Description.PLAIN_TEXT), | ||||
|             uploaderName = "Test" | ||||
|         ) | ||||
|     val comment2 = CommentsInfoItem( | ||||
|         commentText = Description("This is another comment.<br>This is another line.", Description.HTML), | ||||
|         uploaderName = "Test 2", | ||||
|     ) | ||||
|     val flow = flowOf(PagingData.from(listOf(comment1, comment2))) | ||||
|     } | ||||
|     val flow = flowOf(PagingData.from(comments)) | ||||
|  | ||||
|     AppTheme { | ||||
|         CommentSection(flow = flow) | ||||
| @@ -65,16 +69,13 @@ private fun CommentRepliesPreview() { | ||||
|         isPinned = true, | ||||
|         isHeartedByUploader = true | ||||
|     ) | ||||
|  | ||||
|     val reply1 = CommentsInfoItem( | ||||
|         commentText = Description("This is a reply", Description.PLAIN_TEXT), | ||||
|         uploaderName = "Test 2", | ||||
|     val replies = (0..100).map { | ||||
|         CommentsInfoItem( | ||||
|             commentText = Description("Reply $it", Description.PLAIN_TEXT), | ||||
|             uploaderName = "Test" | ||||
|         ) | ||||
|     val reply2 = CommentsInfoItem( | ||||
|         commentText = Description("This is another reply.<br>This is another line.", Description.HTML), | ||||
|         uploaderName = "Test 3", | ||||
|     ) | ||||
|     val flow = flowOf(PagingData.from(listOf(reply1, reply2))) | ||||
|     } | ||||
|     val flow = flowOf(PagingData.from(replies)) | ||||
|  | ||||
|     AppTheme { | ||||
|         CommentSection(parentComment = comment, flow = flow) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Isira Seneviratne
					Isira Seneviratne