Today marks the National Memorial Day for the Nanjing Massacre victims.

In this article we are purely technical.

Reason for writing

Due to today’s special day, many apps mourn the death of their compatriots in black and white, such as Xx Dong and XX Bao:

I remember last year when there was a wave of black and white apps. The Great God of Hong Yang wrote an article exploring the native implementation of Black and white on Android. Then there was a version of Flutter, and then some people implemented some other solutions. But today we do not consider how the native Android is implemented, want to see if you can go to search the article of The God of Hong Yang. Today we’ll focus on how to achieve blackening using Compose.

Began to work

In fact, the last implementation of the previous article is to replace the root layout FrameLayout, and then set the saturation to 0. The implementation of Flutter is easier because Flutter officially provides a Widget, ColorFiltered, that allows you to directly whiten your application.

Compose does not provide a filtered color similar to that found in Flutter.

For Compose, there is no problem using the swarm solution, but Compose should be implemented in a simpler way.

Surface (color = MaterialTheme. The colors. The background,) {/ / normal layout NavGraph () / / black and white Canvas (modifier = modifier. FillMaxSize ()) {  drawRect( color = Color.White, blendMode = BlendMode.Saturation ) } }Copy the code

As you can see from the code above, the previous stack of code now requires only three lines, one line if the indentation is removed.

The principle is the same, also through setting Saturation, let’s look at the realization of the effect:

The effect is good, within the expected range, if you have a better way to tell me in the comment section, thank you very much.

The above two applications are open source, and the following is the open source address

Play the weather Github:https://github.com/zhujiang521/PlayWeather

Play the android Github:https://github.com/zhujiang521/PlayAndroid

Finished work

You can check out my new book, Jetpack Compose: New UI Programming for Android, which includes the Compose framework in its entirety.

Purchase address of JINGdong

Dangdang Purchase address

Pooh pooh, too shameless, recommending his new book again…

If it helps you, don’t forget to hit the Star. Thank you very much.

In fact, there are some details that I haven’t covered, so if you have any questions, please feel free to ask in the comments section.

Let me finish here, goodbye!